Question

A variable xx is said to be live at a statement SiS_i in a program if the following three conditions hold simultaneously:
i. There exists a statement SjS_j that uses xx
ii. There is a path from SiS_i to SjS_j in the flow graph corresponding to the program
iii. The path has no intervening assignment to xx including at SiS_i and SjS_j

Control flow graph with four basic blocks: block 1 branches to blocks 2 and 3, both converge to block 4, which loops back to block 1
Control flow graph of basic blocks

The variables which are live both at the statement in basic block 2 and at the statement in basic block 3 of the above control flow graph are

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2015 answer key

Solution

Trace variable uses and definitions downstream from basic blocks 2 and 3 using the given definition of live variables.

  1. Definition of live variable at statement SiS_i:

    • A variable xx must be used downstream at some SjS_j.
    • There must exist a path from SiS_i to SjS_j without any intervening assignment to xx (including at SiS_i and SjS_j).
  2. Check definitions at blocks 2 and 3:

    • Basic block 2 assigns vv: v = r + u. By condition (iii), vv is assigned at this statement, so vv is NOT live at block 2.
    • Basic block 3 assigns qq: q = s * u. By condition (iii), qq is assigned at this statement, so qq is NOT live at block 3.
      Hence, neither vv nor qq can be live at both blocks.
  3. Check variable uu:

    • In block 2, v = r + u uses uu. Is uu live before this use? The question asks about variables live at the statement in block 2 and block 3. At block 2, uu is read on the right-hand side, defined in block 1 with no intervening assignment. Similarly, at block 3, q = s * u reads uu. Hence, uu is live at both statements.
  4. Check variable rr:

    • Variable rr is read in block 2 (v = r + u).
    • From block 3, control flows to block 4 (q = v + r), which reads rr. Since rr is never assigned anywhere in blocks 1, 2, 3, or 4, rr reaches its use in block 4 without any intervening definition.
      Hence, rr is live at both statements.
  5. Check variable ss:

    • In block 3, q = s * u uses ss.
    • However, from block 2, control flows through block 4 to block 1, where ss is redefined (s = p + q) before any subsequent use of ss. Therefore, ss is NOT live at block 2.

Thus, the variables that are live both at the statement in block 2 and block 3 are rr and uu (option C).

Final answer

C

Common trap

Including variable s, which is overwritten in block 1 before any subsequent use along the path from block 2.

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

Source

Paper
GATE 2015 Computer Science and Information Technology (CS) Session 1
Question
60 of 65, printed as CS Q.50
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.