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: The term peephole optimization was introduced by William Marshall McKeeman in 1965.[5] The following Java bytecode: can be replaced with the following which executes faster: As for most peephole optimizations, this is based on the relative efficiency of different instructions.The following source code: is straightforwardly compiled to: but can be optimized to: If the compiler saves registers on the stack before calling a subroutine and restores them when returning, consecutive calls to subroutines may have redundant stack instructions.Assuming that subroutine _ADDR2 does not depend on previous register values, removing all of the redundant code in the example above would eventually leave the following code: The dictionary definition of peephole optimization at Wiktionary
optimization techniquecompilerpattern matchingalgorithmJava bytecodevariablesource coderedundant codeObject code optimizersalgorithmic efficiencyCapex Corporationoptimizerobject code optimizerSuperoptimizationDigital Research XLT86Muchnick, Steven StanleyAcademic PressMorgan KaufmannGrune, DickBal, HenriJohn Wiley & Sons, LtdCommunications of the ACMAddison-WesleyAho, Alfred VainoLam, Monica Sin-LingSethi, RaviUllman, Jeffrey DavidPearson EducationCompiler optimizationsLocal value numberingLoop nest optimizationLoop splittingLoop unrollingLoop unswitchingSoftware pipeliningStrength reductionData-flowanalysisAvailable expressionCommon subexpression eliminationConstant foldingDead storeInduction variable recognition and eliminationLive-variable analysisUpwards exposed usesUse-define chainReaching definitionsGlobal value numberingSparse conditional constant propagationCode generationInstruction schedulingInstruction selectionRegister allocationRematerializationDeforestationTail-call eliminationInterprocedural optimizationBounds-checking eliminationCompile-time function executionDead-code eliminationExpression templatesInline expansionJump threadingPartial evaluationProfile-guided optimizationAlias analysisArray-access analysisControl-flow analysisData-flow analysisDependence analysisEscape analysisPointer analysisShape analysisValue range analysis