Finding Global Redundancies with Hopcroft’s DFA Minimization Algorithm

Slides:



Advertisements
Similar presentations
Code Optimization, Part II Regional Techniques Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp.
Advertisements

School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
Operator Strength Reduction From Cooper, Simpson, & Vick, “Operator Strength Reduction”, ACM TOPLAS, 23(5), See also § of EaC2e. 1COMP 512,
Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
Lexical Analysis: DFA Minimization & Wrap Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp.
A Deeper Look at Data-flow Analysis Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at Rice University.
Code Motion of Control Structures From the paper by Cytron, Lowry, and Zadeck, COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda.
SSA-Based Constant Propagation, SCP, SCCP, & the Issue of Combining Optimizations 1COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda Torczon,
The Last Lecture Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at Rice University have explicit permission.
Lazy Code Motion Comp 512 Spring 2011
Partial Redundancy Elimination & Lazy Code Motion
Lazy Code Motion C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
Loop Invariant Code Motion — classical approaches — 1COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students.
Introduction to Code Optimization Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
Introduction to Optimization Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Instruction Scheduling II: Beyond Basic Blocks Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp.
Global Common Subexpression Elimination with Data-flow Analysis Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
Code Optimization, Part III Global Methods Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412.
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Structural Data-flow Analysis Algorithms: Allen-Cocke Interval Analysis Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students.
Introduction to Optimization, II Value Numbering & Larger Scopes Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
First Principles (with examples from value numbering) C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon,
Using SSA Dead Code Elimination & Constant Propagation C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon,
1 June 4, June 4, 2016June 4, 2016June 4, 2016 Azusa, CA Sheldon X. Liang Ph. D. Azusa Pacific University, Azusa, CA 91702, Tel: (800)
Building SSA Form, III 1COMP 512, Rice University This lecture presents the problems inherent in out- of-SSA translation and some ways to solve them. Copyright.
Lexical Analysis: DFA Minimization Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice.
Global Redundancy Elimination: Computing Available Expressions Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
Cleaning up the CFG Eliminating useless nodes & edges C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon,
Detecting Equality of Variables in Programs Bowen Alpern, Mark N. Wegman, F. Kenneth Zadeck Presented by: Abdulrahman Mahmoud.
Algebraic Reassociation of Expressions Briggs & Cooper, “Effective Partial Redundancy Elimination,” Proceedings of the ACM SIGPLAN 1994 Conference on Programming.
Parsing — Part II (Top-down parsing, left-recursion removal) Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
Terminology, Principles, and Concerns, III With examples from DOM (Ch 9) and DVNT (Ch 10) Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved.
Dead Code Elimination This lecture presents the algorithm Dead from EaC2e, Chapter 10. That algorithm derives, in turn, from Rob Shillner’s unpublished.
Terminology, Principles, and Concerns, II With examples from superlocal value numbering (Ch 8 in EaC2e) Copyright 2011, Keith D. Cooper & Linda Torczon,
Cleaning up the CFG Eliminating useless nodes & edges This lecture describes the algorithm Clean, presented in Chapter 10 of EaC2e. The algorithm is due.
Iterative Data-flow Analysis C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved. Students.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2011 Data flow analysis John Cavazos University.
Instruction Scheduling: Beyond Basic Blocks Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp.
Definition-Use Chains
Introduction to Optimization
Parsing — Part II (Top-down parsing, left-recursion removal)
Building SSA Form (A mildly abridged account)
Context-sensitive Analysis
Introduction to Optimization
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Intermediate Representations
Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit.
Instruction Scheduling: Beyond Basic Blocks
Building SSA Form COMP 512 Rice University Houston, Texas Fall 2003
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
CS 201 Compiler Construction
Intermediate Representations
Optimization through Redundancy Elimination: Value Numbering at Different Scopes COMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith.
The Last Lecture COMP 512 Rice University Houston, Texas Fall 2003
Automating Scanner Construction
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Parsing — Part II (Top-down parsing, left-recursion removal)
Lexical Analysis: DFA Minimization & Wrap Up
Optimizations using SSA
Dataflow Analysis Hal Perkins Winter 2008
Introduction to Optimization
Instruction Scheduling: Beyond Basic Blocks
Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved.
Algebraic Reassociation of Expressions COMP 512 Rice University Houston, Texas Fall 2003 P. Briggs & K.D. Cooper, “Effective Partial Redundancy Elimination,”
Lecture 17: Register Allocation via Graph Colouring
The Partitioning Algorithm for Detecting Congruent Expressions COMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper.
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Optimizing Compilers CISC 673 Spring 2009 Data flow analysis
Presentation transcript:

Finding Global Redundancies with Hopcroft’s DFA Minimization Algorithm Based on “Detecting Equality of Variables in Programs,” B. Alpern, M. Wegman, & F. Zadeck, Proceedings of the 15th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Langauges, San Diego, CA, USA, January 1988, pages 1 - 11. This lecture ties back to Chapter 2 … Finding Global Redundancies with Hopcroft’s DFA Minimization Algorithm Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make copies of these materials for their personal use.

Review We have already seen Local & Superlocal Value Numbering Finds redundancy, constants, & identities in a block Dominator Value Numbering Extends scope to “almost” global (no back edges) Uses dominance information to handle join points in CFG Global Common Subexpression Elimination (GCSE) Applying data-flow analysis to the problem Today’s lecture The Partitioning Method Using a well-known algorithm for a new purpose

Partitioning Method Key idea Congruence is related to redundancy, but not the same Using the idea Start with SSA form (we need the name space) Partition the set of all expressions into congruence classes Find largest possible sets Each class needs one (or more) representative computation Other uses can be replaced with representer Operations x and y are congruent iff they have the same operator & their operands are congruent Alpern, Wegman, & Zadeck POPL 1988

Partitioning Method The algorithm Based on Hopcroft’s algorithm for DFA minimization A widely-used, often re-invented algorithm s z  x+y n  q+y 1. Partition operations into initial classes by opcode 2. Worklist  all classes 3. While Worklist is not empty A. Remove a class c from Worklist B. For each class s that uses some x  c i. Split s into s1 and s2 around uses of c ii. Put smaller of s1 and s2 onto Worklist 4. Pick a representer for each class & rewrite the code to replace other uses of the class with representer c may split s c x  …

} Partitioning Method All Operations Some Initial Values * m0  a + b n0  a + b p0  c + d r0  c + d q0  a + b r1  c + d e0  b + 18 s0  a + b u0  e0 + f e1  a + 17 t0  c + d u1  e1 + f e2  (e0,e1) u2  (u0,u1) v0  a + b w0  c + d x0  e2 + f r2  (r0,r1) y0  a + b z0  c + d a  1 b  2 c  3 d  4 f  5 All Operations a  1 b  2 c  3 d  4 f  5 m0  a + b n0  a + b A p0  c + d r0  c + d B r2  (r0,r1) y0  a + b z0  c + d G q0  a + b r1  c + d C e0  b + 18 s0  a + b u0  e0 + f D e1  a + 17 t0  c + d u1  e1 + f E e3  (e0,e1) u2  (u0,u1) v0  a + b w0  c + d x0  e2 + f F *

Partitioning Method Compute Initial Partition * Worklist m0  a + b n0  a + b p0  c + d r0  c + d q0  a + b r1  c + d e0  b + 18 s0  a + b u0  e0 + f e1  a + 17 t0  c + d u1  e1 + f e2  (e0,e1) u2  (u0,u1) v0  a + b w0  c + d x0  e2 + f r2  (r0,r1) y0  a + b z0  c + d a  1 b  2 c  3 d  4 f  5 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 m0  a + b n0  a + b p0  c + d r0  c + d q0  a + b r1  c + d e0  b + 18 s0  a + b u0  e0 + f e1  a + 17 t0  c + d u1  e1 + f v0  a + b w0  c + d x0  e2 + f y0  a + b z0  c + d 7 Worklist 1, 2, 3, 4, 5, 6, 7 Compute Initial Partition *

Partitioning Method Split on a * Worklist 2, 3, 4, 5, 6, 7 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 m0  a + b n0  a + b p0  c + d r0  c + d q0  a + b r1  c + d e0  b + 18 s0  a + b u0  e0 + f e1  a + 17 t0  c + d u1  e1 + f v0  a + b w0  c + d x0  e2 + f y0  a + b z0  c + d 7 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 m0  a + b n0  a + b q0  a + b s0  a + b e1  a + 17 v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d e0  b + 18 u0  e0 + f t0  c + d u1  e1 + f w0  c + d x0  e2 + f z0  c + d 8 Split on a Worklist 2, 3, 4, 5, 6, 7 *

Partitioning Method Split on b * Worklist 3, 4, 5, 6, 7, 9, 10 a  1 1 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 m0  a + b n0  a + b q0  a + b s0  a + b e1  a + 17 v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d e0  b + 18 u0  e0 + f t0  c + d u1  e1 + f w0  c + d x0  e2 + f z0  c + d 8 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d u0  e0 + f t0  c + d u1  e1 + f w0  c + d x0  e2 + f z0  c + d 8 e1  a + 17 9 e0  b + 18 10 Split on b Worklist 3, 4, 5, 6, 7, 9, 10 *

Partitioning Method Split on c * Worklist 4, 5, 6, 7, 9, 10, 11 e1  a + 17 9 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d u0  e0 + f t0  c + d u1  e1 + f w0  c + d x0  e2 + f z0  c + d 8 e0  b + 18 10 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 e0  b + 18 10 u0  e0 + f u1  e1 + f x0  e2 + f 11 e1  a + 17 9 Split on c Worklist 4, 5, 6, 7, 9, 10, 11 *

