Because I can see it coming: this is a different question than What optimizations can GHC be expected to perform reliably? because I'm not asking for the most reliable optimizations, just the most clever/powerful.
I'm specifically looking for non-intuitive optimizations that GHC makes that can have serious impacts on performance and demonstrate the power of compiler optimizations related to lazy evaluation or purity. And direct explanations about how to get at them.
The best answers will have:
- An explanation of the optimization and why it is so clever or powerful
- Why the optimization improves performance
- How GHC recognizes when it can use this optimization
- What the optimization actually transforms the code into
- Why this optimization requires lazy evaluation or purity