Open christiaanb opened 3 years ago
Transforming case undefined of {...} ==> undefined
isn't done by xOptimize
, but by caseCon'
.
And caseCon'
run just after caseOneAlt
: https://github.com/clash-lang/clash-compiler/blob/8894dd63aae5522845b7e37ab3c0d6cf10a084a8/clash-lib/src/Clash/Normalize/Transformations/Case.hs#L124
Flipping that order works for simple cases. (and changing >-!
into >->
)
And caseOneAlt
is still used directly in some other transformations.
https://github.com/clash-lang/clash-compiler/blob/a69ace9d21a6a1a925138588a428ed249d191641/clash-lib/src/Clash/Normalize/Transformations/Case.hs#L614-L618
imagine
if we had:
then we would first constant-specialize
f
:which after regular constant propagation becomes:
now, because x-optimization runs late
https://github.com/clash-lang/clash-compiler/blob/a69ace9d21a6a1a925138588a428ed249d191641/clash-lib/src/Clash/Normalize/Strategy.hs#L33-L40
caseOneAlt
(part ofcaseCon
) will fire first:while if xoptimization ran first we would've had:
I guess a solution is for
caseOneAlt
to instead ofdo
for the case where
caseOneAlt
eliminates the case-expression where all alternatives are equal. Then during the x-optimization pass we can cleanup: