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? t1 = x * y; t2 = y * x; t3 = t1 - t2; t4 = t2 - t1; x = t3; t5 = x * y; t6 = t5 + t4

  1. A. 7
  2. B. 5
  3. C. 6
  4. D. 8

Correct answer: C. 6

There are 2 leaf nodes (initial values) and 4 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