GATE Computer ScienceHardGATE CS (PYQ pattern)

Expressions are compared textually (x + y and y + x are different) and an assignment to an operand kills an expression. For 1: a = x + y; 2: if a > 0 goto L1; 3: b = y + x; 4: x = 1; 5: c = x + y; 6: goto L2; 7: L1: d = x + y; 8: L2: e = x + y; 9: return e, which expressions are available on entry to statement 8 (L2)?

  1. A. {x + y, y + x}
  2. B. ∅, since x = 1 kills x + y
  3. C. {y + x}
  4. D. {x + y}

Correct answer: D. {x + y}

Through L1: x + y is computed at 1 and 7 and nothing kills it. Through 3–6: y + x is computed at 3 but killed by x = 1 at 4 (x + y as well), yet statement 5 recomputes x + y after the kill. The meet over both paths leaves {x + y}, so e = x + y at statement 8 can reuse a temporary.

More Compiler Design questions

Exams that ask this topic