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
- A. 7
- B. 5
- C. 6
- 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
- Minimal SSA form is built for 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…
- L is the set of strings over {a, b} that contain abab as a substring but do not end with abab. How many states does the minimal complete…
- An LR parser for E → T E′; E′ → + T E′ | ε; T → F T′; T′ → F T′ | ε; F → ( E ) | id parses "id + id id". How many reductions does it make…
- For each choice of terminals x, y ∈ {a, b, c} consider G(x, y): S → A x B; A → a A | ε; B → b B | y. Of the nine grammars, how many are…
- The grammar S → a S | S a | b is ambiguous. How many distinct parse trees does the string "a a a b a a" have?
- For S → b A d | c A e | b B e; A → x; B → x (augmented), how many ACTION cells of the SLR(1) table are multiply defined, and how many…