Machine-translated by Google. Questions are authored in English.
Top

Code Optimization Questions and Answers

Answer: C

The copy itself often becomes dead once every use has been rewritten. Copy propagation followed by dead code elimination is a standard pairing. Neither pass on its own achieves much, but together they clean up a great deal.

Please log in or register to report this question.

Answer: D

Correct answer: a cheaper one computing the same result

The classic case is replacing a multiplication in a loop by a repeated addition, since an induction variable growing by a fixed amount can be updated incrementally. Replacing a division by a shift where the divisor is a power of two is another. The result must be identical, which is why the transformation is delicate on signed and floating point types.

Please log in or register to report this question.

Answer: A

Correct answer: out of the loop when its operands do not change within it

If nothing the computation depends on is modified inside the loop, the result is the same on every iteration and it can be computed once in a preheader. The payoff is proportional to the trip count, which makes this one of the most valuable loop transformations, and it depends on data flow analysis to establish that the operands really are invariant.

Please log in or register to report this question.

14.

Assertion (A): Loop invariant code is hoisted into a preheader block rather than simply placed before the loop.
Reason (R): The preheader gives the loop a single entry point through which the hoisted computation is guaranteed to pass exactly once.

Answer: B

Both are true and the reason gives the mechanism, and it matters when a loop has several entering edges. Creating the preheader makes the transformation valid without having to duplicate the hoisted code on every edge.

Please log in or register to report this question.

Answer: C

A basic induction variable advances by a constant step. Derived induction variables computed from it can often be updated incrementally, or eliminated in favour of one another. Address computations inside array loops are the classic example.

Please log in or register to report this question.

Answer: D

Several iterations in one pass amortise the loop overhead and expose more instructions for scheduling. The cost is a larger body, which may hurt instruction cache behaviour. Compilers therefore choose the unroll factor by heuristic rather than blindly.

Please log in or register to report this question.

Answer: A

The first three all exploit the repeated structure of a loop. Peephole optimisation examines a short window of adjacent instructions and knows nothing about loops at all. It is nonetheless one of the cheapest passes for the improvement it yields.

Please log in or register to report this question.

Answer: B

Merging halves the loop overhead and can improve locality by touching the same data once instead of twice. A dependence between the loops makes the transformation unsafe. Matching iteration ranges are also required before the loops can be merged.

Please log in or register to report this question.

Answer: C

Splitting a body lets each resulting loop touch a smaller working set or be vectorised independently. Which of fusion and fission helps depends entirely on the code and the machine. Measurement rather than principle usually decides the question.

Please log in or register to report this question.

Answer: D

The window slides over the generated code and recognised patterns are replaced. Redundant loads and stores, jumps to jumps and unreachable code are the usual targets. The pass is cheap enough to run after every other transformation.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Code Optimization Questions and Answers || Code Optimization MCQ Questions and Answers || Code Optimization GK Questions and Answers || Code Optimization GK MCQ Questions || Code Optimization Multiple Choice Questions and Answers || Code Optimization GK || GK on Code Optimization || Compiler Design Questions and Answers || Compiler Design MCQ Questions and Answers || Compiler Design GK Questions and Answers || GK on Compiler Design