[Haskell-cafe] GHC optimisations

Stefan O'Rear stefanor at cox.net
Sun Aug 19 15:14:20 EDT 2007


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.)

> 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...)

Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070819/a6e9f645/attachment.bin


More information about the Haskell-Cafe mailing list