GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Integer code: a = 4; b = a * 2; c = b + n; d = c * 0; e = d + b; f = e - 8; g = n + f; h = g * 1; r = h. Only r is live at the end. The optimiser repeats constant propagation, constant folding, algebraic simplification (x*0 = 0, x*1 = x, x+0 = x), copy propagation and dead-code elimination until nothing changes. How many instructions remain?

  1. A. 7
  2. B. 8
  3. C. 2
  4. D. 1

Correct answer: D. 1

a, b fold to constants (4, 8); d = c*0 becomes 0, so e = 8 and f = 0; g = n + 0 becomes n; h = n*1 becomes n; only r = n survives. Without algebraic rules 7 instructions would remain.

More Compiler Design questions

Exams that ask this topic