1 / 28

Equality Saturation: A New Approach to Optimization

Equality Saturation: A New Approach to Optimization. Ross Tate , Mike Stepp , Zach Tatlock , Sorin Lerner University of California, San Diego. Traditional Optimization. Phase Ordering Problem. Original Program. Optimized Program. Optimizations. Local Profitability Heuristics.

zazu
Download Presentation

Equality Saturation: A New Approach to Optimization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Equality Saturation:A New Approach to Optimization Ross Tate, Mike Stepp, Zach Tatlock, Sorin Lerner University of California, San Diego

  2. Traditional Optimization Phase Ordering Problem Original Program Optimized Program Optimizations Local Profitability Heuristics

  3. Traditional Optimization

  4. Exploring Equivalences

  5. Exploring Equivalences

  6. CFG→PEG Conversion Our Approach Program Expression Graph

  7. Equality Saturation Our Approach

  8. Our Approach Global Profitability Heuristic

  9. PEG→CFG Conversion Our Approach

  10. Benefits • Mitigates Phase Ordering Problem • Non-destructive updates allow exponential search • Global Profitability Heuristic • Explore first, then decide • Translation Validation • Verify translations using equality saturation

  11. Example sum = 0; for (i = 0; i < 10; i++) sum += 4 * i; return sum;

  12. Representing Loops sum = 0; for (i = 0; i < 10; i++) sum += 4 * i; return sum; * 4 θ1 • Complete Representation • Referentially Transparent • No Intermediate Variables 0 + 1

  13. Equality Analyses • Identify Equalities • PEG Node Granularity • Equality Axioms • ∀X. 4*X = (X≪2) ∀X. 4*X = (X≪2) << * 2 4 θ1 0 + 1

  14. Equality Inference ∀X. 4*X = (X≪2) ∀X,Y. 4*θ(X, Y) = θ(4*X, 4*Y) << θ1 * ∀ X,Y,Z. X*(Y+Z) = X*Y+ X*Z * 2 * + 4 θ1 4 * * 4 0 0 + ∀X. X*0 = 0 4 1 4 1 ∀X. X*1 = X

  15. E-PEG << * θ1 + * 2 4 θ1 * 4 * 0 + 4 0 1 4 1

  16. PEG Selection << * θ1 Global Profitability Heuristic + * 2 4 θ1 * 4 * 0 + 4 0 1 4 1

  17. Optimized PEG θ1 0 + 4

  18. Optimized Program sum = 0; for(j = 0; j < 40; j += 4) sum += j; return sum; θ1 0 + 4

  19. Optimized Program sum = 0; for(i = 0; i < 10; i++) sum += 4 * i; return sum; sum = 0; for(j = 0; j < 40; j += 4) sum += j; return sum; Loop Induction Variable Strength Reduction

  20. Emergent Optimizations Optimizations composed from simple rules • Loop Induction Variable Strength Reduction • Loop-Operation Factoring • Loop-Operation Distributing • Inter-Loop Strength Reduction • Temporary Object Removal • Partial Inlining

  21. Implementation

  22. Implementation • Algorithm provided in the Technical Report • Model heap with values having linear types

  23. Implementation • Tarjan’s Union-Find Algorithm • tracks equivalence classes in the E-PEG • Rete Pattern Matching Algorithm • incrementally finds significant nodes in the E-PEG • Equality Analyses: • PEG Operator Axioms • Language-Specific Axioms • Domain-Specific Axioms

  24. Implementation • Pseudo-Boolean Solver • Assign a cost to each operation in the E-PEG • Impose constraints for a well-formed PEG • Minimize the cost of the selected PEG

  25. Peggy: Java Bytecode Optimizer • Observed Emergent Optimizations • Traditionally need to be explicitly implemented • Domain-Specific Analyses: • 7% runtime improvement on Java ray tracer • Compilation of SpecJVM (per method): • 1030 programs found in less than 200MB memory • Average compilation time per stage: 14 msec 88 msec 1499 msec 1499 msec 43 msec

  26. CFG→PEG Conversion • CFG→PEG Conversion • Equality Saturation Translation Validator • Validation of Soot optimizer on SpecJVM: • 98% of optimized methods successfully validated • Optimization bug found within remaining 2% ?

  27. Conclusions • Powerful • Simultaneous Exponential Search • Emergent Optimizations • Extensible • Cooperative Equality Analyses • Domain-Specific Axioms • General • Optimization • Translation Validation

  28. Related Work • E-Graphs • Denali: Basic Block Assembly Superoptimizer • Simplify: Theorem Prover • Representations • Thinned-Gated SSA • Lucid programming language • Value Dependence Graph • Dependence Flow Graph • Program Dependence Graph/Web • Rewrite-Based Optimizers • TAMPR • ASF+SDF • Stratego

More Related