


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document from the university of michigan covers various classical optimization techniques, including constant folding, strength reduction, dead code elimination, and constant propagation, in the context of dataflow analysis for eecs 483. The concepts, conditions for application, and examples of each optimization.
Typology: Study Guides, Projects, Research
1 / 26
This page cannot be seen from the preview
Don't miss anything!



















Project 3 » Due tonight (Monday) » Can turn it anytime before 9am Tues » Grading will happen next week (Thurs/Fri)
No class on Wednes, 11/
Traditional compiler class » Fancy implementations of optimizations, efficient algorithms » Bla bla bla » Spend entire class on 1 optimization
For this class – Go over concepts of eachoptimization » What it is » When can it be applied (set of conditions that must be satisfied)
Simplify operation based on values of src operands
All constant operands
y r1 = 3 * 4
r1 = 12 y r1 = 3 / 0
??? Don’t evaluate excepting ops !, what about FP?
y if (1 < 2) goto BB
y if (1 > 2) goto BB
convert to a noop
Algebraic identities
Y
Y
X can be deleted y no stores or branches » DU chain empty or dest not live Y
Especially in loops » Critical operation y store or branch operation » Any operation that does notdirectly or indirectly feed acritical operation is dead » Trace UD chains backwardsfrom critical operations » Any op not visited is dead r1 = 3 r2 = 10 r4 = r4 + 1 r7 = r1 * r r2 = 0 r3 = r3 + 1 r3 = r2 + r1 store (r1, r3)
Optimize this applying 1. constant folding 2. strength reduction 3. dead code elimination r1 = 0 r4 = r1 | -1 r7 = r1 * 4 r6 = r r3 = 8 / r r3 = 8 * r6 r3 = r3 + r r2 = r2 + r1r6 = r7 * r6r1 = r1 + 1 store (r1, r3)
Consider 2 ops, X and Y ina BB, X is before Y
y Defn is locally available!
1: r1 = 5 2: r2 = ‘_x’ 3: r3 = 7 4: r4 = r4 + r1 5: r1 = r1 + r2 6: r1 = r1 + 1 7: r3 = 12 8: r8 = r1 - r2 9: r9 = r3 + r5 10: r3 = r2 + 1 11: r10 = r3 – r
Consider 2 ops, X and Y indifferent BBs
y Rules 4/5 guarantee X is available
r1 = 5 r2 = ‘_x’ r1 = r1 + r r7 = r1 – r r8 = r1 * r r9 = r1 + r Note: checks for subroutine calls whenever SP/FP/etc. are involved is required for all optis. I will omit the check from here on!
X: r1 = r »
Y: r4 = r1 + 1
r4 = r2 + 1 Y
Reduce chain of dependences » Possibly eliminate the move Y
X is a move » src1(X) is a register » Y consumes dest(X) » X.dest is an available def at Y » X.src1 is an available expr at Y r1 = r2 r3 = r r2 = 0 r6 = r3 + 1 r5 = r2 + r
X: r1 = r2 + r
r4 = r2 + r »
r5 = r1 + r
r5 = r4 + r »
Y: r4 = r
noop Y
dest(X) is a register » dest(X) not live out of BB(X) » Y is a move » dest(Y) is a register » Y consumes dest(X) » dest(Y) not consumed in (X…Y) » dest(Y) not defined in (X…Y) » There are no uses of dest(X) after the firstredefinition of dest(Y)
Rules (ops X and Y)
r1 = r2 * r6^ r3 = r4 / r r2 = r2 + 1 r1 = r3 * 7 r5 = r2 * r6^ r8 = r4 / r7^ r9 = r3 * 7 if op is a load, call it redundant load elimination rather than CSE
Optimize this applying 1. constant propagation 2. constant folding 3. strength reduction 4. dead code elimination 5. forward copy propagation 6. backward copy propagation 7. CSE r1 = 9 r4 = 4 r5 = 0 r6 = 16 r2 = r3 * r4 r8 = r2 + r r9 = r r7 = load(r2)^ r5 = r9 * r4 r3 = load(r2)^ r10 = r3 / r6^ store (r8, r7) r11 = r r12 = load(r11) store(r12, r3)
Classic example is MPYADD » r1 = r2 * r »
r5 = r1 + r
r5 = r2 * r3 + r Y
Y
Y
X is an arithmetic operation » dest(X) != any src(X) » Y is an arithmetic operation » Y consumes dest(X) » X and Y can be merged » src(X) not modified in (X…Y)
The most important set of optimizations » Because programs spend so much time in loops
Optimize given that you know a sequenceof code will be repeatedly executed
Optis » Invariant code removal » Global variable migration » Induction variable strength reduction » Induction variable elimination