Equality Saturation with E-graphs for Non-destructive Optimization

This direction is no longer present in the current build. Its last version stays readable and citable here.

Version 1 of 134 papers54 conceptsfrozen 2026-10-04

Traditional compilers are "greedy" and "destructive." When an optimizer sees a pattern like x * 2, it might replace it with x << 1 and immediately discard the original expression. This approach creates a fundamental challenge known as the phase-ordering problem: the order in which you apply optimizations matters. If a compiler performs a simplification too early, it might accidentally destroy a pattern that a later, more powerful optimization pass needed to see.

To solve this, researchers are shifting toward equality saturation, a technique that allows compilers to explore thousands of equivalent program versions simultaneously without ever throwing anything away.

The E-graph: A Superposition of Programs

At the heart of this research is a data structure called the equivalence graph, or e-graph. Unlike a standard abstract syntax tree (AST) that represents a single version of a program, an e-graph represents a "superposition" of many equivalent programs.

As Gus Henry Smith and colleagues argue in There and Back Again: A Netlist's Tale with Much Egraphin', e-graphs allow Electronic Design Automation (EDA) tools to store multiple versions of a circuit design at once. Instead of choosing between two designs, the e-graph stores both, linking them as members of the same "equivalence class."

This non-destructive nature is the "secret sauce." By maintaining all versions, the compiler avoids making premature, suboptimal choices. As Shadaj Laddad and Alvin Cheung demonstrate in Optimizing Stateful Dataflow with Local Rewrites, this allows an optimizer to discover complex transformations—like turning a slow cross-product into an efficient join—simply by composing basic algebraic rules like associativity and distributivity.

Reaching Saturation

The process of equality saturation involves repeatedly applying rewrite rules to the e-graph. Each rule adds new nodes and equivalences but never deletes old ones. The process continues until "saturation"—a state where no more new equivalences can be discovered.

Once saturated, the e-graph contains a massive search space of equivalent programs. The compiler then uses a cost model to "extract" the best version. In SEER: Super-Optimization Explorer for HLS using E-graph Rewriting with MLIR, Jianyi Cheng and Samuel Coward use this to bypass the phase-ordering problem in High-Level Synthesis (HLS), discovering hardware designs that are up to 38× faster than those produced by standard, linear optimization pipelines.

Beyond Compilers: Verification and Symbolic Regression

The power of e-graphs extends beyond just making code faster; it also makes code easier to verify. Because e-graphs can prove that two syntactically different programs are semantically identical, they are becoming a cornerstone of formal verification.

For example, Kahfi S. Zulkifli and Chang Lou developed Scalify, which uses equality saturation to verify the equivalence of massive machine learning models like Llama-3. By treating optimizations as logical relations, they can catch "silent errors" in production frameworks that would otherwise go unnoticed. Similarly, Ferran Alet and Armando Solar-Lezama use Program Expression Graphs and equality saturation in PROGRES to robustly verify synthesized code against ground truth.

In the realm of scientific discovery, Yexiang Xue and Nan Jiang introduced EGG-SR, which injects mathematical "common sense" into symbolic regression. By using an e-graph to recognize that $x+x$ is the same as $2x$, the algorithm avoids wasting time exploring redundant mathematical expressions, leading to faster discovery of physical laws.

Native Integration and Hardware Co-Design

A major trend in this field is moving equality saturation from external libraries directly into the compiler's core. In eqsat: An Equality Saturation Dialect for Non-destructive Rewriting, Jules Merckx and Tobias Grosser integrate e-graphs as first-class citizens within LLVM’s MLIR framework. This eliminates the "translation tax" and allows non-destructive rewriting to interoperate with standard passes like inlining.

This integration is particularly potent for hardware-software co-optimization. Yun Liang has applied this to both Aquas, which co-optimizes RISC-V processors and their compilers, and SkyEgg, which models hardware resource mapping as rewrite rules. By representing both algebraic logic and physical implementation choices in the same e-graph, these systems can simultaneously optimize what the program does and how the hardware executes it.

Papers in this version

History & citationVersion 1 · 2026-10-04

No longer present in the current build · Permanent link

View frozen version 1

Cite this direction

Latest version (a living page):

@misc{lacuna_equality_saturation_with_e_graphs_for_no_81974a87,
  title = {Equality Saturation with E-graphs for Non-destructive Optimization},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/equality-saturation-with-e-graphs-for-non-destructive-optimization/rdr_81974a871304458595dbdd463ff2e405},
  note = {Latest version of a living research direction; cite a version for a fixed text. Accessed 2026-11-24},
}

This exact version (version 1, frozen text):

@misc{lacuna_equality_saturation_with_e_graphs_for_no_81974a87_v1,
  title = {Equality Saturation with E-graphs for Non-destructive Optimization},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/equality-saturation-with-e-graphs-for-non-destructive-optimization/rdr_81974a871304458595dbdd463ff2e405/v/1},
  note = {Version 1, frozen 2026-10-04. Accessed 2026-11-24},
}