[GHC] #8763: forM_ [1..N] does not get fused (10 times slower than go function)

GHC ghc-devs at haskell.org
Thu Mar 29 22:32:02 UTC 2018


#8763: forM_ [1..N] does not get fused (10 times slower than go function)
-------------------------------------+-------------------------------------
        Reporter:  nh2               |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  7.6.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #7206             |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 How about this (untested), which seems a lot simpler
 {{{
 efdtIntUpFB :: (Int -> r -> r) -> r -> Int# -> Int# -> Int# -> r
 efdtIntUpFB c n x1 x2 y    -- Be careful about overflow!
  | isTrue# (y <# x1)
  = n
  | otherwise
  = go_up x1    -- Common case: x1 <= y
  where
    !delta = x2 -# x1   -- >= 0
    !y' = y -# delta    -- x1 <= y' <= y; hence y' is representable

        -- Invariant: x <= y
        -- Note that: x <= y' => x + delta won't overflow
        -- so we are guaranteed not to overflow if/when we recurse
    go_up x = I# x `c` if isTrue# (x ># y')
                       then n
                       else go_up (x +# delta)
 }}}

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8763#comment:54>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list