Docsity

3 Solved Problems on Local Value Numbering - Assignment 1 | CS 640, Assignments of Computer Science

Toggle sidebar
bg1
CS 640 HW #1
Fall 2008
Due Sept 22 at classtime
1. For the code below, what optimizations can be detected using Local Value
Numbering? What about DAG construction?
a = 2
b = 3
c = a + b
d = a + a
b = a
e = a + b
c = 3
f = a + c
Value Numbering:
a = 2
b = 3
c = a + b
d = a + a
b = a
e = a + b
c = 3
f = a + c
With value numbering, we can reduce the code to a series of constant assignments,
based on the table.
DAG: Assuming we can only associate names with operator nodes (which you may
or may not have done), we get the following. From this, it is straightforward to see
that a, b and c are constants and that d,e are common expressions. That constant
folding would apply is less obvious and would require additional work.
a,2,b 1 const = 2
b,3,c 2 const = 3
c,(1)+(2),f 3 const = 5
d,(1)+(1),e 4 const = 4
=
2
a,b =
3
b’,c
+c’,f
+d,e
1 1
2
1 23
4 1 1
2
11
11
4
22
13 2
pf3
pf4
pf5

Partial preview of the text

Download 3 Solved Problems on Local Value Numbering - Assignment 1 | CS 640 and more Assignments Computer Science in PDF only on Docsity!

CS 640 HW

Fall 2008

Due Sept 22 at classtime

  1. For the code below, what optimizations can be detected using Local Value Numbering? What about DAG construction? a = 2 b = 3 c = a + b d = a + a b = a e = a + b c = 3 f = a + c Value Numbering: a = 2 b = 3 c = a + b d = a + a b = a e = a + b c = 3 f = a + c With value numbering, we can reduce the code to a series of constant assignments, based on the table. DAG: Assuming we can only associate names with operator nodes (which you may or may not have done), we get the following. From this, it is straightforward to see that a, b and c are constants and that d,e are common expressions. That constant folding would apply is less obvious and would require additional work. a,2,b 1 const = 2 b,3,c 2 const = 3 c,(1)+(2),f 3 const = 5 d,(1)+(1),e 4 const = 4

a,b

b’,c

+ d,e + c’,f

1 1 2 3 1 2 4 1 1 2 1 1 (^41 ) 2 2 3 1 2

T

j

CFG

a b c d e f g h a i

CFG

h

  1. In order to do super-local value numbering, the extended basic blocks (single entry, N exits) in a CFG must be found.  Give the extended basic blocks for the CFG1 from question 3.  Give an algorithm for finding the extended basic blocks of a CFG (assuming we have the basic blocks already). a b c d f h e g i k l a b c d e f i k l

a b j c d e f g h i k l CFG1 – a spanning tree a b c d e f g h a i CFG2 – a spanning tree

  1. For the CFGs on next page, draw a spanning tree and the IDOM trees. Compute the dominance frontiers for all of the join nodes in the CFGs. Spanning trees shown in bold edges. Remember that your spanning trees may be different. Node (CFG1) DF Node (CFG2) DF a - a - b - b - c c, k c e d d, k d e, h e c, k e c, h f d, f f f, h g g, k g c h d, f h - i g i f j d k - l -

Computing DF for CFG1: The following are the join nodes: c, d, g, f, k – These are the only nodes that can appear in a dominance frontier.  First consider node c with predecessors b and e. Node b isn’t interesting since it is c’s immediate dominator. Starting at node e in the IDom tree and moving up until we encounter b, we pass through nodes e and c. Put c in the DF for both nodes.  Consider node d with predecessors b and j. Node b isn’t interesting since it is d’s immediate dominator. Starting at node j in the IDom tree and moving up until we encounter b, we pass through nodes j, h, f and d. Put d in the DF for these nodes.  Consider node g with predecessors e and i. Node e isn’t interesting since it is g’s immediate dominator. Starting at node i in the IDom tree and moving up until we encounter e, we pass through nodes i and g. Put g in the DF for these nodes.  Consider node f with predecessors d and h. Node d isn’t interesting since it is g’s immediate dominator. Starting at node h in the IDom tree and moving up until we encounter d, we pass through nodes h and f. Put f in the DF for these nodes.  Consider node k with predecessors g and d. Node k is immediately dominated by b. Starting at node g in the IDom tree and moving up until we encounter b, we pass through nodes g, e and c. Put k in the DF for these nodes. Starting at node d in the IDom tree and moving up until we encounter b, we pass through node d. Put k in the DF for d.

a

CFG1 –

IDOM tree

CFG2 –

a IDOM tree

b

c d k

e f l

g h

i j

b

h c e d

g f

i