Optimizations and constant unboxed values

Hi Cafe, Profiling a function that I thought ultra simple revealed that it consumed more than half the execution time of my code. After noticing that GHC did not unbox all I thought it did, I rewrote it with primitive types, and it did a little better, but not much. Then, examining the core (with of course -O3 on) revealed things like : (GHC.Prim.*## (GHC.Prim.-## 1.0 (GHC.Prim.**## 2.0 -53.0)) (GHC.Prim.**## 2.0 1024.0)) or case GHC.Prim.<## x_aB9 (GHC.Prim.**## 2.0 -1021.0) of _ {... Then I wondered if this was really the last stage of GHC's optimizations, as constants are not yet propagated. Or maybe GHC does not propagate constants, in which case I'd really like to write my 1-2^53 and 2^-1021 once and for all in my program. But since unsafeCoerce# does not work between doubles and words ( there is a trac ticket about it : http://hackage.haskell.org/trac/ghc/ticket/4092 ), I do not even think this is possible (and of course, specifying a double in decimal notation with ## is not precise enough for this program). Any clue about how to do it ? Thanks, PE

Hi,
On 28 May 2010 01:22, Pierre-Etienne Meunier
Then, examining the core (with of course -O3 on)
FYI, -O3 is the same as -O2.
revealed things like :
(GHC.Prim.*## (GHC.Prim.-## 1.0 (GHC.Prim.**## 2.0 -53.0)) (GHC.Prim.**## 2.0 1024.0))
or
case GHC.Prim.<## x_aB9 (GHC.Prim.**## 2.0 -1021.0) of _ {...
GHC does constant-fold many operations on floats/doubles at the Core level (see PrelRules.lhs) but there is no RULE for **. Perhaps there should be.
Then I wondered if this was really the last stage of GHC's optimizations,
I eyeballed the C-- code generator and it looks like that doesn't constant-fold ** either.
Any clue about how to do it ?
I think that rewriting your code is the only thing you can do. Please also submit a bug to the tracker and I'm sure that the right RULEs will get added soon. Cheers, Max
participants (2)
-
Max Bolingbroke
-
Pierre-Etienne Meunier