1 / 26

A Polynomial-Time Algorithm for Global Value Numbering

A Polynomial-Time Algorithm for Global Value Numbering. SAS 2004 Sumit Gulwani George C. Necula. Global Value Numbering. Goal: Discover equivalent expressions in procedures Applications: Compiler optimizations

edwink
Download Presentation

A Polynomial-Time Algorithm for Global Value Numbering

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. A Polynomial-Time Algorithm for Global Value Numbering SAS 2004 Sumit Gulwani George C. Necula

  2. Global Value Numbering Goal: Discover equivalent expressions in procedures Applications: • Compiler optimizations • Copy propagation, Constant propagation, Common sub-expression elimination, Induction variable elimination etc. • Program verification • Discover loop invariants, verify program assertions • Discover equivalent computations across programs • Plagiarism detection tools, Translation validation

  3. Global Value Numbering • Equivalence problem is undecidable. • Simplification Assumptions: • Operators are uninterpreted (will not discover x = c) • Conditionals are non-deterministic (will not discover y = c) • Will discover z = c c := a £ b; If (b == 3) True False x := b £ a; y := a £ 3; z := a £ b;

  4. Non-trivial Example * x := b; y := b; z := F(b); x := a; y := a; z := F(a); assert(x = y); assert(z = F(y));

  5. Existing Algorithms • Algorithms that work on SSA form of the program • Alpern, Wegman, Zadeck’s (AWZ) algorithm: POPL 1988 • Polynomial, Incomplete • Ruthing, Knoop, Steffen’s (RKS) Algorithm: SAS 1999 • Polynomial, Incomplete, Improvement on AWZ • Dataflow analysis or Abstract interpretation based • Kildall’s Algorithm: POPL 1973 • Exponential, Complete • Our Algorithm: POPL 2004 • Polynomial, Complete, Randomized • Our Algorithm: this paper • Polynomial, Complete

  6. Why SSA based algorithms are incomplete? x = (a,b) y = (a,b) z = (F(a),F(b)) F(y) = F((a,b)) * x := b; y := b; z := F(b); x := a; y := a; z := F(a); assert(x = y); assert(z = F(y)); • AWZ Algorithm:  functions are uninterpreted • fails to discover second assertion • RKS Algorithm: uses rewrite rules for normalization • Does not discover all assertions in little more involved examples. • Rewrite rules not applied exhaustively (exp applications o.w.) • Rules are pessimistic in handling loops

  7. G0 Assignment Node x := e G = SP(G0,x := e) G0 Conditional Node * G2= G0 G1= G0 G20 G10 Join Node G = Join(G10,G20) Abstract Interpretation based algorithm

  8. Outline • Strong equivalence DAG (SED) • The join operation: Idea #1 • Pruning an SED: Idea #2 • The strongest postcondition operation • Fixed point computation

  9. Representing Equivalences a := 1; b := 2; x := F(1,2); { a,1 } { b,2 } { x, F(1,2) }

  10. Representing Equivalences a := 1; b := 2; x := F(1,2); { a,1 } { b,2 } { x, F(1,2), F(a,2), F(1,b), F(a,b) } Such an explicit representation can be exponential.

  11. Strong Equivalence DAG (SED) A data structure for representing equivalences. • Nodes n: <Set of variables, Type> • Type: c, ?, F(n1,n2) • Terms(n): set of equivalent expressions • Terms(<V, ?>) = V • Terms(<V, c>) = V [ { c } • Terms(<V, F(n1,n2)>) = V [ { F(e1,e2) | e12 Terms(n1), e22 Terms(n2) } • 8 variables x, 9 at most one node <V,t> s.t. x 2 V • called Node(x)

  12. SED: Example n4 This SED represents the following partition: Terms(n1) = { a, 2 } Terms(n2) = { b} Terms(n3) = { c, d, F(a,b), F(2,b) } Terms(n4) = { e, F(c,b), F(d,b), F(F(a,b),b), F(F(2,b),b) } e, F n3 d,c, F n2 n1 a, 2 b, ?

  13. Outline • Strong equivalence DAG (SED) • The join operation: Idea #1 • Pruning an SED: Idea #2 • The strongest postcondition operation • Fixed point computation

  14. The Join Operation G = Join(G1, G2) G is obtained by product construction of G1 and G2 If n=<V1,t1>2 G1 and m=<V2,t2>2 G2, then [n,m]= <V1Å V2, t1t t2>2 G Definition of t1t t2 c t c = c F(l1,r1) t F(l2,r2) = F ([l1,l2],[r1,r2]) t1t t2 = ?, otherwise Proof of Correctness Terms([n,m]) = Terms(n) Å Terms(m) (Thus product construction = partition intersection)

  15. y1, F y1, F y1, F y2, F y2, F y2, F F F F F F F y3,y4 y5,? y6,? y7,? y6,y7? y3,? y4,y5 ? y7,? y6,? y4,y5? y3,? G = Join(G1,G2) Example: The Join Operation G1 G2 G

  16. Outline • Strong equivalence DAG (SED) • The join operation: Idea #1 • Pruning an SED: Idea #2 • The strongest postcondition operation • Fixed point computation

  17. Motivation: The Prune Operation • If G=Join(G1,G2), then Size(G) can be Size(G1) £ Size(G2) • There are programs, where size of SEDs after n joins is exponential in n. Discovering equivalences among all expressions Discovering equivalences among program expressions vs. For the latter, it is sufficient to discover equivalences among all terms of size at most t at each program point (where t = #variables * size of program). Thus, SEDs can be pruned to have a small size.

  18. The Prune Operation Prune(G,k) • For each node <V,t>, check if x 2 V is equal to some F-term of size less than k. • If not, then delete all the nodes that are reachable from only <V,t>

  19. y1, G y1, G y2, F y2, ? F F y4,y5? y7,? y6,? y4,y5? y3,? Prune(G,2) G Example: The Prune Operation G

  20. Outline • Strong equivalence DAG (SED) • The join operation: Idea #1 • Pruning an SED: Idea #2 • The strongest postcondition operation • Fixed point computation

  21. The Strongest Postcondition Operation G = SP(G0, x := e) To obtain G from G’, do: • Delete label x from Node(x) in G0 • Let n=<V,t> be the node in G0 s.t. e 2 Terms(n) (Add such a node to G0 if it does not already exists) Add x to V.

  22. z, u, F z, F x, ? x, ? G0 Example: The Strongest Postcondition Operation F u, F G = SP(G0, u := F(z,x))

  23. Outline • Strong equivalence DAG (SED) • The join operation: Idea #1 • Pruning an SED: Idea #2 • The strongest postcondition operation • Fixed point computation

  24. Fixed Point Computation and Complexity • The lattice of sets of equivalences (among uninterpreted function terms) has height at most k. • Complexity • Dominated by the cost of join operations • # of join operations: O(j £ k) • Each join operation: O(k2£ N) • This requires doing pruning while computing join • Total cost: O(k3£ N £ j) k: # of variables N: size of program j: # of join points in program

  25. G2 z, F G1 z, F x,y, 2 x,y, 1 G3 z, F x,y,? G4 u,z, F G3 = Join(G1,G2) x,y, ? G4 = Assignment(G3, u := F(x,y)) Example x := 1; y := 1; z := F(1,1); x := 2; y := 2; z := F(2,2); L1 L2 L3 u := F(x,y); L4 Assert(u = z);

  26. Conclusion • Idea #1: Join of 2 SEDs = Product construction • Idea #2: Prune SEDs (Discovering equivalences among program expressions does not require computing equivalences involving large terms) Future Work • Inter-procedural value numbering • Abstract interpretation for combined theory of linear arithmetic and uninterpreted functions

More Related