Question
Official answer and solution
- Official answer
- D
- From
- Official GATE 2023 answer key
Solution
Perform backward data-flow analysis to compute LiveOut for each basic block.
A variable is live at the exit of block if it is used along some execution path starting from an outgoing edge of before being redefined.
- In block : statements are . It uses variable and defines . At the exit of , control can loop back to , where and use variables and , while may be used in future iterations. Hence .
- In block : statement is . Successor is (and through loop back to ). At exit of , is immediately overwritten by in , but is needed in , and is used in . Hence .
- In block : uses and updates them. Successors are and . If taking the edge to , (from ) is used, and is preserved. Hence .
- In block : defines , , . The successor immediately uses and , and is preserved. Hence .
Thus, the live variable sets at block exits are B1: {a, i, j}, B2: {a, j}, B3: {a, j}, B4: {a, i, j}.
Final answer
Option (D)
Common trap
Assuming is live at the exit of , forgetting that immediately defines before any use.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2023 Computer Science and Information Technology (CS)
- Question
- 37 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.