Quiz #6 Help Center

Learn more

Warning: The hard deadline has passed. You can attempt it, but you will not get credit for it. You are welcome to try it as a learning exercise.

Question 1

Consider the basic block:
y := 3
x := y
z := 4 * x
Now consider the local optimizations: constant propagation, copy propagation, and constant folding. For this example, what is the best order in which to apply the three optimizations, if each can be applied only once?

Question 2

Now consider an optimization strategy that picks an order for applying copy propagation, constant folding, and constant propagation, and repeatedly performs those three optimizations in the same order until nothing changes.
What is the worst possible order (i.e. requires the most passes) for the basic block given in last question (Question 1)?

Question 3

Consider the following intermediate code:
1     X := 2
2   Label1:
3     Y := X + 1
4     if Z > 8 goto Label2
5     X := 3
6     X := X + 5
7     Y := X + 5
8     X := 2
9     if Z > 10 goto Label1
10    X := 3
11  Label2:
12    Y := X + 2
13    X := 0
14    goto Label3
15    X := 10
16    X := X + X
17  Label3:
18    Y := X + 1
Using the algorithm for constant propagation in the videos, in which of the following lines could the use of X could be replaced by a constant? Assume that no other optimizations are performed before constant propagation.
[check all that apply]

Question 4

Which of the following statements about dataflow analyses is true?
For these choices, dataflow analysis 1 initializes the variables to ⊤ at entry, and to ⊥ at all other points, as discussed in class, while dataflow analysis 2 initializes the variables to ⊤ at all points in the control flow graph.

Question 5

Consider the following program:
1:   x := 5
2:   if y > 1 goto Label3
3: Label1:
4:   w := w + 1
5:   if y > 2 goto Label3
6: Label2:
7:   q := 3
8:   if z < 1 goto Label1
9: Label3:
10:  w := 2
11:  if z > 1 goto Label2
12:  q := y + w
Which variables are live immediately before the execution of statement 7? Assume only variable q is live after statement in line 12.
[Choose all that apply]

Question 6

For the program in last question (Question 5), assume the constant propagation algorithm has completed.
Which of the following statements is true?
L_N is the statement at line N, and C(L,v,in) = C means that at the "in" of statement L variable v is some constant, and C(L,v,in) = ⊤ means v is not a constant.
[Choose all that apply]

Question 7

Assume that the following lines are added before line 1 of the above code in Question 5:
z := 2
y := 3
Which lines (using the numbering given above) are now unreachable?
[Choose all that apply]

Question 8

Consider the program:
1:   z := 3
2:   if b > 0 goto Label1
3:   x := 1
4:   y := 2
5:   z := x + y
6:   goto Label2
7: Label1:
8:   w := x + 1
9:   y := x + 1
10: Label2:
11:  a := x + y
12:  b := a * z
Which of the following local optimal optimizations could be applied to the program, considering all possible orders of applying different optimizations? Assume that only variable b is live on exit from the program.
[Check all that apply]

Question 9

Considering the program in the previous question, which of the following local optimizations will change the output of constant propagation? Mark those that will change the result only when used in conjunction with other optimizations as well.
    
You cannot submit your work until you agree to the Honor Code. Thanks!