Compilers
What basic condition must compiler optimizations respect?
- AAlways cutting the instruction count to half or less of the original
- BAllowing the program's output to change somewhat if it gets faster
- 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.