Combining E-Graphs with Abstract Interpretation

Samuel Coward, George A. Constantinides, Theo Drane

TL;DR

This paper introduces a novel way to combine e-graphs, a data structure for representing equivalent expressions, with abstract interpretation, a technique for program analysis. This synergy allows for more precise program analysis and more efficient e-graph construction, leading to tighter bounds on expressions and the discovery of new optimization algorithms.

What Problem Does This Paper Address?

E-graphs are powerful for simplifying expressions by finding equivalent forms. However, many practical applications require conditional rewrite rules (e.g., x/x -> 1 only if x != 0). Applying these rules necessitates proving conditions, which is traditionally done using abstract interpretation (AI) in static analysis. The challenge is that AI and e-graph construction have historically been separate. This paper addresses the gap by showing how these two techniques can mutually reinforce each other, leading to a more powerful combined system.

Methods

The core of this work is the tight integration of abstract interpretation with e-graph construction. The authors formalize this by viewing e-classes (groups of equivalent expressions in an e-graph) as forming a lattice. This allows abstract interpretation to be applied directly to e-classes, producing more precise abstractions. Conversely, these precise abstractions enable the application of more conditional rewrite rules, further growing the e-graph and refining the abstractions. This creates a positive feedback loop.

Key techniques include:

  • Formalizing AI on E-graphs: Defining a lattice-theoretic interpretation for abstract interpretation over e-graphs.
  • Abstract Property Propagation: An algorithm (described in Figure 3) that propagates abstract properties (like intervals) through the e-graph, using a meet operation instead of a join for precision.
  • Handling Cyclic E-graphs: Developing a method to extract abstract fixpoint equations from cycles in e-graphs, which naturally leads to iterative refinement of abstractions.
  • Relational Domains: Incorporating techniques to capture relationships between variables, enabling more powerful conditional rewrites.
  • Interval Arithmetic Implementation: Demonstrating the approach with an interval arithmetic implementation using the egg library.

Datasets

The paper evaluates its implementation using 40 benchmarks from the FPBench benchmark suite. No new benchmarks were introduced.

Key Insights and Ideas

  • Synergistic Feedback Loop: The most significant insight is the positive feedback loop: more precise abstractions enable more conditional rewrites, which in turn lead to even more precise abstractions. This is a powerful combination that goes beyond the capabilities of either technique alone.
  • E-classes as Lattices: Viewing e-classes as forming a lattice provides a natural theoretical foundation for applying abstract interpretation. This allows for a more precise analysis by leveraging the structure of the e-graph.
  • Automated Discovery of Iterative Refinements: The method for handling cyclic e-graphs can automatically discover known iterative refinement algorithms, such as the Krawczyk method for solving linear systems. This suggests that this framework can be a powerful tool for discovering new optimization and analysis techniques.
  • Improved Precision for Conditional Rewrites: By using abstract interpretation, the system can prove the validity of conditional rewrite rules, leading to more aggressive and effective transformations.

Key Results

  • Increased E-graph Nodes: The inclusion of interval arithmetic and domain-specific rewrites increased the average number of e-graph nodes by 4%, with a maximum increase of 84%. This demonstrates the effectiveness of the combined approach in exploring more equivalent expressions.
  • Reduced Interval Width: On average, e-graph rewriting reduced the interval width to 85% of the naive interval approximation. In some cases, the reduction was close to 100%.
  • Minimal Runtime Overhead: The overhead of incorporating interval arithmetic into the e-graph increased runtimes by less than 1% on average, indicating that the approach is computationally feasible.
  • Discovery of Krawczyk Method: The framework was able to automatically discover the Krawczyk method for interval enclosures of linear systems, showcasing its potential for algorithmic discovery.

Limitations and Future Work

  • Limitations: The paper notes that for abstract domains with infinite descending chains, standard techniques like narrowing might be required. The current implementation focuses on real-valued expressions and a specific set of operators. The authors also mention that NaNs are generally avoided, but their handling in abstract intervals is noted.
  • Future Work: The authors suggest exploring additional abstract domains and their incorporation into e-graph optimization tools. They also mention that their techniques have been applied to fixed-width integer-valued expressions in related work.

Summary updated

BibTeX
@inproceedings{coward2023combining,
  author = {Samuel Coward and George A. Constantinides and Theo Drane},
  title = {{Combining E-Graphs with Abstract Interpretation}},
  booktitle = {SOAP@PLDI},
  year = {2023},
  doi = {10.1145/3589250.3596144},
}
Figure