Local/Global Optimization: Predicate Expressions and Dataflow Analysis - Prof. Scott Mahlk, Study notes of Electrical and Electronics Engineering

This document from the university of michigan's eecs 583 course covers local/global optimization, focusing on representing predicate expressions and predicate-sensitive dataflow analysis. The lecture discusses converting predicate expressions to 1-disjunctive normal form (1-dnf), implementing pqs functions, and predicate-sensitive liveness analysis.

Typology: Study notes

Pre 2010

Uploaded on 09/02/2009

koofers-user-zka-1
koofers-user-zka-1 🇺🇸

10 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
EECS 583 – Lecture 11
Local/Global Optimization
University of Michigan
February 12, 2003
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Local/Global Optimization: Predicate Expressions and Dataflow Analysis - Prof. Scott Mahlk and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

EECS 583 – Lecture 11 Local/Global Optimization

University of Michigan February 12, 2003

  • 1 -

Representing Predicate Expressions

Y

1-disjunctive normal form (1-dnf)^ »

Restrict predicate expressions to simple form^ y

Code efficiency, complexity

»^

Make conservative approximations when form does not allow theexact answer to be expressed

»^

Disjunctions of individual symbols^ y

P + Q

  • 3 -

Implementing PQS Functions in 1-dnf (2) lub_diff(E, p) = return Sum(qi-p) for all qi in E. 4 subcases

  1. qi <= p

Æ

qi removed, E += NULL

  1. p <= qi

Æ

E += rel_cmpl(p,qi)

  1. p,qi disjoint

Æ

E += qi

  1. otherwise

Æ

E += approx_diff(p,q)

/* q – p */ approx_diff(p,q)

relative_complement(p, lca(p,q)) relative_complement(p,q)

find a path from q to p E = false for each edge r

Æ

s on path do

let R = S|Ti be the partition

containing r

Æ

s

add Ti to E return E

1 p^

q r^

s

t

Examples: {q} – r =? {q} – p =? {t} – r =? {t} – s =?

  • 4 -

Predicate-Sensitive Dataflow Analysis

Y

Use liveness as representative example

Y

Representation without predicates^ »

On region entry/exit edges

»^

Set of live variables, {r1, r4, r10, r11}

»^

Could represent as a bitvector

Y

Now with predicates^ »

Variable no longer live/not-live

»^

Live for a set of executions

»^

For each variable, have predicate expression in each set^ y

Bitvector becomes vector of predicate expressions

  • 6 -

What About UN/UC CMPP’s?

Destination operands

GEN’

GEN’(p) = GEN(p) – true = false KILL’(p) = KILL(p) + true = true

p = cmpp.un(a<1) if q

Source (data) operands GEN’(a) = GEN(a) + true = true KILL’(a) = KILL(a) – true = false

GEN

Source (predicate) operands

backward analysis

GEN’(q) = GEN(q) + true = true KILL’(q) = KILL(q) – true = false

  • 7 -

What About ON/OC CMPP’s?

Destination operands

GEN’

GEN’(p) = GEN(p) – (a<1)Q KILL’(p) = KILL(p) + (a<1)Q

p = cmpp.on(a<1) if q

Source (data) operands GEN’(a) = GEN(a) + Q KILL’(a) = KILL(a) – Q

GEN

Source (predicate) operands

backward analysis

GEN’(q) = GEN(q) + true = true KILL’(q) = KILL(q) – true = false

  • 9 -

Global Predicate Analysis

Y

Compute local GEN/KILL info^ »

Derive predicate expression per variable via backwards walk ofthe operations

»^

Round predicate expression to T/F at the block entrance^ y

If GEN(x) != false, GEN(x) = true, else = false y If KILL(x) = true, KILL(x) = true, else = false y Conservative y But, global solver does not need to know about predicates !!

»^

Can also extend entire global solver to use predicate expressions^ y

More accurate y Slower y Elcor uses the approximate method

  • 10 -

Class Problem^ r = pclear^ x =^ p,q = cmpp.un.uc (a == b)^ x =

if p

x =

if q

r,s = cmpp.on.uc(c < d)

if p

r,t = cmpp.on.uc(e > f)

if s

u,v = cmpp.un.uc

if r

x =

if s

x =

if v

= x

if r

x =

if t

= x Compute liveness GEN/KILL of x at each point in the block Compute UD chain for “=x if True”, “=x if r”

  • 12 -

Classical Optimizations Y

Operation-level – 1 operation in isolation^ »

Constant folding, strength reduction

Y

Dead code elimination (global, but 1 op at a time)

Y

Local/Global – Pairs of operations^ »

Constant propagation »^

Forward copy propagation »^

Backward copy propagation »^

CSE

»^

Constant combining »^

Operation folding

Y

Loop – Body of a loop^ »

Invariant code removal »^

Global variable migration »^

Induction variable strength reduction »^

Induction variable elimination

  • 13 -

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 each optimization^ »

What it is

»^

When can it be applied (set of conditions that must be satisfied)

  • 15 -

Strength Reduction

Y

Replace expensive ops with cheaper ones»

Constant propagation creates opportunities for this

Y

Power of 2 constants»

Multiply by power of 2, replace with left shift^ y

r1 = r2 * 8

Æ

r1 = r2 << 3

»^

Divide by power of 2, replace with right shift^ y

r1 = r2 / 4

Æ

r1 = r2 >> 2

»^

Remainder by power of 2, replace with logical and^ y

r1 = r2 REM 16

Æ

r1 = r2 & 15

Y

More exotic»

Replace multiply by constant by sequence of shift and adds/subs^ y

r1 = r2 * 6

X^

r100 = r2 << 2; r101 = r2 << 1; r1 = r100 + r

y^

r1 = r2 * 7^ X

r100 = r2 << 3; r1 = r100 – r

  • 16 -

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 destregister 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)

  • 18 -

Constant Propagation Y

Forward propagation of movesof the form^ »

rx = L (where L is a literal) »^

Maximally propagate »^

Assume no instructionencoding restrictions

Y

When is it legal?^ »

SRC: Literal is a hard codedconstant, so never a problem »^

DEST: Must be available^ y

Guaranteed to reach y^

May reach not good enough

r1 = 5r2 = r1 + r

r1 = r1 + r

r7 = r1 + r

r8 = r1 + 3

r9 = r1 + r

  • 19 -

Local Constant Propagation Y

Consider 2 ops, X and Y in aBB, X is before Y^ »

  1. X is a move »^
    1. src1(X) is a literal »^
      1. Y consumes dest(X) »^
        1. There is no definition ofdest(X) between X and Y »^
          1. No danger betw X and Y^ y

When dest(X) is a Macroreg, BRL destroys the value

r1 = 5 r2 = ‘_x’ r3 = 7 r4 = r4 + r1 r1 = r1 + r2 r1 = r1 + 1 r3 = 12 r8 = r1 - r2 r9 = r3 + r5 r3 = r2 + 1 r10 = r3 – r