GATE Computer ScienceVery hardGATE CS (PYQ pattern)
In the code 1: a = 4; 2: b = n * 2; 3: i = 0; 4: L1: t1 = a * b; 5: t2 = t1 + 8; 6: t3 = i * a; 7: t4 = t2 + t3; 8: c = t1 - 3; 9: t5 = c + t2; 10: i = i + 1; 11: if i < n goto L1; 12: return t4, the loop consists of statements 4 to 11 (back edge at 11). Using the standard definition (operands defined outside the loop, constants, or defined by a single already-invariant statement inside the loop), how many statements inside the loop are loop-invariant and can be hoisted?
- A. 3
- B. 4
- C. 5
- D. 6
Correct answer: B. 4
Invariant statements: [4, 5, 8, 9]. t1 = a*b uses a, b defined outside; t2 = t1 + 8 and c = t1 - 3 depend only on t1; t5 = c + t2 depends on those two. t3 uses the loop variable i, so t3 and t4 are not invariant; the increment i = i + 1 and the test are not either.
More Compiler Design questions
- For 1: a = 0; 2: if p > 0 goto L2; 3: L1: a = a + 1; 4: if a < m goto L1; 5: goto L3; 6: L2: b = 1; 7: if q > 0 goto L1; 8: L3: return a…
- For E → id | E [ E ] | ( E ) (augmented with S′ → E), how many more states does the canonical LR(1) automaton have than the LALR(1)…
- For the grammar E → E + T | T; T → T F | F; F → ( E ) | id, the LALR(1) parser is obtained by merging LR(1) states with identical cores…
- How many distinct LR(0) items does the grammar S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε have (do not augment it; an ε-production…
- Which of the following is/are true? I. Every S-attributed definition is L-attributed. II. Every L-attributed definition can be evaluated…
- For S → S ( S ) | ε (augmented), count the reduce entries ( column included, accept excluded) in the SLR(1) and in the LALR(1) ACTION…