


















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!



















ILP Optimization
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
Promote with Copy
Y
Promotion alone not legalbecause a live valuedestroyed
Y
Might as well choose True »^
Substitute uses for which defis the only reaching def »^
Insert copy of old_dest =new_dest if original_ped »^
Again, must ensure operationwill not cause a spuriousexception
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
Tree Height Reduction
original:
r9 = r1 + r2 r10 = r9 + r3 r11 = r10 - r4 r12 = r11 + r5 r13 = r12 – r
Y
Obey precedence rules »^
Essentially re-parenthesize
Y
Height reduced (n terms)^ y
n-1 (assuming unit latency) y^
ceil(log2(n))
Number of operationsremains constant »^
Cost^ y
Temporary registers “live”longer
Watch out for^ y
Always ok for integerarithmetic y^
Floating-point – may notbe!!
after back subs:
r13 = r1 + r2 + r3 – r4 + r5 – r r1 + r
r3 – r
r5 – r
final code:^ t1 = r1 + r2^ t2 = r3 – r4^ t3 = r5 – r6^ t4 = t1 + t2^ r13 = t4 + t
Fancier Tree Height Reduction (2)
after back subs:
Y
a(b+c) = ab + bc »^
Or the reverse »^
Danger^ y
Generate more operations y^
Lots of possibilities
Y
Want latencies balanced, notthe number of operations »^
multiply = 3, add = 1
Y
Delay use of late arrivingoperands
r13 = r1r3 + r1r4 + r2r3 + r2r4 r1 * r
r1 * r
r2 * r
r
r2 * r
r1 + r
r3 + r
r
or better yet: r13 = (r1 + r2) * (r3 + r4)
Class Problem
Assume: + = 1, * = 3
operand arrival times
0 r
0 r
0 r
1 r
2 r
0 r
Back susbstitute Re-express in tree-height reduced form
Account for latency and arrival times
Register Renaming on Unrolled Loop
loop:
loop:
r1 = load(r2) r3 = load(r4) r5 = r1 * r3 r6 = r6 + r5 r2 = r2 + 4 r4 = r4 + 4
r1 = load(r2) r3 = load(r4) r5 = r1 * r3 r6 = r6 + r5 r2 = r2 + 4 r4 = r4 + 4
iter
iter
r1 = load(r2) r3 = load(r4) r5 = r1 * r3 r6 = r6 + r5 r2 = r2 + 4 r4 = r4 + 4
r11 = load(r2) r13 = load(r4) r15 = r11 * r13 r6 = r6 + r15 r2 = r2 + 4 r4 = r4 + 4
iter
iter
r1 = load(r2) r3 = load(r4) r5 = r1 * r3 r6 = r6 + r5 r2 = r2 + 4 r4 = r4 + 4 if (r4 < 400) goto loop
r21 = load(r2) r23 = load(r4) r25 = r21 * r23 r6 = r6 + r25 r2 = r2 + 4 r4 = r4 + 4 if (r4 < 400) goto loop
iter
iter
Register Renaming is Not Enough!
Y
Y
r2, r4, r6 sequentialize theiterations »^
Need to rename these
Y
Accumulator variableexpansion (r6) »^
Induction variable expansion(r2, r4)
loop:
r1 = load(r2) r3 = load(r4) r5 = r1 * r3 r6 = r6 + r5 r2 = r2 + 4 r4 = r4 + 4
iter
r11 = load(r2) r13 = load(r4) r15 = r11 * r13 r6 = r6 + r15 r2 = r2 + 4 r4 = r4 + 4
iter
r21 = load(r2) r23 = load(r4) r25 = r21 * r23 r6 = r6 + r25 r2 = r2 + 4 r4 = r4 + 4 if (r4 < 400) goto loop
iter
Induction Variable Expansion
r1 = load(r2)r3 = load(r4)r5 = r1 * r3r6 = r6 + r5r2 = r2 + 12r4 = r4 + 12r11 = load(r12)r13 = load(r14)r15 = r11 * r13r16 = r16 + r15r12 = r12 + 12r14 = r14 + 12r21 = load(r22)r23 = load(r24)r25 = r21 * r23r26 = r26 + r25r22 = r22 + 12r24 = r24 + 12if (r4 < 400) goto loop
iter1 iter2 iter
loop:
r12 = r2 + 4, r22 = r2 + 8r14 = r4 + 4, r24 = r4 + 8r16 = r26 = 0 r6 = r6 + r16 + r
Y
x = x + y or x = x – y »^
where y is loop invariant
Y
Y
Y
Y
Y
Better Induction Variable Expansion
Y
Just change offsets in eachiterations to reflect step »^
Change final increments to n* original step
r1 = load(r2)r3 = load(r4)r5 = r1 * r3r6 = r6 + r5r11 = load(r2+4)r13 = load(r4+4)r15 = r11 * r13r16 = r16 + r15r21 = load(r2+8)r23 = load(r4+8)r25 = r21 * r23r26 = r26 + r25r2 = r2 + 12r4 = r4 + 12if (r4 < 400) goto loop
iter1 iter2 iter
loop:
r16 = r26 = 0 r6 = r6 + r16 + r
New Topic: Code Generation
Determine when every operation executions y Create MultiOps
Map virtual
physical registers
y^
Spill to memory if necessary
What Do We Need to Schedule Operations?
2 issue slots, 1 memory port, 1 adder/multiplier y load = 2 cycles, add = 1 cycle, mpy = 3 cycles; all fully pipelined y Each operand can be register or 6 bit signed literal
What about memory deps? control deps? Delay slots?