Partitioning Method Split on d, f 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 e0  b + 18 10 u0  e0 + f u1  e1 + f x0  e2 + f 11 e1  a + 17 9 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 e1  a + 17 9 e0  b + 18 10 u0  e0 + f u1  e1 + f x0  e2 + f 11 Neither d nor f refine the partitions Split on d, f Worklist 6, 7, 9, 10, 11 *

11 is already on the Worklist Partitioning Method a  1 1 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 e1  a + 17 9 e0  b + 18 10 x0  e2 + f 11 u0  e0 + f u1  e1 + f 12 11 is already on the Worklist b  2 2 c  3 3 Split on e2,u2,r2 d  4 4 f  5 5 e1  a + 17 9 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 u0  e0 + f u1  e1 + f x0  e2 + f 11 e0  b + 18 10 Worklist 7, 9, 10, 11 *

Partitioning Method Split on m0, ... 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 e1  a + 17 9 e0  b + 18 10 x0  e2 + f 11 u0  e0 + f u1  e1 + f 12 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 e1  a + 17 9 e0  b + 18 10 x0  e2 + f 11 u0  e0 + f u1  e1 + f 12 Does not refine the partitions ... Split on m0, ... Worklist 9, 10, 11 *

Partitioning Method Split on e1 * Worklist 10, 11, 12, 6 a  1 1 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 e1  a + 17 9 e0  b + 18 10 x0  e2 + f 11 u1  e1 + f 12 u0  e0 + f 15 u2  (u0,u1) r2  (r0,r1) 14 b  2 2 c  3 3 Split on e1 d  4 4 f  5 5 e1  a + 17 9 e2  (e0,e1) u2  (u0,u1) r2  (r0,r1) 6 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 x0  e2 + f 11 x0  e2 + f 11 u0  e0 + f u1  e1 + f 12 Worklist 10, 11, 12, 6 e0  b + 18 10 *

Partitioning Method Split on e0 Does not refine the partitions ... * 1 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 e1  a + 17 9 e0  b + 18 10 x0  e2 + f 11 u1  e1 + f 12 u0  e0 + f 14 u2  (u0,u1) r2  (r0,r1) Does not refine the partitions ... b  2 2 c  3 3 Split on e0 d  4 4 f  5 5 e1  a + 17 9 e2  (e0,e1) 6 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 u2  (u0,u1) r2  (r0,r1) 14 x0  e2 + f 11 u1  e1 + f 12 u0  e0 + f 15 Worklist 11, 12, 6 e0  b + 18 10 *

Partitioning Method Split on x0 Does not refine the partitions ... * 1 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 e1  a + 17 9 e0  b + 18 10 x0  e2 + f 11 u1  e1 + f 12 u0  e0 + f 15 u2  (u0,u1) r2  (r0,r1) 14 Does not refine the partitions ... b  2 2 c  3 3 Split on x0 d  4 4 f  5 5 e1  a + 17 9 e2  (e0,e1) 6 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 u2  (u0,u1) r2  (r0,r1) 14 x0  e2 + f 11 u1  e1 + f 12 u0  e0 + f 15 Worklist 12, 6 e0  b + 18 10 *

Partitioning Method Split on u1 * Worklist 6, 14 a  1 1 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 e1  a + 17 9 e0  b + 18 10 x0  e2 + f 11 u1  e1 + f 12 u0  e0 + f 15 u2  (u0,u1) 14 r2  (r0,r1) 16 b  2 2 c  3 3 Split on u1 d  4 4 f  5 5 e1  a + 17 9 e2  (e0,e1) 6 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 u2  (u0,u1) r2  (r0,r1) 14 x0  e2 + f 11 u1  e1 + f 12 u0  e0 + f 15 Worklist 6, 14 e0  b + 18 10 *

Partitioning Method Split on e2 Does not refine the partitions ... * 1 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 e1  a + 17 9 e0  b + 18 10 x0  e2 + f 11 u1  e1 + f 12 u0  e0 + f 15 u2  (u0,u1) 14 r2  (r0,r1) 16 Does not refine the partitions ... b  2 2 c  3 3 Split on e2 d  4 4 f  5 5 e1  a + 17 9 e2  (e0,e1) 6 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 u2  (u0,u1) 14 r2  (r0,r1) 16 x0  e2 + f 11 u1  e1 + f 12 u0  e0 + f 15 Worklist 14 e0  b + 18 10 *

