

























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
Various compiler optimization techniques including dead code elimination, forward copy propagation, common subexpression elimination, loop optimizations, induction variable strength reduction, class problem optimization, ilp optimization, rename with copy, tree height reduction, optimizing unrolled loops, register renaming on unrolled loops, accumulator variable expansion, and induction variable expansion. The techniques aim to improve compiler performance by reducing redundancy, increasing parallelism, and optimizing memory usage.
Typology: Assignments
1 / 33
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