GATE Computer ScienceModerateGATE CS (PYQ pattern)

Live-variable analysis is used to find dead assignments (target not live immediately after the statement) in 1: x = a + b; 2: if c > 0 goto L1; 3: x = 0; 4: goto L2; 5: L1: y = x; 6: L2: return y. Which assignments are dead?

  1. A. Statements 1 and 3
  2. B. None of them
  3. C. Only statement 1
  4. D. Only statement 3

Correct answer: D. Only statement 3

x = 0 at 3 is followed only by goto L2 and return y, so x is dead there. x = a + b at 1 is used on the path through L1 (y = x), so it is live after 1 even though the other path overwrites it — it is only partially dead, which liveness cannot remove. y = x at 5 is used by return y.

More Compiler Design questions

Exams that ask this topic