Compilers

What does dead-code elimination remove?

  1. AThe code for the most frequently executed, most important part of the program
  2. BCode that is never executed and computations whose results are never used
  3. COutput instructions that display results on the screen
Show answer and explanation

Answer: B. Code that is never executed and computations whose results are never used

Dead-code elimination removes code such as the body of a branch whose condition is always false and assignments whose results are never used. Constant propagation and folding leave many such unused assignments behind, so these optimizations are used together. Frequently executed code is precisely what should be made fast, not deleted. Instructions with externally visible effects, such as screen output, are part of the program's result and are kept.

  • A. Frequently executed code must not be deleted.
  • B. Correct. It removes unexecuted code and unused computations.
  • C. Instructions with visible effects are not removed.
Practice this topic Back to topic

More Compilers questions

  1. Which pair gives the advantage and drawback of function inlining?
  2. What is the main effect of loop unrolling?
  3. In the loop above, which computation is a candidate for loop-invariant code motion (hoisting out of the loop)? (Assume x and y are not modified in the loop.)
  4. In the loop above, which transformation applies strength reduction to the index computation i * 4?
  5. Why is the loop above hard to vectorize with SIMD instructions?