Partial Redundancy Elimination CS243 Review Session Full - - PowerPoint PPT Presentation

partial redundancy elimination
SMART_READER_LITE
LIVE PREVIEW

Partial Redundancy Elimination CS243 Review Session Full - - PowerPoint PPT Presentation

Partial Redundancy Elimination CS243 Review Session Full Redundancy x = b + c y = b + c z = b + c Partial Redundancy x = b + c z = b + c Partial Redundancy t = b + c x = t t = b + c z = t B1 B2 B3 u = a + b B4 Original graph B5


slide-1
SLIDE 1

Partial Redundancy Elimination

CS243 Review Session

slide-2
SLIDE 2

Full Redundancy

x = b + c y = b + c z = b + c

slide-3
SLIDE 3

Partial Redundancy

x = b + c z = b + c

slide-4
SLIDE 4

Partial Redundancy

t = b + c x = t z = t t = b + c

slide-5
SLIDE 5

u = a + b v = a + b w = a + b b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

Original graph

slide-6
SLIDE 6

u = a + b v = a + b w = a + b b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

Add blocks on critical edges

slide-7
SLIDE 7

u = a + b v = a + b w = a + b b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

slide-8
SLIDE 8

u = a + b v = a + b w = a + b b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

Anticipated expressions: places where it is safe to place a + b

slide-9
SLIDE 9

u = a + b v = a + b w = a + b b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

Can delete added blocks where a + b is not anticipated

slide-10
SLIDE 10

u = a + b v = a + b w = a + b b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

Available expressions: points where a + b could be made available

slide-11
SLIDE 11

u = a + b v = a + b w = a + b b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

Earliest: when can we earliest compute a + b

slide-12
SLIDE 12

u = a + b v = a + b w = a + b b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

Earliest: when can we earliest compute a + b

slide-13
SLIDE 13

u = a + b v = a + b w = a + b b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

How much can we postpone evaluating a + b?

slide-14
SLIDE 14

u = a + b v = a + b w = a + b b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

Latest: need to compute a + b here

slide-15
SLIDE 15

u = a + b v = a + b w = a + b b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

Latest: need to compute a + b here

slide-16
SLIDE 16

u = a + b v = a + b w = a + b b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

Remove added blocks where we are not going to compute anything

slide-17
SLIDE 17

u = t t = a + b v = t t = a + b w = t b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 t = a + b t = a + b

Use a temporary variable to store the result

slide-18
SLIDE 18

u = t t = a + b v = t t = a + b w = t b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 t = a + b t = a + b

slide-19
SLIDE 19

u = t t = a + b v = t t = a + b w = t b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 t = a + b t = a + b

Result not used beyond the block in which the variable is defined

slide-20
SLIDE 20

u = t v = a + b t = a + b w = t b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 t = a + b t = a + b

Clean up unrequired temporaries

slide-21
SLIDE 21

u = t v = a + b t = a + b w = t b = read() B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 t = a + b t = a + b

slide-22
SLIDE 22

More Examples

slide-23
SLIDE 23

i = 0 a = b + c i = i + 1 i < 1000 z = b + c i = 0 t = b + c a = t i = i + 1 i < 1000 z = t B1 B2 B3 B1 B2 B3 B0 B0

slide-24
SLIDE 24

i = 0 a = b + c i = i + 1 i < 1000 z = b + c i = 0 a = t i = i + 1 i < 1000 z = t B1 B2 B3 B1 B2 B3 B0 B0 t = b + c

slide-25
SLIDE 25

c = 2 d = b + c e = b + c a = b + c

B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

c = 2 t = b + c d = t e = t t = b + c a = t

B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11

slide-26
SLIDE 26

c = 2 d = b + c e = b + c a = b + c

B1 B2 B3 B4 B5 B6 B7 B8 B9 B10

c = 2 t = b + c d = t e = t t = b + c a = t

B1 B2 B3 B4 B5 B6 B7 B8 B9 B10

slide-27
SLIDE 27

