Directions (Q91–95): Consider the following three-address code.
100: t1 = y + 2
101: initial = x / t1
102: limit = 10
103: if i > j goto 105
104: goto 111
105: if num > b goto 107
106: goto 111
107: num = limit − 1
108: b = y + 2
109: i = i − num
110: goto 103
111: j = i − num
112: k = j + b
Which of the following is the Optimized version for the given TAC in the passage
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: C. 100: t1 = y + 2 101: limit = 10 102: num = 9 103: b = t1 104: if i > j goto 106 105: goto 110 106: if num > b goto 108 107: goto 110 108: i = i - num 109: goto 104 110: j = i - num 111: k = j + b
Explanation
Option C removes the unused 'initial' computation, folds limit − 1 into the constant 9, replaces y + 2 with the already computed t1, and moves these loop-invariant assignments out of the loop, keeping the loop test and updates intact.
Note: Hoisting num = 9 before the first test assumes the loop body runs at least once; this follows the official key.
More Theory of Computation and Compilers questions
- What all blocks does Block 3 and Block 5 dominate in the Flow graph for the TAC given in the passage?
- Which of the followings is the correct Flow graph for the TAC given in the passage?
- Match the LIST-I with LIST-II
- Match List I with List II. List I: A. Type-0 grammar, B. Type-1 grammar, C. Type-2 grammar, D. Type-3 grammar. List II: I. Linear grammar;…
- For the above mentioned passage which of the following is correct?
- Which of the following represented the minimum state DFA for the above specified passage?