Common subexpression elemination (CSE)

Christian Maeder maeder at tzi.de
Mon Nov 27 08:49:55 EST 2006


Lennart Augustsson schrieb:
> GHC doesn't normally do CSE.  CSE can cause space leaks, so you can't do
> it willy-nilly.
> I'm sure there are some strict contexts where it could be done safely,
> but I don't think ghc uses that information (yet).

Interestingly, it can only be switched off by -fno-cse, so I suppose
there should be some cases of cse.

C.

> On Nov 27, 2006, at 08:34 , Christian Maeder wrote:
> 
>> the following code does not run as fast as expected:
>>
>> modexp a e n = if e <= 0 then 1 else
>>    if even e
>>    then mod (modexp a (div e 2) n * modexp a (div e 2) n) n
>>    else mod (a * modexp a (e - 1) n) n
>>
>> it gets only fast if written as:
>>
>> modexp2 a e n = if e <= 0 then 1 else
>>    if even e
>>    then let d = modexp2 a (div e 2) n in mod (d * d) n
>>    else mod (a * modexp2 a (e - 1) n) n



More information about the Glasgow-haskell-users mailing list