inside the GHC code generator

Bulat Ziganshin bulat.ziganshin at
Thu Feb 23 08:31:58 EST 2006

Hello Rene,

Thursday, February 23, 2006, 4:19:15 PM, you wrote:

RdV> The following link gives reasons for not generating via C

i read it now

RdV> Naturally a number of these are common lisp specific, however I think that
RdV> Haskell and GCC are quite semantically different, so using GCC might prevent
RdV> a lot of optimizations, that aren't possible in C, but would be in GHC.

seems that you don;t understand the situation. ghc compiles Haskell to
language called "core", do almost all optimizations at level of this
language, then translates final result to the "STG" language from that
the C-- code is generated. changing the translation of STG can't
prevent ANY ghc optimization. although iy is not so easy because ghc
code generation and RTS closely tied together

RdV> The OCAML-OPT backend is supposed to produce i386 assembly that is 
RdV> competitive with GCC. Maybe this could be ported to GHC?

can you please show the code for the factorial accumulating function:

factorial n r  =  if n=1  then r  else (factorial (n - 1) (n*r))

i think that ocaml can't generate code better than gcc and especially
icc (intel C/C++ compiler), but may be i'm wrong? ;)

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at

More information about the Glasgow-haskell-users mailing list