IAE Academy

GATE 2025 CS1 Q.13: solution and answer

GATE 2025 · CS1Q.13 · 1 mark · MCQ

Which ONE of the following techniques used in compiler code optimization uses live variable analysis?

  1. (A)

    Run-time function call management

  2. (B)

    Register assignment to variables

  3. (C)

    Strength reduction

  4. (D)

    Constant folding

See the question in the paper

Answer and solution

ANSWER

The answer is (B): register assignment to variables.

Official answer: BSource: Official answer key, GATE 2025 CS1 (IIT Roorkee)

  1. 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.

  2. 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.

  3. Register assignment (allocation) builds an interference graph from the live ranges and colours it. It therefore uses live variable analysis.

  4. Strength reduction replaces an expensive operation with a cheaper one, for example with . It depends on the form of the expression, not on liveness.

  5. Constant folding evaluates constant expressions at compile time. Any data-flow support it needs is constant propagation (reaching definitions), not liveness.

  6. Run-time function call management concerns activation records and the stack. It is not a data-flow optimization.

  7. 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

More Optimisation questions