[Haskell-cafe] GHC optimisations

Isaac Dupree isaacdupree at charter.net
Tue Aug 21 16:43:07 EDT 2007

Simon Peyton-Jones wrote:
> | > 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.
> | >
> |
> | So... you mean it's source-level transformation rules? (Rather than
> | wired into the compiler itself somewhere.)
> No, constant folding is part of the compiler, I'm afraid, in the module PrelRules.
> Simon

_Constant_ folding is, but in GHC.Base there are rules like (unboxed) 
multiplying by zero or one, or adding or subtracting zero, from an 
unknown other (non-constant) value.  I think shifts might be doable via 
RULES... if you were willing to make one rule for each denominator 2, 4, 
8 and so on, which rather depends on max. Int... (and that's not 
Integers either, I guess)


More information about the Haskell-Cafe mailing list