Peephole optimization

Peephole optimization is an optimization technique performed on a small set of compiler-generated instructions, known as a peephole or window,[1][2] that involves replacing the instructions with a logically equivalent set that has better performance.

For example:

  • Instead of pushing a register onto the stack and then immediately popping the value back into the register, remove both instructions
  • Instead of multiplying x by 2, do x + x
  • Instead of multiplying a floating point register by 8, add 3 to the floating point register's exponent

The term peephole optimization was introduced by William Marshall McKeeman in 1965.[3]

  1. ^ Cite error: The named reference Muchnick_1997 was invoked but never defined (see the help page).
  2. ^ Cite error: The named reference Grune_2012 was invoked but never defined (see the help page).
  3. ^ Cite error: The named reference McKeeman_1965 was invoked but never defined (see the help page).