Improving Placement of Heap Checks - Avoiding Slowdowns in Hot Code
When generating both heap and stack checks in Cmm, GHC can sometimes be fairly obtuse about their placement. As a result, they can be generated for paths in hot code that actually do not perform any allocation. Examples can be found in the related tickets, particularly #14791 and #16040.
This ticket exists to track the work proposed by Simon to detect such code patterns. They are described as follows:
- A primitive case with no allocation upstream from it.
- One alternative that performs no allocation.
Under such circumstances the stack/heap checks can be moved from being performed on every iteration to being performed just prior to the allocation itself.