No need to enter a scrutinised value
While analysing the output of #13861 I stumbled over an unnecessary pessimisation in handling of scrutinised values. With words of Simon (from https://phabricator.haskell.org/D4267 with minor edits added):
Interesting. Yes, please make a ticket! (And transfer the info below into it.)
I think the issue is this. Given (the STG-ish code)
data Colour = Red | Green | Blue f x = case x of y Red -> Green DEFAULT -> y
y is the case binder) we can just return
x rather than entering it in DEFAULT branch, because
y will be fully evaluated and its pointer will be correctly tagged.
You absolutely can't check for an
"wild"!! That is neither necessary nor sufficient :-).
isEvaldUnfolding (idUnfolding y). See
Note [Preserve evaluatedness] in
CoreTidy.hs. And be sure to augment that note if you make the change.
I would expect perf benefits to be small on average, but it's simple to implement.