GATE Computer ScienceVery hardGATE CS (PYQ pattern)

The control-flow graph of 1: if p > 0 goto L2; 2: L1: x = x + 1; 3: if x > n goto L3; 4: L2: y = y + x; 5: if y < m goto L1; 6: L3: return y has blocks B0 = {1}, B1 = {2, 3}, B2 = {4, 5}, B3 = {6}. Using 'a back edge is an edge whose head dominates its tail', how many back edges and natural loops does it have?

  1. A. 1 back edge (B2 → B1) and 1 natural loop
  2. B. 2 back edges and 2 natural loops
  3. C. 1 back edge (B1 → B2) and 1 natural loop
  4. D. 0 back edges and 0 natural loops

Correct answer: D. 0 back edges and 0 natural loops

B0 jumps into the cycle B1 ⇄ B2 at both B1 (fall-through) and B2 (goto L2). So neither B1 dominates B2 nor B2 dominates B1 (both have idom B0). Neither cycle edge is a back edge, and natural loops are defined only from back edges: the graph is irreducible and has a cycle but no natural loop.

More Compiler Design questions

Exams that ask this topic