r/Compilers • u/compilers-r-us • Aug 13 '26
Another partial SSI trick with canonicalize
https://bernsteinbear.com/blog/more-partial-ssi/
11
Upvotes
r/Compilers • u/compilers-r-us • Aug 13 '26
1
u/adityazero Aug 13 '26
I like that the branch-condition seeding rides along the same dominator walk you already built for the rewrite maps, so it avoids turning into a separate SCCP style pass. If a later value numbering run exposes fresh branch conditions, does interning the CBool constants alone keep it idempotent, or do you still need a fixpoint?
1
u/AustinVelonaut Aug 14 '26
This looks a lot like the inliner / simplifier rewrite for case scrutinees in the GHC Haskell compiler mentioned here and here: a case statement with a known compile-time scrutinee can be replaced by its matching case arm:
can simply be rewritten as
expr2. But if the case scrutinee is a variable, we can rewrite each case arm with the variable re-bound to the specific constructor value. This can enable future simplifications if the scrutinee variable is referenced again in the case arms:In the case arm, we rebind
xtoFalse, leading to future simplification ofx & yto simplyFalse.This works for any constructor pattern, so in something like:
the second case expression in the arm can be entirely replaced with
a + b