#5237: Inefficient code generated for x^2
-------------------------------+--------------------------------------------
Reporter: scpmw | Owner:
Type: bug | Status: new
Priority: normal | Component: Compiler
Version: 7.0.3 | Keywords:
Testcase: | Blockedby:
Os: Linux | Blocking:
Architecture: x86_64 (amd64) | Failure: Runtime performance bug
-------------------------------+--------------------------------------------
Okay, this one is quite surprising to me. Suppose the following trivial
Haskell program:
{{{
main = print (2.0 ^ 2)
}}}
This innocent example actually ends up generating multiple pages of Core!
To see what's going on we just have to look at a few type signatures:
{{{
$wg1_r11f :: Double# -> Type.Integer -> Double# -> Double#
$wf1 :: Double# -> Type.Integer -> Double#
}}}
The function `$wf1` is what is called to perform the calculation. First
thing to note is that it actually compiles `^2` into a ''loop'' (that's
what `$wg1_r11f` is for). Second, to make matters worse, it ends up using
''Integer'' of all things as the index type (defaulting at work,
probably).
This has obviously drastic performance implications. A more complicated
example program actually got about 4 times faster just by replacing all
instances of `x^2` with `x*x`.
I guess this probably is not easy to fix in the general case (speculative
loop unrolling?). But couldn't we have, say, a rule that catches the worst
cases?
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5237>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs