Which ONE of the following techniques used in compiler code optimization uses live variable analysis?
- (A)
Run-time function call management
- (B)
Register assignment to variables
- (C)
Strength reduction
- (D)
Constant folding
Which ONE of the following techniques used in compiler code optimization uses live variable analysis?
Run-time function call management
Register assignment to variables
Strength reduction
Constant folding
ANSWER
The answer is (B): register assignment to variables.
Official answer: BSource: Official answer key, GATE 2025 CS1 (IIT Roorkee)
A variable is live at a point if its current value may still be used later before it is redefined. Live variable analysis is a backward data-flow analysis that finds these points.
Two variables can share a register only if they are never live at the same time, so the live ranges decide which variables may be put in the same register.
Register assignment (allocation) builds an interference graph from the live ranges and colours it. It therefore uses live variable analysis.
Strength reduction replaces an expensive operation with a cheaper one, for example with . It depends on the form of the expression, not on liveness.
Constant folding evaluates constant expressions at compile time. Any data-flow support it needs is constant propagation (reaching definitions), not liveness.
Run-time function call management concerns activation records and the stack. It is not a data-flow optimization.
Only option (B), register assignment to variables, uses live variable analysis.
KEY IDEA
Live variable analysis tells the compiler when a variable's value is still needed. Variables that are never live together can share a register, so register allocation depends on it.
WATCH OUT FOR
Picking constant folding or strength reduction because they are "optimizations that analyse expressions". They use the form of the expression or constant propagation, not liveness. The other classic use of liveness is dead-code elimination.
From the GATE 2025 CS1 paper. Every question of this paper · Download the full paper · All 6 Optimisation questions, with notes