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?
- APeephole optimization
- BLink-time optimization
- 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.