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

Code Optimization Questions and Answers

Answer: A

Correct answer: preserve the meaning of the program for every possible input

Correctness is the constraint within which everything else is negotiable. A transformation that makes the program faster on the cases tested and wrong on one it was not is not an optimisation at all, and this is why compilers reason conservatively and decline transformations they cannot prove safe.

Please log in or register to report this question.

Answer: B

Correct answer: within a single basic block at a time

A basic block is a straight-line run with one entry and one exit, so within it control flow is trivial and every statement executes exactly once in order. That makes local optimisation cheap and certain - no data flow analysis is needed - and correspondingly limited in what it can see.

Please log in or register to report this question.

3.

Match each scope of optimisation with the region it considers.
List I
A. local
B. global
C. interprocedural
D. peephole
List II
1. several procedures together
2. one basic block
3. a short window of adjacent instructions
4. one whole procedure

Answer: C

Correct answer: A-2, B-4, C-1, D-3

Four scopes in increasing order of reach and cost. Peephole works over a short window of adjacent instructions; local optimisation over one basic block; global optimisation over a whole procedure, which is where data flow analysis becomes necessary; and interprocedural optimisation across several procedures at once.

Please log in or register to report this question.

Answer: D

Since control enters a block only at the top and leaves only at the bottom, every instruction runs whenever the block does. That guarantee is what makes local transformations safe without any data flow analysis, and it is why the partition is computed before anything else.

Please log in or register to report this question.

Answer: A

The three leader rules are entirely mechanical, so any two compilers applying them to the same instruction sequence produce exactly the same blocks. Nothing about the source syntax or the block sizes enters into the computation at all.

Please log in or register to report this question.

Answer: B

Correct answer: the basic blocks of the procedure being analysed

The flow graph abstracts away everything inside a block and keeps only the possible transfers of control between blocks. This is exactly the right level for data flow analysis, which asks what holds on entry to and exit from each block and propagates those facts along the edges.

Please log in or register to report this question.

Answer: C

Correct answer: works out at compile time the value of an expression built from literals

Constant folding evaluates \( 3 \times 4 \) to 12 during compilation. It is distinct from constant propagation, which replaces a variable by a constant known to be in it - the two are almost always run together, each exposing further opportunities for the other.

Please log in or register to report this question.

Answer: D

Establishing that only one constant reaches the use is a data flow question. Propagation and folding reinforce one another, each creating opportunities for the other. Running the pair repeatedly until nothing changes is common practice.

Please log in or register to report this question.

Answer: A

An assignment to any operand between the two occurrences invalidates the saved value. Establishing that no such assignment occurs requires available expression analysis. Within a single block the check is much simpler and needs no data flow at all.

Please log in or register to report this question.

Answer: B

Constant propagation may make a branch unreachable and copy propagation may leave an assignment with no remaining uses. Each round of removal can therefore expose more dead code, so the pass is iterated until nothing further changes.

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