Peephole Optimizer

The Compiler contains a simple optimizer, called a peephole optimizer. A peephole optimizer optimizes specific co de patterns for speed or code size. After recognizing these specific patterns, the Compiler replaces them with other optimized patterns.

After the Compiler backend generates the optimized code, the generated code may still benefit from further optimization. The peephole optimizer generates backend-dependent code, because optimizer implementation uses the characteristic code patterns of the specific backend.

Certain peephole optimizations only make sense in conjunction with other optimizations, or together with some code patterns. These patterns may have been generated by doing other optimizations. The peephole optimizer removes some optimizations (for example, removing a branch to the next instruction), although the branch optimizer can perform these optimizations as well. The peephole optimizer performs such simple branch optimizations to reach new optimizable states.