Classical Optimization Techniques in Dataflow Analysis at UMich (EECS 483), Study Guides, Projects, Research of Electrical and Electronics Engineering

This document from the university of michigan covers various classical optimization techniques, including constant folding, strength reduction, dead code elimination, and constant propagation, in the context of dataflow analysis for eecs 483. The concepts, conditions for application, and examples of each optimization.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 09/17/2009

koofers-user-2b8
koofers-user-2b8 🇺🇸

10 documents

1 / 26

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Dataflow Analysis/Opti III
Classical Optimization
EECS 483 – Lecture 20
University of Michigan
Monday, November 22, 2004
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Classical Optimization Techniques in Dataflow Analysis at UMich (EECS 483) and more Study Guides, Projects, Research Electrical and Electronics Engineering in PDF only on Docsity!

Dataflow Analysis/Opti III Classical Optimization

EECS 483 – Lecture 20 University of Michigan Monday, November 22, 2004

  • 1 -

Announcements

Y

Project 3 » Due tonight (Monday) » Can turn it anytime before 9am Tues » Grading will happen next week (Thurs/Fri)

y

Signup sheet available next Monday

Y

No class on Wednes, 11/

  • 3 -

Caveat

Y

Traditional compiler class » Fancy implementations of optimizations, efficient algorithms » Bla bla bla » Spend entire class on 1 optimization

Y

For this class – Go over concepts of eachoptimization » What it is » When can it be applied (set of conditions that must be satisfied)

  • 4 -

Constant Folding Y

Simplify operation based on values of src operands

» Constant propagation creates opportunities for this

Y

All constant operands

» Evaluate the op, replace with a move

y r1 = 3 * 4

Æ

r1 = 12 y r1 = 3 / 0

Æ

??? Don’t evaluate excepting ops !, what about FP?

» Evaluate conditional branch, replace with BRU or noop

y if (1 < 2) goto BB

Æ
BRU BB

y if (1 > 2) goto BB

Æ

convert to a noop

Y

Algebraic identities

» r1 = r2 + 0, r2 – 0, r2 | 0, r2 ^ 0, r2 << 0, r2 >> 0

Æ

r1 = r

» r1 = 0 * r2, 0 / r2, 0 & r

Æ

r1 = 0

» r1 = r2 * 1, r2 / 1

Æ

r1 = r

  • 6 -

Dead Code Elimination

Y

Remove any operation who’sresult is never consumed

Y

Rules

X can be deleted y no stores or branches » DU chain empty or dest not live Y

This misses some dead code!!

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 + r1 store (r1, r3)

  • 7 -

Class Problem

Optimize this applying 1. constant folding 2. strength reduction 3. dead code elimination r1 = 0 r4 = r1 | -1 r7 = r1 * 4 r6 = r r3 = 8 / r r3 = 8 * r6 r3 = r3 + r r2 = r2 + r1r6 = r7 * r6r1 = r1 + 1 store (r1, r3)

  • 9 -

Local Constant Propagation

Y

Consider 2 ops, X and Y ina BB, X is before Y

» 1. X is a move » 2. src1(X) is a literal » 3. Y consumes dest(X) » 4. There is no definition of

dest(X) between X and Y

y Defn is locally available!

» 5. Be careful if dest(X) is SP,

FP or some other specialregister – If so, no subroutinecalls between X and Y

1: r1 = 5 2: r2 = ‘_x’ 3: r3 = 7 4: r4 = r4 + r1 5: r1 = r1 + r2 6: r1 = r1 + 1 7: r3 = 12 8: r8 = r1 - r2 9: r9 = r3 + r5 10: r3 = r2 + 1 11: r10 = r3 – r

  • 10 -

Global Constant Propagation

Y

Consider 2 ops, X and Y indifferent BBs

» 1. X is a move » 2. src1(X) is a literal » 3. Y consumes dest(X) » 4. X is in adef_IN(BB(Y)) » 5. dest(X) is not modified

between the top of BB(Y) and Y

y Rules 4/5 guarantee X is available

» 6. If dest(X) is SP/FP/..., no

subroutine call between X and Y

r1 = 5 r2 = ‘_x’ r1 = r1 + r r7 = r1 – r r8 = r1 * r r9 = r1 + r Note: checks for subroutine calls whenever SP/FP/etc. are involved is required for all optis. I will omit the check from here on!

  • 12 -

Forward Copy Propagation Y

Forward propagation of theRHS of moves

X: r1 = r »

Y: r4 = r1 + 1

Æ

r4 = r2 + 1 Y

Benefits

Reduce chain of dependences » Possibly eliminate the move Y

Rules (ops X and Y)

X is a move » src1(X) is a register » Y consumes dest(X) » X.dest is an available def at Y » X.src1 is an available expr at Y r1 = r2 r3 = r r2 = 0 r6 = r3 + 1 r5 = r2 + r

  • 13 -

Backward Copy Propagation Y

Backward prop. of the LHS of moves

X: r1 = r2 + r

Æ

r4 = r2 + r »

r5 = r1 + r

Æ

r5 = r4 + r »

Y: r4 = r

Æ

noop Y

Rules (ops X and Y in same BB)

dest(X) is a register » dest(X) not live out of BB(X) » Y is a move » dest(Y) is a register » Y consumes dest(X) » dest(Y) not consumed in (X…Y) » dest(Y) not defined in (X…Y) » There are no uses of dest(X) after the firstredefinition of dest(Y)

r1 = r8 + r9 r2 = r9 + r1 r4 = r2 r6 = r2 + 1 r9 = r1 r10 = r6 r5 = r6 + 1 r4 = 0 r8 = r2 + r

  • 15 -

Global CSE

Y

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 store that may writeto address(X) along anypath between X and Y

r1 = r2 * r6^ r3 = r4 / r r2 = r2 + 1 r1 = r3 * 7 r5 = r2 * r6^ r8 = r4 / r7^ r9 = r3 * 7 if op is a load, call it redundant load elimination rather than CSE

  • 16 -

Class Problem

Optimize this applying 1. constant propagation 2. constant folding 3. strength reduction 4. dead code elimination 5. forward copy propagation 6. backward copy propagation 7. CSE r1 = 9 r4 = 4 r5 = 0 r6 = 16 r2 = r3 * r4 r8 = r2 + r r9 = r r7 = load(r2)^ r5 = r9 * r4 r3 = load(r2)^ r10 = r3 / r6^ store (r8, r7) r11 = r r12 = load(r11) store(r12, r3)

  • 18 -

Operation Folding Y

Combine 2 dependent ops into 1complex op

Classic example is MPYADD » r1 = r2 * r »

r5 = r1 + r

Æ

r5 = r2 * r3 + r Y

First op often becomes dead

Y

Borders on machine dependent opti

Y

Rules (ops X and Y in same BB)

X is an arithmetic operation » dest(X) != any src(X) » Y is an arithmetic operation » Y consumes dest(X) » X and Y can be merged » src(X) not modified in (X…Y)

r1 = r2 & 4 r3 = r1 ^ -1 r2 = r3 < 6 r4 = r2 == 0 r5 = r6 << 1 r7 = r5 + r

  • 19 -

Loop Optimizations

Y

The most important set of optimizations » Because programs spend so much time in loops

Y

Optimize given that you know a sequenceof code will be repeatedly executed

Y

Optis » Invariant code removal » Global variable migration » Induction variable strength reduction » Induction variable elimination