























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 2003;
Typology: Study notes
1 / 31
This page cannot be seen from the preview
Don't miss anything!
























Constant Combining
Y
r1 = r2 + 4
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(comparison also ok)
Y consumes dest(X)
src1(X) not modified in (XโฆY)
Loop Optimizations
Recall Loop Terminology
r1 = 3
r2 = 10
loop preheader
r4 = r4 + 1 r7 = r4 * 3
r2 = 0
r3 = r2 + 1
r1 = r1 + 2
store (r1, r3)
loop header
exit BB
backedge BB
Global Variable Migration
Y
Load in preheader
Store at exit points
Y
X is a load or store
address(X) not modified in theloop
if X not executed on everyiteration, then X must provablynot cause an exception
All memory ops in loop whoseaddress can equal address(X)must always have the sameaddress as X
r4 = load(r5)
r4 = r4 + 1
r8 = load(r5)
r7 = r8 * r
store(r5, r4)
store(r5,r7)
Class Problem
Optimize this applying 1. loop invariant removal 2. global variable migration + other optis
r2 = 10
r7 = r4 * r
r6 = load(r10)
r3 = 1 / r
r3 = r4 * r r3 = r3 + r
r2 = r2 + 1
store(r10,r3) store (r2, r3)
Induction Variable Elimination
Y
Y
Find 2 basic induction varsx,y
x,y in same family
y
incremented in same places
increments equal
initial values equal
x not live when you exit loop
for each BB where x isdefined, there are no uses of xbetween first/last defn of xand last/first defn of y
r1 = r1 - 1r2 = r2 - 1
r9 = r2 + r
r7 = r1 * r
r4 = load(r1)
store(r2, r7)
Induction Variable Elimination (2)
ILP Optimization
Register Renaming
Y
Re-use of source variables
Re-use of temporaries
Anti, output dependences
Y
Y
Make each def a uniqueregister
Substitute new name intosubsequent uses
Rename with Copy
Y
The worst case is a web spansall defs/uses
Want to enable some of thedefs within the web to bereordered or executed inparallel
Y
Rename def
Rename uses for which def isthe the only reaching def
Insert copy
y
orig_dest = new_dest
y =
= y
y = = y
= y
y =
= y
= y
Predicate Promotion
Y
Remove dependence betweenCMPP and predicated operation
Modify predicate of an operationto an ancestor predicate
Operation executes more oftenthan it should, โspeculatedโ
Y
Where p2 is an ancestor of p
Legal if x not live on p2 โ p
And, op will not cause aspurious exception
Class Problem
using promotion with renaming
Back Substitution
Y
Account for operatorprecedence
Apply left-to-right withinsame precedence
Y
Create larger expressions
y
Iteratively substitute RHSexpression for LHS variable
Note โ may correspond tomultiple source statements
Enable subsequent optis
Y
Re-compute expression in amore favorable manner
y = a + b + c โ d + e โ f;
r9 = r1 + r2 r10 = r9 + r3 r11 = r10 - r4 r12 = r11 + r5 r13 = r12 โ r
Subs r12:
r13 = r11 + r5 โ r
Subs r11:
r13 = r10 โ r4 + r5 โ r
Subs r
r13 = r9 + r3 โ r4 + r5 โ r
Subs r
r13 = r1 + r2 + r3 โ r4 + r5 โ r