GATE Computer ScienceHardGATE CS (PYQ pattern)

Code: k = 3; m = k * k; k = k + 1; p = k * m; q = p - 36; s = q + z; r = s * 1. Only r is live at the end and z is an input. After constant propagation, folding, algebraic simplification and dead-code elimination (repeated to a fixed point), which instruction sequence is left?

  1. A. s = z; r = s
  2. B. s = z + 12; r = s
  3. C. r = z
  4. D. q = 0; s = q + z; r = s

Correct answer: C. r = z

k = 3, m = 9, then k is reassigned to 4 (a kill), so p = 4*9 = 36 and q = 0; s = 0 + z = z, and r = s*1 = z. Everything collapses to the copy r = z.

More Compiler Design questions

Exams that ask this topic