Compilers

What is the optimization called that examines short sequences of generated machine code through a small window and replaces wasteful instruction combinations with better ones?

  1. APeephole optimization
  2. BLink-time optimization
  3. CProfile-guided optimization
Show answer and explanation

Answer: A. Peephole optimization

Peephole optimization looks at just a few consecutive instructions, as if through a peephole, and replaces any waste it finds. For example, it removes a load from a location just stored to, deletes an instruction that adds 0, or merges two instructions into one. Usually applied after code generation, it is simple but effective. Link-time optimization optimizes the whole program, and profile-guided optimization uses execution records.

  • A. Correct. It finds and replaces waste within a few-instruction window.
  • B. Link-time optimization optimizes the whole program together.
  • C. PGO uses execution records to optimize.
Practice this topic Back to topic

More Compilers questions

  1. In the code above, which optimization applies after inlining sq, and with what result?
  2. Which describes software pipelining?
  3. Why does a compiler with strict settings not reorder the floating-point sum (a + b) + c into a + (b + c) on its own?
  4. Which kind of instruction does a compiler's automatic vectorization use?
  5. What basic condition must compiler optimizations respect?