GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Dead-code elimination deletes every assignment whose target is not live immediately after it (live-variable analysis), and is repeated until nothing changes. How many statements does it delete from 1: s = 0; 2: i = 0; 3: L1: if s > n goto L2; 4: s = s + 1; 5: i = i + 1; 6: goto L1; 7: L2: return s? (i is never used outside statements 2 and 5.)
- A. 2
- B. 1
- C. 0
- D. 3
Correct answer: C. 0
i is useless, but liveness cannot see it: i = i + 1 reads i, and around the back edge that read keeps i live after statement 5 and after statement 2. So no assignment has a dead target and nothing is deleted. Removing statements 2 and 5 needs faint-variable (or 'useful code') analysis, which marks a variable used only to compute itself as faint.
More Compiler Design questions
- Same function f(n) = 1 for n ≤ 2, else f(n − 1) + f(n − 2) + f(n − 3). Each activation record takes 28 bytes. What is the maximum stack…
- The SLR(1) table of S → i E t S Z | a; Z → e S | ε; E → b has one shift-reduce conflict (shift e versus reduce Z → ε), resolved as yacc…
- G: S → a A d | b B d | a B e | b A e; A → c; B → c is LR(1) but not LALR(1). Which of these changes, each made on its own, makes the…
- Sethi–Ullman labelling (a leaf is 1 if it is a left child and 0 if it is a right child, since a right operand may come from memory; an…
- An SDD uses N → B N1 { N.val = B.val + 2 × N1.val } | B { N.val = B.val } and B → 0 { B.val = 0 } | 1 { B.val = 1 }. What is N.val at the…
- A SLR(1) parser for the augmented grammar S → id | id [ E ] | id ( E ); E → id parses "id [ id ]". What is the maximum number of grammar…