GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A basic block is converted to a DAG with value numbering (+ and * commutative; a new leaf is made for each variable's initial value; a reassigned variable refers to its new node). How many nodes does the DAG have? a1 = x * y; b1 = a1 + z; x = b1; c1 = x * y; d1 = c1 + z; e1 = d1 + b1

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

Correct answer: C. 8

3 leaves for the initial x, y, z; x is reassigned, so c1 = x * y is a different node from a1; total 8 nodes.

More Compiler Design questions

Exams that ask this topic