
#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 bgamari): I think the issue here is that while on paper the code we emit is independent of our `GcPlan`, in practice we emit the code in most cases in `heapCheck` and **how** we end up in `heapCheck` is very much dependent on the `GcPlan`. I believe this almost does what we want, {{{#!hs maybeAltHeapCheck :: (GcPlan,ReturnKind) -> FCode a -> FCode a maybeAltHeapCheck gc_plan code = do codeOnly $ case gc_plan of (NoGcInAlts,_) -> code (GcInAlts regs, AssignedDirectly) -> altHeapCheck regs code (GcInAlts regs, ReturnedTo lret off) -> altHeapCheckReturnsTo regs regs lret off code }}} The trouble is you have now thrown away the heap usage information from the code you emitted in the `NoGcInAlts` case. Alternatively, you can lift the code emission out of `heapCheck`, but this breaks its nice interface, {{{#!hs maybeAltHeapCheck :: (GcPlan,ReturnKind) -> FCode a -> FCode a maybeAltHeapCheck gc_plan code = do codeOnly $ case gc_plan of (NoGcInAlts,_) -> return () -- These now only compute the heap usage of 'code' and do not emit it (GcInAlts regs, AssignedDirectly) -> altHeapCheck regs code (GcInAlts regs, ReturnedTo lret off) -> altHeapCheckReturnsTo regs regs lret off code code }}} Anyways, let's see how Reid's approach performs; perhaps this is all irrelevant. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8326#comment:32 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler