Note [Add scrutinee to ValueEnv too]
Consider this:
case x of y
(a,b) -> case b of c
I# v -> ...(f y)...
By the time we get to the call (f y), the ValueEnv
will have a binding for y, and for c
y -> (a,b)
c -> I# v
BUT that's not enough! Looking at the call (f y) we
see that y is pair (a,b), but we also need to know what 'b' is.
So in extendCaseBndrs we must *also* add the binding
b -> I# v
else we lose a useful specialisation for f. This is necessary even
though the simplifier has systematically replaced uses of 'x' with 'y'
and 'b' with 'c' in the code. The use of 'b' in the ValueEnv came
from outside the case. See #4908 for the live example.
It's very like the binder-swap story, so we use scrutOkForBinderSwap
to identify suitable scrutinees -- but only if there is no cast
(isReflMCo) because that's all that the ValueEnv allows. References 0
This Note does not link to any other.
Referenced by 2
- Add unfolding for scrutinee GHC.Core.Opt.Simplify.Iteration
- GHC.Core.Opt.SpecConstr call site