Questions: Code Optimization Fundamentals

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A compiler's reaching definitions analysis determines that variable x is assigned the constant value 5 on every path reaching a loop body, and x is not modified inside the loop. Which optimization applies, and what dataflow analysis enables it?

ADead code elimination, enabled by liveness analysis showing x is never used after the loop
BConstant propagation, enabled by reaching definitions analysis proving x always holds the value 5 at each use
CLoop-invariant code motion, enabled by dominator analysis showing the assignment dominates the loop header
DRegister allocation, enabled by an interference graph showing x has a short live range
Question 2 Multiple Choice

After optimization, a compiled program runs 15% faster but produces slightly different output on certain inputs compared to the unoptimized version. How should this be classified?

AA valid optimization — performance gain justifies small deviations in output
BA valid optimization for floating-point operations, which have inherent imprecision
CA compiler bug — preserving observable behavior is an absolute constraint on all optimizations
DAcceptable for machine-dependent optimizations but a bug in machine-independent ones
Question 3 True / False

Machine-independent optimizations like constant propagation and dead code elimination are applied during target-specific code generation to the instruction sequences of the target architecture.

TTrue
FFalse
Question 4 True / False

Applying constant propagation to a program may create opportunities for dead code elimination that would not have been detectable before constant propagation ran.

TTrue
FFalse
Question 5 Short Answer

Why must every compiler optimization be justified by a dataflow analysis that proves the transformation is safe to apply?

Think about your answer, then reveal below.