GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Available-expressions analysis (expressions compared textually, so a * b and b * a differ; assigning an operand kills an expression) is run on 1: t = a * b; 2: if c > 0 goto L1; 3: a = a + 1; 4: u = a * b; 5: goto L2; 6: L1: v = b * a; 7: w = a * b; 8: L2: x = a * b; 9: if x > n goto L3; 10: b = b + x; 11: goto L2; 12: L3: return x. How many expressions are available on entry to statement 8 (L2), and on entry to statement 12 (L3)?

  1. A. 1 and 1
  2. B. 2 and 1
  3. C. 0 and 1
  4. D. 0 and 0

Correct answer: C. 0 and 1

a * b reaches L2 recomputed on both forward paths (statement 4 after a changes, statement 7), but L2 is also entered from the back edge 11 → 8, and b = b + x in statement 10 kills a * b (and b * a). The meet is intersection, so nothing is available at 8. Statement 8 then recomputes a * b and nothing before L3 kills it, so exactly a * b is available at 12.

More Compiler Design questions

Exams that ask this topic