Question

Consider the control flow graph given below.

Control flow graph with ENTRY leading to basic block B1 (a = b + c); B1 branches to B2 (d = a + e) and B3 (e = a + f); B3 loops back to B1; B2 leads to B4 (g = d + e) and then EXIT.

Which one of the following options is the set of live variables at the exit point of each basic block?

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2026 answer key

Solution

Compute use[B]use[B] and def[B]def[B] for each basic block and iterate the backward data-flow equations OUT[B]=⋃S∈succ(B)IN[S]OUT[B] = \bigcup_{S \in succ(B)} IN[S] and IN[B]=use[B]∪(OUT[B]−def[B])IN[B] = use[B] \cup (OUT[B] - def[B]).

For each block BiB_i, let use[Bi]use[B_i] be variables used before definition and def[Bi]def[B_i] be variables defined:

  • B1B_1 (a = b + c): use[B1]={b,c}use[B_1] = \{b, c\}, def[B1]={a}def[B_1] = \{a\}
  • B2B_2 (d = a + e): use[B2]={a,e}use[B_2] = \{a, e\}, def[B2]={d}def[B_2] = \{d\}
  • B3B_3 (e = a + f): use[B3]={a,f}use[B_3] = \{a, f\}, def[B3]={e}def[B_3] = \{e\}
  • B4B_4 (g = d + e): use[B4]={d,e}use[B_4] = \{d, e\}, def[B4]={g}def[B_4] = \{g\}

Backward live-variable equations:

  1. OUT[B4]=∅  ⟹  IN[B4]={d,e}OUT[B_4] = \emptyset \implies IN[B_4] = \{d, e\}.
  2. OUT[B2]=IN[B4]={d,e}  ⟹  IN[B2]={a,e}∪({d,e}−{d})={a,e}OUT[B_2] = IN[B_4] = \{d, e\} \implies IN[B_2] = \{a, e\} \cup (\{d, e\} - \{d\}) = \{a, e\}.
  3. Since B3B_3 initially has IN[B3]={a,f}IN[B_3] = \{a, f\}, OUT[B1]=IN[B2]∪IN[B3]OUT[B_1] = IN[B_2] \cup IN[B_3] contains {a,e,f}\{a, e, f\}, which gives IN[B1]={b,c}∪({a,e,f}−{a})={b,c,e,f}IN[B_1] = \{b, c\} \cup (\{a, e, f\} - \{a\}) = \{b, c, e, f\}.
  4. Because B1B_1 is the successor of B3B_3, OUT[B3]=IN[B1]={b,c,e,f}OUT[B_3] = IN[B_1] = \{b, c, e, f\}, which propagates to IN[B3]={a,f}∪({b,c,e,f}−{e})={a,b,c,f}IN[B_3] = \{a, f\} \cup (\{b, c, e, f\} - \{e\}) = \{a, b, c, f\}.
  5. Consequently, OUT[B1]=IN[B2]∪IN[B3]={a,e}∪{a,b,c,f}={a,b,c,e,f}OUT[B_1] = IN[B_2] \cup IN[B_3] = \{a, e\} \cup \{a, b, c, f\} = \{a, b, c, e, f\}.

Thus the fixed-point OUTOUT sets are: B1:{a,b,c,e,f}B_1:\{a, b, c, e, f\}, B2:{d,e}B_2:\{d, e\}, B3:{b,c,e,f}B_3:\{b, c, e, f\}, B4:∅B_4:\emptyset.

Final answer

Option (A)

Common trap

Forgetting to propagate b,c,fb, c, f around the loop B1→B3→B1B_1 \rightarrow B_3 \rightarrow B_1.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2026 Computer Science and Information Technology - Session 2 (CS2)
Question
45 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.