[GHC] #13966: Missed optimization - loop fusion
GHC
ghc-devs at haskell.org
Wed Jul 12 20:44:30 UTC 2017
#13966: Missed optimization - loop fusion
-------------------------------------+-------------------------------------
Reporter: jmspiewak | Owner: (none)
Type: feature | Status: new
request |
Priority: low | Milestone:
Component: Compiler | Version: 8.2.1-rc3
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
I think GHC should be able to optimize func1 into func2, but currently it
doesn't.
{{{#!hs
data Step s a = Done | Yield s a
func1 high = loop1 0# 1# where
loop1 acc i = case loop2 i of
Done -> acc
Yield (I# i') (I# x) -> loop1 (acc +# x) i'
loop2 i = case tagToEnum# (i ># high) :: Bool of
False -> case remInt# i 2# of
0# -> Yield (I# (i +# 1#)) (I# i)
_ -> loop2 (i +# 1#)
True -> Done
func2 high = loop1 0# 1# where
loop1 acc i = case tagToEnum# (i ># high) :: Bool of
False -> case remInt# i 2# of
0# -> loop1 (acc +# i) (i +# 1#)
_ -> loop1 acc (i +# 1#)
True -> acc
}}}
When using the LLVM backend func2 is almost 4x faster than func1.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13966>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list