ITPEC FE Morning October 2019 Question 20

Topic: Software

Which of the following is the main purpose of optimization by a compiler?

Explanation

Reducing the execution time of a program — an optimizing compiler rewrites the generated code so that it runs faster, or uses less memory, without changing what it does.

Typical optimizations are constant folding (computing constant expressions at compile time), removing dead code and repeated subexpressions, moving loop-invariant code out of loops, and keeping variables in registers. All of them spend extra compile time to make the object code faster.

Answer (c)

Why not others:

  • •(a) — maintainability is a property of the source code, which optimization does not touch; it changes only the object code
  • •(b) — optimization makes debugging harder, because statements are reordered and variables removed, so debug builds usually turn it off
  • •(d) — optimization adds analysis work, so it lengthens the time to generate object code rather than shortening it

Key rule: Compiler optimization trades longer compilation for faster or smaller object code, and it must never change the program's result.

Software · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.