

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























Reading Material
Now Back to Optimization … Last Last Week: Dead Code Elimination
X can be deleted
y
no stores or branches
DU chain empty or destregister not live
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 + r store (r1, r3)
Last Last Week: Global Constant Propagation
y
When dest(X) is a Macro reg,BRL destroys the value
r1 = 5 r2 = ‘_x’
r1 = r1 + r
r7 = r1 – r
r8 = r1 * r
r9 = r1 + r
CSE – Common Subexpression Elimination
Eliminate recomputation of anexpression by reusing the previousresult
»
r1 = r2 * r
»
Æ
r100 = r
»
…
»
r4 = r2 * r
Æ
r4 = r
Benefits
»
Reduce work
»
Moves can get copy propagated
Rules (ops X and Y)
»
X and Y have the same opcode
»
src(X) = src(Y), for all srcs
»
expr(X) is available at Y
»
if X is a load, then there is no storethat may write to address(X) alongany path between X and Y
r1 = r2 * r
r3 = r4 / r
r2 = r2 + 1
r6 = r3 * 7
r5 = r2 * r
r8 = r4 / r r9 = r3 * 7
if op is a load, call it redundant load elimination rather than CSE
Class Problem
Optimize this applying 1. dead code elimination 2. forward copy propagation 3. CSE
Be careful of the predicates!
Loop Invariant Code Motion (LICM)
Execute them only 1x perinvocation of the loop
Be careful with memoryoperations!
Be careful with ops notexecuted every iteration
r1 = 3r5 = 0
r4 = load(r5)
r7 = r4 * 3
r8 = r2 + 1 r7 = r8 * r
r3 = r2 + 1
r1 = r1 + r store (r1, r3)
LICM (2)
Rules
»
X can be moved
»
src(X) not modified in loop body
»
X is the only op to modify dest(X)
»
for all uses of dest(X), X is in theavailable defs set
»
for all exit BB, if dest(X) is live on theexit edge, X is in the available defs set onthe edge
»
if X not executed on every iteration, thenX must provably not cause exceptions
»
if X is a load or store, then there are nowrites to address(X) in loop
r1 = 3r5 = 0
r4 = load(r5)
r7 = r4 * 3
r8 = r2 + 1 r7 = r8 * r
r3 = r2 + 1
r1 = r1 + r store (r1, r3)
Induction Variable Strength Reduction
y
y
Induction Variable Strength Reduction (2)
Rules
»
X is a *, <<, + or – operation
»
src1(X) is a basic ind var
»
src2(X) is invariant
»
No other ops modify dest(X)
»
dest(X) != src(X) for all srcs
»
dest(X) is a register
Transformation
»
Insert the following into the preheader
y
new_reg = RHS(X)
»
If opcode(X) is not add/sub, insert to thebottom of the preheader
y
new_inc = inc(src1(X)) opcode(X) src2(X)
»
else
y
new_inc = inc(src1(X))
»
Insert the following at each update ofsrc1(X)
y
new_reg += new_inc
»
Change X
Æ
dest(X) = new_reg
r5 = r4 - 3 r4 = r4 + 1
r7 = r4 * r
r6 = r4 << 2
ILP Optimization
Register Renaming
Re-use of source variables
Re-use of temporaries
Anti, output dependences
Make each def a uniqueregister
Substitute new name intosubsequent uses
Rename with Copy
The worst case is a web spansall defs/uses
Want to enable some of thedefs within the web to bereordered or executed inparallel
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
Remove dependence betweenCMPP and predicated operation
Modify predicate of an operationto an ancestor predicate
Operation executes more oftenthan it should, “speculated”
Where p2 is an ancestor of p
Legal if x not live on p2 – p
And, op will not cause aspurious exception