[GHC] #8326: Place heap checks common in case alternatives before the case

GHC ghc-devs at haskell.org
Tue Aug 4 06:10:12 UTC 2015


#8326: Place heap checks common in case alternatives before the case
-------------------------------------+-------------------------------------
        Reporter:  jstolarek         |                   Owner:
            Type:  task              |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Compiler          |                 Version:  7.7
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |               Test Case:
      Blocked By:                    |                Blocking:  8317
 Related Tickets:  #1498             |  Differential Revisions:  Phab:D343
-------------------------------------+-------------------------------------

Comment (by rwbarton):

 I'm not convinced that we shouldn't just always do the heap check outside
 the case, even when there is only one branch that allocates. In the worst
 case we do an extra memory read (HpLim, probably in L1 cache), a
 comparison and a branch (which is highly predictable). However

 * In simple functions (like the one in #10676) we don't need to allocate
 stack if we do the heap check up front. However a heap check in an
 alternative in this case requires allocating a stack frame (not sure
 whether occurs in all cases, or whether it is avoidable), so then we do
 have to do a stack check up front instead which is almost as expensive.
 (The difference is that SpLim is in a register while HpLim must be stored
 in memory.) In addition the code becomes substantially larger because we
 have two separate entries to the GC.

 * In functions which need to allocate stack anyways, putting the heap
 check outside the case does mean we have to an extra check when we take a
 branch that does not allocate. On the other hand, we can then use the same
 GC entry code for the stack check and the heap check, so the code is again
 much smaller. This may pay for the extra instructions of the heap check,
 especially if the non-allocating branch(es) are infrequent anyways.

 At any rate it's simpler than the knot-tying discussed in this ticket, so
 I will try it.

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


More information about the ghc-tickets mailing list