The GATE Grind

GATE 2010 CS (CS1) – Question 47

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

Without spilling values to memory, what is the minimum number of registers needed for this basic block?

a=1
b=10
c=20
d=a+b
e=c+d
f=c+e
b=c+e
e=b+f
d=5+e
return d+f
  1. 2
  2. 3
  3. 4
  4. 6

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) 3

Explanation

Immediately after computing f, the values c,e,f are simultaneously needed: c and e for the next assignment, and f for later uses. Thus at least three registers are required. Three suffice by reusing registers of dead a,b,d values, overwriting c when computing the later b, and overwriting dead operands thereafter. Hence B.

More Code Optimization and Data Flow Analysis questions

All Code Optimization and Data Flow Analysis questions →