GATE / CS ARCHIVE

GATE CSE 2025 SET 1 / QUESTION 13

Using liveness for register allocation

Compiler Design · Code Generation & Register Allocation · Full GATE CSE 2025 Set 1 paper

GATE 2025 Set 1, Q13 1 mark · MCQ
Report issue

Code Generation & Register Allocation

Question 13, GATE 2025: Which compiler activity uses live-variable analysis? A runtime function-call management; B assigning registers to variables; C strength reduction; D constant folding.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Approach: Ask which optimization needs to know whether an existing variable value can be used again.
A variable is live at a program point if some execution path may read its current value before assigning a new value to that variable. Registers hold only a limited number of such values. If two values must remain available at the same time, allocating the same physical register to both can destroy a value that will be needed.
Register allocation therefore uses live ranges, commonly creating an interference edge between values that are simultaneously live. Values whose live ranges do not overlap can reuse a register. This selects B.
Strength reduction, C, replaces an expensive operation with an equivalent cheaper one, while constant folding, D, evaluates expressions with known constants. Neither is identified by the need for liveness in this question. Runtime call management concerns the calling convention and activation records rather than this particular analysis.

Original paper, page 13 · Answer key