Partitioning Method Split on u2 Does not refine the partitions ... * 1 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 a  1 1 b  2 2 c  3 3 d  4 4 f  5 5 e2  (e0,e1) 6 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 e1  a + 17 9 e0  b + 18 10 x0  e2 + f 11 u1  e1 + f 12 u0  e0 + f 15 u2  (u0,u1) 14 r2  (r0,r1) 16 Does not refine the partitions ... b  2 2 c  3 3 Split on u2 d  4 4 f  5 5 e1  a + 17 9 e2  (e0,e1) 6 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 u2  (u0,u1) 14 r2  (r0,r1) 16 x0  e2 + f 11 u1  e1 + f 12 u0  e0 + f 15 Worklist is empty e0  b + 18 10 *

Partitioning Method Now what? We have proved a set of theorems Must rewrite code to use them Knowledge alone won’t do it! a  1 1 m0  a + b n0  a + b q0  a + b s0  a + b v0  a + b y0  a + b 7 b  2 2 c  3 3 d  4 4 f  5 5 e1  a + 17 9 Rebuild the code from the partition Sets with > 1 member  reuse Sets with 1 member  no reuse Let’s look at the code Opportunities are a+b & c+d Can we make this work? e2  (e0,e1) 6 p0  c + d r0  c + d r1  c + d t0  c + d w0  c + d z0  c + d 8 u2  (u0,u1) 14 r2  (r0,r1) 16 x0  e2 + f 11 u1  e1 + f 12 u0  e0 + f 15 e0  b + 18 10

Partitioning Method A B G C D E F Fixing a+b is easy m0  a + b n0  a + b A p0  c + d r0  c + d B r2  (r0,r1) y0  a + b z0  c + d G q0  a + b r1  c + d C e0  b + 18 s0  a + b u0  e + f D e1  a + 17 t0  c + d u1  e + f E e3  (e0,e1) u2  (u0,u1) v0  a + b w0  c + d x0  e + f F Fixing a+b is easy Need to choose the right instance to keep Rest are redundant

Partitioning Method A B G C D E F m0  a + b n0  m0 A p0  c + d r0  c + d B r2  (r0,r1) y0  m0 z0  c + d G q0  m0 r1  c + d C e0  b + 18 s0  m0 u0  e + f D e1  a + 17 t0  c + d u1  e + f E e3  (e0,e1) u2  (u0,u1) v0  m0 w0  c + d x0  e + f F Notice that when we move to a global scope for optimization, we suddenly need to separate analysis & transformation. Fixing c+d is harder Need some rationale for replacement scheme *

Partitioning Method A B G C D E F m0  a + b n0  a + b A p0  c + d r0  c + d B r2  (r0,r1) y0  a + b z0  c + d G q0  a + b r1  c + d C e0  b + 18 s0  a + b u0  e + f D e1  a + 17 t0  c + d u1  e + f E e3  (e0,e1) u2  (u0,u1) v0  a + b w0  c + d x0  e + f F AWZ suggest removing any computation that is dominated by another computation in the same partition For a+b, the def of m0 dominates all other instances For c+d no single instance will do Some cases cannot be caught this way Simpson suggested an alternative approach. *

Partitioning Method Simpson’s suggestion Encode congruences into the name space Same idea Briggs used in reassociation Use LCM to remove redundancies Simplification In SSA name space, there are no KILLs Knocks terms out of some equations Makes initial information cheaper to compute Larger name space, but O(n) rather than O(n2) initialization Consistently outdoes dominator-based replacement Lazy Code Motion is a major extension of AVAIL-based GCSE

} Partitioning Method Is this optimistic or pessimistic? Earlier view said Initialize to top  optimistic Initialize to bottom  pessimistic This algorithm does neither AWZ builds a set of congruence relations Assumes maximal size sets Knocks out infeasible elements Over-estimates set of congruences Finds largest set of self-consistent congruences  Must let it run to completion, or sets might contain lies } inherently optimistic *

Partitioning Method Strengths Global algorithm for finding redundancies Handles arbitrary control flow (loops) Finds largest congruence classes consistent with definition Relies on well understood technology Weaknesses Cannot put 2xa and a+a in same class Not obvious how to handle identities or constants (Click) Slower than DVNT

Redundancy Elimination Wrap-up The partitioning method based on DFA minimization Redundancy Elimination Wrap-up Generalizations Hash-based methods are fastest AWZ find the most cases Expect better results with larger scope Experimental data Ran LVN, SVN, DVNT, AWZ Used global name space for DVNT Requires offline replacement Exposes more opportunities Code was compiled with lots of optimization How did they do? DVNT beat AWZ Improvements grew with scope SCCVN 2.5x faster than AWZ *

Redundancy Elimination Wrap-up Conclusions Redundancy elimination has some depth & subtlety Variations on names, algorithms & analysis matter Compile-time speed does not have to sacrifice code quality DVNT is probably the method of choice Results quite close to the global methods (± 1%) Much lower costs than AWZ