



















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; Professor: Mahlke; Class: Advanced Compilers; Subject: Electrical Engineering And Computer Science; University: University of Michigan - Ann Arbor; Term: Winter 2006;
Typology: Study notes
1 / 27
This page cannot be seen from the preview
Don't miss anything!




















Reading Material^
Classical Optimizations^
Constant folding, strength reduction
Constant propagation »^
Forward copy propagation »^
Backward copy propagation »^
Constant combining »^
Operation folding
Invariant code removal »^
Global variable migration »^
Induction variable strength reduction »^
Induction variable elimination
Caveat^
Strength Reduction^
r1 = r2 * 8
r1 = r2 << 3
r1 = r2 / 4
r1 = r2 >> 2
r1 = r2 REM 16
r1 = r2 & 15
r1 = r2 * 6
^
r100 = r2 << 2; r101 = r2 << 1; r1 = r100 + r
^
r1 = r2 * 7^
r100 = r2 << 3; r1 = r100 – r
Dead Code Elimination^
X can be deleted^
no stores or branches
»^
DU chain empty or destregister not live
Especially in loops »^
Critical operation^
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 = 3r2 = 10 r4 = r4 + 1r7 = r1 * r
r2 = 0
r3 = r3 + 1
r3 = r2 + r1 store (r1, r3)
Constant Propagation^
rx = L (where L is a literal) »^
Maximally propagate »^
Assume no instructionencoding restrictions
SRC: Literal is a hard codedconstant, so never a problem »^
DEST: Must be available^
Guaranteed to reach May reach not good enough
r1 = 5r2 = r1 + r
r1 = r1 + r
r7 = r1 + r
r8 = r1 + 3
r9 = r1 + r
Local Constant Propagation^
When dest(X) is a Macroreg, BRL destroys the value
What About Predicated Code?^
Use global formulation with predicate-sensitive dataflow
Use local formulation
» Predicate dominates – predicate of def >=
predicate of use » Intervening writes do not matter if they are on
disjoint predicater1 = 2 if p1.. .r2 = r1 + r3 if p
Predicated Local Constant Propagation^
3.5. pred(X) >= pred(Y) »^
pred(X)
!= False »^
When dest(X) is a Macroreg, BRL destroys the value
Forward Copy Propagation^
r1 = r »^
r4 = r1 + 1
r4 = r2 + 1
Reduce chain of dependences »^
Eliminate the move
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 = r2r3 = r
r2 = 0
r6 = r3 + 1
r5 = r2 + r
Backward Copy Propagation^
Backward propagation of the LHSof moves»
r1 = r2 + r
r4 = r2 + r
»^
… »^
r5 = r1 + r
r5 = r4 + r
»^
… »^
r4 = r
noop
Rules (ops X and Y in same BB)»
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) afterthe first redefinition of dest(Y)
Class Problem
Optimize this applying 1. dead code elimination2. forward copy propagation3. backward copy propagation4. CSE
Be careful of the predicates!
Loop Optimizations^