Repository navigation
[DAE2] Refinalize when changing types - #9290
Conversation
When `DAE2` removes unused values, replacing an expression (such as a `drop` of a concrete block containing an `unreachable` child) with its kept children can change the expression's type from `none` to `unreachable`. Track when a replacement in `Optimizer` becomes `unreachable` and run `ReFinalize` in parallel on affected functions at the end of `DAE2::optimize()` after global type rewriting.
There was a problem hiding this comment.
Code Review
This pull request introduces a refinalization step in the Dead Argument Elimination (DAE2) pass to handle cases where removing unused expression results introduces new unreachability, requiring enclosing expressions to be refinalized. It adds a refinalize flag to FunctionInfo and runs a custom Refinalizer pass after global type rewriting to ensure correct type propagation for instructions like call_ref and ref.func. Test cases have been added to verify this behavior. There are no review comments, so I have no additional feedback to provide.
There was a problem hiding this comment.
We seem to do results analysis now?
| ;; Refinalizing must happen after global type rewriting so that the ref.func | ||
| ;; gets the final rewritten subtype rather than a temporary scratch type. |
There was a problem hiding this comment.
It would be nice to elaborate what "scratch type" here is and why it is necessary. (Grepping the codebase with "scratch type" doesn't yield anything.
(Gemini told me it was this
binaryen/src/passes/DeadArgumentElimination2.cpp
Lines 1085 to 1090 in f1f3a48
But it would have been nice if could be read without Gemini's help when you don't have a detailed knowledge about the pass)
Also it would be nice if the comment describes what goes wrong if refinalizing doesn't happen at the end in this test.
There was a problem hiding this comment.
Updated the comment with a pointer to the code that creates this temporary type. (Explaining all the rationale for that would be too much for the test, I think). Also added an explanation of what would go wrong if we didn't refinalize at the right time.
When
DAE2removes unused values, replacing an expression (such as adropof a concrete block containing anunreachablechild) with its kept children can change the expression's type fromnonetounreachable. Track when a replacement inOptimizerbecomesunreachableand runReFinalizein parallel on affected functions at the end ofDAE2::optimize()after global type rewriting.