GATE / CS ARCHIVE

GATE CSE 2023 / QUESTION 37

GATE CSE 2023 Q37

Compiler Design · Code Optimization & Data-Flow Analysis · Full GATE CSE 2023 paper

GATE 2023, Q37 2 marks · MCQ
Report issue

Code Optimization & Data-Flow Analysis

Question 37, GATE 2023: The control-flow graph has B1: i=m−1;j=n;a=10; B2: i=i+1;j=j−1; B3: a=20; B4: i=a+1. Edges are entry→B1→B2, B2→B3, B2→B4, B3→B4, B4→B2, and B4→exit. Find the live-variable set at each block exit; no values are used after exit.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Liveness means a current value can be read along some future path before redefinition. B4 computes i from a, then can return to B2, where i and j are read; a can also survive to another B4. Thus OUT(B4)={a, i, j}. Before B4 the old i is killed, so IN(B4)={a, j}, yielding OUT(B3)={a, j}. B2 can reach B4 directly or through B3, so OUT(B2)={a, j}; its updates read i, j, yielding IN(B2)={a, i, j}=OUT(B1). Therefore D.

Teaching detail. Use OUT(B)=the union of IN over successor blocks and IN(B)=USE(B) union (OUT(B)−DEF(B)). Here USE(B2)={i,j}, DEF(B2)={i,j}, USE(B3)=∅, DEF(B3)={a}, USE(B4)={a}, DEF(B4)={i}. The loop requires a fixed point rather than a single backward pass. Crucially j remains live through B4 because the next B2 reads it; old i is killed inside B4 but the newly assigned i is live afterward. Values m,n are used only in B1 and are not live at its exit.

Original paper, page 37 · Answer key