[Haskell-cafe] GHC optimisations

Andrew Coppin andrewcoppin at btinternet.com
Mon Aug 20 13:30:27 EDT 2007


Stefan O'Rear wrote:
> On Sun, Aug 19, 2007 at 12:53:07PM +0100, Andrew Coppin wrote:
>   
>> Does GHC do stuff like converting (2*) into (shift 1) or converting x + x 
>> into 2*x?
>>     
>
> For a good time, compile some code which uses even or odd :: Int -> Bool
> using -O2 -fasm -ddump-asm...  The compiler *really* shouldn't be using 'idivl'.
>
> (If you use -fvia-C -optc-O2, the C compiler will notice the operations
> and optimize it itself.  This is one of the very few areas where -fvia-C
> is still better.)
>   

The way I heard it is that compilation via C is "always better", though 
they "plan" to change that some day. I don't know how true that is...

>> If I do x * sin 12, is GHC likely to compute sin 12 at compile-time?
>>     
>
> Also try -ddump-simpl-stats and -ddump-simpl-iterations if you want to
> know *why*.  (The extremely obscure 'full laziness' transformation
> performed by GHC has a fundamental effect on the compilation of x * sin
> 12...)
>   

Hmm, OK.



More information about the Haskell-Cafe mailing list