Peephole optimization

Peephole optimization is an optimization technique performed on a small set of compiler-generated instructions; the small set is known as the peephole or window.

Peephole optimization involves changing the small set of instructions to an equivalent set that has better performance.

For example:

  • instead of pushing register A onto the stack and then immediately popping the value back into register A, a peephole optimization would remove both instructions;
  • instead of adding A to A, a peephole optimization might do an arithmetic shift left;
  • instead of multiplying a floating point register by 8, a peephole optimization might add 3 to the floating point register's exponent; and
  • instead of multiplying an index by 4, adding the result to a base address to get a pointer value, and then dereferencing the pointer, a peephole optimization might use a hardware addressing mode that accomplishes the same result with one instruction.

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

This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.