GATE Computer ScienceHardGATE CS (PYQ pattern)

A basic block is converted to a DAG using value numbering, treating + and * as commutative, reusing an existing node when the same operator is applied to the same operand nodes, and making a new leaf for each variable's initial value. How many nodes (leaves plus interior nodes) does the DAG of this block have? p = a + b; q = p - c; r = q + p; p = r * r; s = q + p; c = a + b; t = c - q; u = b + a

  1. A. 10
  2. B. 8
  3. C. 11
  4. D. 9

Correct answer: D. 9

There are 3 leaf nodes (initial values) and 6 interior nodes; a reassigned variable (like a or p) makes later uses refer to a new node, so same-looking expressions after the kill do not share.

More Compiler Design questions

Exams that ask this topic