Chapter 9: Code generation

Peephole Optimization

. target code often contains redundant instructions and suboptimal constructs

. examine a short sequence of target instruction (peephole) and replace by a shorter or faster sequence

. peephole is a small moving window on the target systems

A statement-by-statement code-generation strategy often produces target code that contains redundant instructions and suboptimal constructs. A simple but effective technique for locally improving the target code is peephole optimization, a method for trying to improve the performance of the target program by examining a short sequence of target instructions (called the peephole) and replacing these instructions by a shorter or faster sequence, whenever possible. The peephole is a small, moving window on the target program. The code in the peephole need not be contiguous, although some implementations do require this.