Skip to content

feat: Dataflow forward equality analysis#9597

Open
eytan-starkware wants to merge 1 commit intoeytan_graphite/_feat_creating_forward_analysis_for_the_dataflow_frameworkfrom
eytan_graphite/feat_dataflow_forward_equality_analysis
Open

feat: Dataflow forward equality analysis#9597
eytan-starkware wants to merge 1 commit intoeytan_graphite/_feat_creating_forward_analysis_for_the_dataflow_frameworkfrom
eytan_graphite/feat_dataflow_forward_equality_analysis

Conversation

@eytan-starkware
Copy link
Contributor

@eytan-starkware eytan-starkware commented Feb 3, 2026

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:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

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:

  • A union-find data structure to efficiently track equivalence classes
  • Tracking of box/unbox and snapshot/desnap relationships between variables
  • A forward dataflow analysis that propagates equality information through the program
  • Comprehensive test cases demonstrating the analysis capabilities

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.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

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.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@eytan-starkware eytan-starkware marked this pull request as ready for review February 3, 2026 12:27
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +360 to +366
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants