GATE Computer ScienceModerateGATE CS (PYQ pattern)
Live-variable analysis is used to find dead assignments (target not live immediately after the statement) in 1: x = a + b; 2: if c > 0 goto L1; 3: x = 0; 4: goto L2; 5: L1: y = x; 6: L2: return y. Which assignments are dead?
- A. Statements 1 and 3
- B. None of them
- C. Only statement 1
- D. Only statement 3
Correct answer: D. Only statement 3
x = 0 at 3 is followed only by goto L2 and return y, so x is dead there. x = a + b at 1 is used on the path through L1 (y = x), so it is live after 1 even though the other path overwrites it — it is only partially dead, which liveness cannot remove. y = x at 5 is used by return y.
More Compiler Design questions
- A DAG is built for the basic block x = a b; y = b a; z = x + y; a = z − x; w = a b; v = y + x (+ and commutative, a new leaf for each…
- In the LL(1) table of S → i E t S Z | a; Z → e S | ε; E → b the only multiply-defined cell is M[Z, e]. A parser generator resolves it by…
- Which of the following is/are true for the grammar S → a S | S b | c? I. It is ambiguous. II. It is LL(1). III. It is SLR(1). IV. It is…
- In the LL(1) table of S → A B C; A → a | ε; B → b | ε; C → c | ε, how many cells hold an ε-production, and how many cells of the column…
- Consider the grammar G with productions S → A B C; A → a | ε; B → b | ε; C → c | ε. Which of the following statements is/are true? I. G is…
- int x = 1; int g() { x = x + 1; return x; } int f(int n) { int x = n; if (n == 0) return g(); int r = f(n − 1); return r + g(); } What…