[Haskell-cafe] GHC optimisations
simonpj at microsoft.com
Mon Aug 20 16:57:38 EDT 2007
GHC does some constant folding, but little by way of strength reduction, or using shifts instead of multiplication. It's pretty easy to add more: it's all done in a single module. Look at primOpRules in the module PrelRules.
Patches welcome! But please also supply test-suite tests that check the correctness of the rules.
| -----Original Message-----
| From: haskell-cafe-bounces at haskell.org [mailto:haskell-cafe-
| bounces at haskell.org] On Behalf Of Stefan O'Rear
| Sent: 19 August 2007 20:14
| To: Andrew Coppin
| Cc: haskell-cafe at haskell.org
| Subject: Re: [Haskell-cafe] GHC optimisations
| 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 ->
| using -O2 -fasm -ddump-asm... The compiler *really* shouldn't be using
| (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-
| 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
More information about the Haskell-Cafe