Dominators

CS243 Review Session

slide-28
SLIDE 28

Example

Draw the dominator tree for this control flow graph.

slide-29
SLIDE 29

Example

Draw the dominator tree for this control flow graph.

{M}

IN = RED OUT = BLACK

{M} {M} {M,B} {M,C} {M,C} {M,C} {M} {M} {M,C,G} {M,C,F} {M,A} {M,D} {M,C,G} {M} {M,D} {M} {M,E} {M,D,L} {M,C,G,J} {M,I} {M} {M,H} {M} {M,K}

slide-30
SLIDE 30

Example

Draw the dominator tree for this control flow graph.

{M}

IN = RED OUT = BLACK

{M} {M} {M,B} {M,C} {M,C} {M,C} {M} {M} {M,C,G} {M,C,F} {M,A} {M,D} {M,C,G} {M} {M,D} {M} {M,E} {M,D,L} {M,C,G,J} {M,I} {M} {M,H} {M} {M,K}

Dominator Tree

slide-31
SLIDE 31

Example

Aside: there are algorithms for constructing the dominator tree directly

  • Tarjan’s algorithm (based on

DFS)

  • Buchsbaum’s algorithm

Dominator Tree

slide-32
SLIDE 32

Example

Find the back edges and natural loops in this graph.

{M}

IN = RED OUT = BLACK

{M} {M} {M,B} {M,C} {M,C} {M,C} {M} {M} {M,C,G} {M,C,F} {M,A} {M,D} {M,C,G} {M} {M,D} {M} {M,E} {M,D,L} {M,C,G,J} {M,I} {M} {M,H} {M} {M,K}

Dominator Tree

slide-33
SLIDE 33

Example

Find the back edges and natural loops in this graph.

{M}

IN = RED OUT = BLACK BACK EDGE = ORANGE

{M} {M} {M,B} {M,C} {M,C} {M,C} {M} {M} {M,C,G} {M,C,F} {M,A} {M,D} {M,C,G} {M} {M,D} {M} {M,E} {M,D,L} {M,C,G,J} {M,I} {M} {M,H} {M} {M,K}

Dominator Tree

slide-34
SLIDE 34

Example

Find the back edges and natural loops in this graph. Natural loop for back edge K → M: all nodes

* All nodes can reach K without passing through M

{M}

IN = RED OUT = BLACK BACK EDGE = ORANGE

{M} {M} {M,B} {M,C} {M,C} {M,C} {M} {M} {M,C,G} {M,C,F} {M,A} {M,D} {M,C,G} {M} {M,D} {M} {M,E} {M,D,L} {M,C,G,J} {M,I} {M} {M,H} {M} {M,K}

Dominator Tree

slide-35
SLIDE 35

Post-dominators

How would we compute the post-dominators for this graph?

slide-36
SLIDE 36

Definitions

A block B dominates block B’ if every path from the entry to B’ goes through B A block B postdominates block B’ if every path from B’ to the exit of the graph goes through B If B dominates B’ and B’ postdominates B, B and B’ are control equivalent * One is executed when and only when the other is

slide-37
SLIDE 37

Example

c = b if (a == 0) goto L e = d + d L: B3 B2 B1

slide-38
SLIDE 38

Example

c = b if (a == 0) goto L e = d + d L: B3 B2 B1

1. B1 and B3 are control equivalent. 2. B1 dominates B2, but B2 does not postdominate B1. 3. B2 does not dominate, B3 but B3 posdominates B2.

slide-39
SLIDE 39

Code Motion

If two blocks are control-equivalent, you may move instructions between the two (upward/downward code motion) assuming there are no conflicting data dependences More to come next week: instruction scheduling lecture

slide-40
SLIDE 40

SSA

Construction of the static single assignment form (SSA) requires dominance frontier information. The dominance frontier of a node d is the set of all nodes n such that d dominates an immediate predecessor of n, but d does not strictly dominate n. More to come in Homework 3: converting to SSA form