feat: Dataflow forward equality analysis#9597
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9cbc122819
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for (&var, _) in info1.union_find.iter() { | ||
| let rep1 = info1.find_immut(var); | ||
| let rep2 = info2.find_immut(var); | ||
|
|
||
| // If this variable has the same representative in both branches, preserve the equality. | ||
| if rep1 == rep2 { | ||
| result.union(var, rep1); |
There was a problem hiding this comment.
Preserve equalities despite differing representatives
The merge logic only keeps an equality when rep1 == rep2, but union-find representatives are order-dependent. If two branches derive the same equivalence class via different union orders (e.g., branch A unions a,b then b,c, branch B unions b,c then a,b), they can end with different reps even though the classes are identical. In that case this merge drops equalities that hold on all paths, making the analysis overly conservative and missing valid equivalences. Consider comparing class membership rather than representative identity (e.g., by checking mutual equality between variables across states or normalizing reps) before discarding.
Useful? React with 👍 / 👎.

Summary
Added an equality analysis module to track semantic equivalence between variables in lowered IR. The analysis uses a union-find data structure to efficiently track equivalence classes, with additional tracking for box/unbox and snapshot/desnap relationships between classes.
Type of change
Please check one:
Why is this change needed?
This PR adds a new dataflow analysis that tracks when variables hold the same value, including through box/unbox and snapshot/desnap operations. This analysis will enable future optimizations that can eliminate redundant operations when variables are known to be equivalent.
What was the behavior or documentation before?
Previously, there was no way to track semantic equivalence between variables in the lowered IR, making it difficult to implement optimizations that rely on knowing when variables hold the same value.
What is the behavior or documentation after?
The new equality analysis module provides:
Additional context
This is a foundational analysis that will enable future optimizations like redundant operation elimination. The analysis is conservative at control flow merge points, preserving only equalities that hold on all paths.