GATE Computer ScienceHardGATE CS (PYQ pattern)

In 1: i = 0; 2: L1: if i >= n goto L3; 3: i = i + 1; 4: if i > k goto L1; 5: j = j + i; 6: goto L1; 7: L3: return j, how many back edges does the control-flow graph have, and how many basic blocks are in the loop obtained by merging the natural loops that share a header?

  1. A. 1 back edge; 3 blocks
  2. B. 2 back edges; 3 blocks
  3. C. 2 back edges; 2 blocks
  4. D. 2 back edges; 4 blocks

Correct answer: B. 2 back edges; 3 blocks

Blocks: {1}, {2} (header L1), {3, 4}, {5, 6}, {7}. Both the conditional jump at 4 and the goto at 6 return to L1, and L1 dominates both tails: 2 back edges. Their natural loops are {L1, {3,4}} and {L1, {3,4}, {5,6}}; with a common header they are merged into one loop of 3 blocks ({1} and {7} are outside).

More Compiler Design questions

Exams that ask this topic