




















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
Material Type: Notes; Class: Compiler Constr; Subject: Electrical Engineering And Computer Science; University: University of Michigan - Ann Arbor; Term: Fall 2003;
Typology: Study notes
1 / 28
This page cannot be seen from the preview
Don't miss anything!





















Operation-level – 1 operation in isolation » Constant folding, strength reduction » Dead code elimination (global, but 1 op at a time)
Local – Pairs of operations in same BB » May or may not use dataflow analysis
Global – Again pairs of operations » But, operations in different BBs » Dataflow analysis necessary here
Loop – Body of a loop
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)
Forward propagation ofmoves of the form
When is it legal?
y Guaranteed to reach y May reach not good enough r1 = 5 r2 = r1 + r r1 = r1 + r r7 = r1 + r r8 = r1 + 3 r9 = r1 + 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!
Optimize this applying 1. constant propagation 2. constant folding 3. strength reduction 4. dead code elimination 1: r1 = 0 2: r2 = 10 3: r4 = 1 4: r7 = r1 * 4 5: r6 = 8 6: r2 = 0 7: r3 = r2 / r 8: r3 = r4 * r6 9: r3 = r3 + r 10: r2 = r2 + r111: r6 = r7 * r612: r1 = r1 + 1 13: store (r1, r3)
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)
Y
X: r1 = r2 * r »
r100 = r »
Y: r4 = r2 * r
r4 = r Y
Reduce work » Moves can get copy propagated Y
X and Y have the same opcode » src(X) = src(Y), for all srcs » for all srcs(X) no defs of srci in [X ... Y) » if X is a load, then there is no store thatmay write to address(X) between X and Y
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)
X: r1 = r2 + 4 »
Y: r5 = r1 - 9
r5 = r2 – 5 Y
Y
X is of the form rx +- K » dest(X) != src1(X) » Y is of the form ry +- K (comparisonalso ok) » Y consumes dest(X) » src1(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
r1 = 3 r2 = 10 loop preheader r4 = r4 + 1r7 = r4 * 3 r2 = 0 r3 = r2 + 1 r1 = r1 + 2 store (r1, r3) loop header exit BB backedge BB
Y
X can be moved » src(X) not modified in loop body » X is the only op to modifydest(X) » for all uses of dest(X), X is in theavailable defs set » for all exit BB, if dest(X) is liveon the exit edge, X is in theavailable defs set on the edge » if X not executed on everyiteration, then X must provablynot cause exceptions » if X is a load or store, then thereare no writes to address(X) inloop r1 = 3 r5 = 0 r4 = load(r5) r7 = r4 * 3 r8 = r2 + 1r7 = r8 * r r3 = r2 + 1 r1 = r1 + r7 store (r1, r3)
Can you do LICM w/oavailable defs info?
Rules that need change
First rule approx:
Second rule approx:
This is how thecompiler that I workon does it..