#5237: Inefficient code generated for x^2
--------------------------------------+-------------------------------------
Reporter: scpmw | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 7.4.1
Component: libraries/base | Version: 7.0.3
Resolution: | Keywords:
Testcase: | Blockedby:
Difficulty: | Os: Linux
Blocking: | Architecture: x86_64 (amd64)
Failure: Runtime performance bug |
--------------------------------------+-------------------------------------
Changes (by igloo):
* status: patch => new
Comment:
So if I understand correctly, the problem is that with `q.hs`:
{{{
{-# RULES "^^^2/Integer" forall x. x ^^^ (2 :: Integer) = x * x #-}
{-# SPECIALISE (^^^) :: Integer -> Integer -> Integer #-}
{-# NOINLINE (^^^) #-}
(^^^) :: (Num a, Integral b) => a -> b -> a
x ^^^ y = 1
v :: Integer
v = 8 ^^^ 2
main :: IO ()
main = print v
}}}
we get the specialisation matching and not the rule, and thus the result
is 1 rather than 64:
{{{
$ ghc -O -ddump-rule-firings q.hs
[1 of 1] Compiling Main ( q.hs, q.o )
Rule fired: Class op fromInteger
Rule fired: SPEC Main.^^^
Rule fired: Class op show
Linking q ...
$ ./q
1
}}}
If we comment out the specialisation then we get the desired:
{{{
$ ghc -O -ddump-rule-firings q.hs
[1 of 1] Compiling Main ( q.hs, q.o )
Rule fired: ^^^2/Integer
Rule fired: Class op *
Rule fired: timesInteger
Rule fired: Class op show
Linking q ...
$ ./q
64
}}}
(as a sidenote, I think the rule should be
{{{
{-# RULES "^^^2/Integer" forall x. x ^^^ (2 :: Integer) = let v = x in v *
v #-}
}}}
in case x is a large expression)
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5237#comment:10>
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