[GHC] #8763: forM_ [1..N] does not get fused (allocates 50% more)

GHC ghc-devs at haskell.org
Mon Sep 3 18:46:03 UTC 2018


#8763: forM_ [1..N] does not get fused (allocates 50% more)
-------------------------------------+-------------------------------------
        Reporter:  nh2               |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.8.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 sgraf):

 It turns out that the implementation from comment:60 doesn't get rid of
 the problem. It seems that the hard earned single call to `c` in `emit
 True x = I# x \`c\` emit next_ok next` gets duplicated because of case-of-
 case.

 The relevant Core began as this expression:

 {{{
 case (case ==# next_ovf_a3hz delta_ovf_a3h0 of lwild_s4fL {
            __DEFAULT -> GHC.Types.False
            1# -> b_a2jS
       }) of next_ok_a2k8 {
     __DEFAULT -> c_a2jU (GHC.Types.I# ds_d42Y) (emit_a3hf next_ok_a2k8
 next_a3hx)
 }
 }}}

 Now case-of-case comes along and immediately simplifies this to

 {{{
 case ==# next_ovf_a3hz delta_ovf_a3h0 of {
   __DEFAULT ->
     case b_a2jS of { __DEFAULT ->
       c_a2jU
         (GHC.Types.I# ds_d42Y)
         (emit_a3hf GHC.Types.False next_a3hx)
     };
   1# ->
     case b_a2jS of next_ok_a2k8 { __DEFAULT ->
       c_a2jU
         (GHC.Types.I# ds_d42Y)
         (emit_a3hf next_ok_a2k8 next_a3hx)
     }
 }
 }}}

 I'm not sure if the intermediate join point is never generated or is just
 inlined immediately, but I'd very much like this not to duplicate the call
 to `c`.

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


More information about the ghc-tickets mailing list