Docsity

Control Height Reduction: A Branch Height Reduction Optimization for EPIC Architectures - , Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Control Height Reduction: A Branch Height Reduction Optimization for EPIC Architectures - and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

EECS 583 – Lecture 12 ILP Optimization, ControlOptimization, SSA Intro

University of Michigan February 18, 2004

  • 1 -

Class Problem From Last Time

r1 = 0; r2 = 0

r111 = r5 * 2

r110 = r111 + 2

r109 = r1 << 1

r104 = r109 – 10

r113 = r2 – 1

r1 = 0 r2 = 0

r5 = r5 + 1

r11 = r5 * 2

r10 = r11 + 2

r12 = load (r10+0)

r9 = r1 << 1

r4 = r9 - 10

r3 = load(r4+4)

r3 = r3 + 1

store(r4+0, r3)

r7 = r3 << 2

r6 = load(r7+0)

r13 = r2 - 1

r1 = r1 + 1 r2 = r2 + 1

r6, r10, r12, r13 live

r5 = r5 + 1

r111 = r111 + 2 r110 = r110 + 2

r12 = load (r110+0)

r3 = load(r104+4)

r3 = r3 + 1

store(r104+0, r3)

r7 = r3 << 2

r6 = load(r7+0)

r1 = r1 + 1

r109 = r109 + 2 r104 = r104 + 2

r2 = r2 + 1

r113 = r113 + 1

apply ind var str reduction and copy propagation

r6, r110, r12, r113 live

  • 3 -

Recap: Tree Height Reduction

original:

r9 = r1 + r2 r10 = r9 + r3 r11 = r10 - r4 r12 = r11 + r5 r13 = r12 – r

Y

Re-compute expression as abalanced binary tree

Obey precedence rules

Essentially re-parenthesize

Y

Effects

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

r

  • 4 -

Class Problem

Assume: + = 1, * = 3

operand arrival times

0 r

0 r

0 r

1 r

2 r

0 r

r10 = r1 * r2 r11 = r10 + r3 r12 = r11 + r4 r13 = r12 – r5 r14 = r13 + r

Back susbstitute Re-express in tree-height reduced form

Account for latency and arrival times

  • 6 -

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

  • 7 -

Register Renaming is Not Enough!

Y

Still not much overlap possible

Y

Problems

r2, r4, r6 sequentialize theiterations

Need to rename these

Y

2 specialized renaming optis

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

  • 9 -

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

iter

iter2 iter

loop:

r12 = r2 + 4, r22 = r2 + 8r14 = r4 + 4, r24 = r4 + 8r16 = r26 = 0 r6 = r6 + r16 + r

Y

Induction variable

x = x + y or x = x – y

where y is loop invariant

Y

Create n-1 additional inductionvariables

Y

Each iteration uses andmodifies a different inductionvariable

Y

Initialize induction variables toinit, init+step, init+2*step, etc.

Y

Step increased to n*originalstep

Y

Now iterations are completelyindependent !!

  • 10 -

Better Induction Variable Expansion

Y

With base+displacementaddressing, often don’t needadditional induction variables

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

iter

iter2 iter

loop:

r16 = r26 = 0 r6 = r6 + r16 + r

Control CPR: A Branch HeightReduction Optimization for EPICArchitectures PLDI - 1999

Mike Schlansker Scott Mahlke Hewlett-Packard Laboratories Richard Johnson Transmeta Corporation

  • 13 -

Introduction and Problem Statement

Y

Dependences limit performance

Data

Control

Long dependence chains

Sequential code

Y

Problem worse for next generationprocessors

High degree hardwareparallelism

Low degree of programparallelism

Resources idle most of the time

Y

Height reduction optimizations

Traditional compilers focus onreducing operation count

Future compilers need onincreasing program parallelism

b++ = t1;if (a == 0) break;b++ = t2;if (a == 0) break;*b++ = t3;

Loop:

t1 = *a++;t2 = *a++;t3 = a++;if (a != 0) goto Loop;

  • 15 -

Our Approach to Control Height Reduction

Y

Goals

»

Reduce dependence height through a network of branches

»

Reduce number of executed branches

»

Applicable to a large fraction of the program

»

Fit into our existing compiler infrastructure

Y

Difficulty

»

Reducing height while

»

Not increasing operation count

Y

Irredundant Consecutive Branch Method (ICBM)

»

Use branch profile information

»

Optimize likely the important control flow paths

»

Possibly penalize less important paths

  • 16 -

Definitions

E

branch store 1

E

branch

E

branch store 0 store 2

E

a

b

<

a

b

<

a

b

<

Y

Superblock

single-entry linear sequence ofoperations containing 1 or morebranches

Our basic compilation unit

Non-speculative operations

Y

Exit branch

branch to allow early transfer outof the superblock

compare condition (ai

i

< bi) < bi)

Y

On-trace

preferred execution path (E4)

identified by profiling

Y

Off-trace

non-preferred paths (E1, E2, E3)

taking an exit branch

  • 18 -

ICBM for a Simple RISC Processor - Step 2

Move code down through bypass branch

store 0 bypass

off-trace

code

c

c

c

E

E

branch store 1

E

branch

E

store 2

c0 c

c

branch

E

E

branch store 1

E

branch

E

store 2

c0 c

c

branch

E

branch store 1

E

branch

E

branch store 0 store 2

c0 c1 c

bypass

never

occurs

E

c

c

c

Superblock with bypass branch

  • 19 -

ICBM for a Simple RISC Processor - Step 3

Code after downward motion

store 0 bypass

off-trace

code

c

c

c

E

E

branch store 1

E

branch

E

store 2

c0 c

c

branch

E

E

branch store 1

E

branch

E

store 2

c0 c

c

branch

store 0 bypass

off-trace

code

c

c

c

E

store 1

store 2

E

branch store 1

E

branch

E

store 2

c0 c

jump

Simplify resultant code