GATE Computer ScienceHardGATE CS (PYQ pattern)

Expressions are compared textually and an assignment to an operand kills the expressions that use it. Which expressions are available on entry to statement 2 (L1) of 1: t = a + b; 2: L1: if t > n goto L2; 3: u = a + b; 4: a = u - 1; 5: v = a + b; 6: t = v; 7: goto L1; 8: L2: return t?

  1. A. ∅
  2. B. {a + b, u − 1}
  3. C. {u − 1}
  4. D. {a + b}

Correct answer: D. {a + b}

From the entry, a + b is computed at 1. Around the loop, a = u − 1 at 4 kills a + b, but statement 5 recomputes it after the kill, and nothing later changes a or b. u − 1 is computed only inside the loop, never on the entry path, so the intersection is {a + b}; hence u = a + b at 3 is redundant.

More Compiler Design questions

Exams that ask this topic