The GATE Grind

GATE 2013 CS (CS1) – Question 59

Compiler Design · Code Optimization and Data Flow Analysis · 2 marks · Multiple choice

For the same register-only architecture and complete segment below, apply register allocation only, with no code motion. Find minimum registers to avoid all spilling.

c=a+b;
d=c*a;
e=c+a;
x=c*c;
if (x>a) { y=a*a; }
else { d=d*d; e=e*e; }
  1. 3
  2. 4
  3. 5
  4. 6

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) 4

Explanation

Before computing x, a,c,d,e must all remain live: c is needed for x and the others for the comparison/branches. This gives a lower bound of four registers. The x result can overwrite c at its final use; later branch results can reuse dead registers. Four therefore suffice, B.

More Code Optimization and Data Flow Analysis questions

All Code Optimization and Data Flow Analysis questions →