Compilers

What basic condition must compiler optimizations respect?

  1. AAlways cutting the instruction count to half or less of the original
  2. BAllowing the program's output to change somewhat if it gets faster
  3. CNot changing the externally visible results of a correct program
Show answer and explanation

Answer: C. Not changing the externally visible results of a correct program

Optimizations transform programs to make them faster or smaller, but they must not change externally visible behavior of correctly written programs, such as output or writes to files. Within this constraint, compilers reorder computations and remove unnecessary ones. How much the instruction count shrinks varies, with no rule of halving. Results may change only when the user explicitly opts in, for example by allowing floating-point reordering.

  • A. There is no rule about how much must be removed.
  • B. Results must not change for the sake of speed.
  • C. Correct. Not changing visible results is the fundamental rule.
Practice this topic Back to topic

More Compilers questions

  1. Which describes instruction selection, one stage of code generation?
  2. Which describes a cross compiler?
  3. When debugging a program compiled with optimization, some variables may show as "unavailable." What is the main reason?
  4. After thoroughly applying constant propagation, constant folding and dead-code elimination to the function above, what does it return and what code remains?
  5. What is the role of lexical analysis in a compiler?