SlideShare a Scribd company logo
BIRLA INSTITUTE OF TECHNOLOGY
MESRA, JAIPUR CAMPUS
TOPIC : PEEPHOLE OPTIMIZATION
BY:
MEGHAJ KUMAR MALLICK
(MCA/25017/18)
2ND YEAR 3RD SEMESTER
CONTENTS
2
What is an Optimization
Introduction to Peephole Optimization
Working Flow of Peephole Optimization
Replacement Rules
Functioning of Peephole Optimization & Example
Conclusion
References
What is Optimization ??
 Process of transforming a piece of code to make it more efficient (eitherin
terms of time or space) without changing its output or side-effects.
 Tries to minimize or maximize some attributes of an executable computer
program.
Introduction to Peephole
Optimization ??
 Optimization performed over a very small set of
instructions in a segment of generated code.
 Works by recognizing sets of instructions that can be
replaced by shorter or faster sets of instructions.
 Goals:
 improve performance
 reduce code size
 reduce memory footprint
Why it’s needed ??
After compilation, the code still has some flaws
 Scheduling & allocation really are NP-Complete
 Optimizer may not implement every needed transformation
Curing the problem
 More work on scheduling and allocation
 Implement more optimizations
— or —
 Optimize after compilation
 Peephole optimization
 Link-time optimization
Working Flow of Peephole
Optimization
Replacement Rules
Common techniques applied in peephole optimization:-
 Constant folding
– Evaluate constant sub-expressions in advance.
 Strength reduction
– Replace slow operations with faster equivalents.
 Null sequences
– Delete useless operations.
 Combine operations
– Replace several operations with one equivalent.
 Algebraic laws
– Use algebraic laws to simplify or reorder instructions.
 Special case instructions
– Use instructions designed for special operand cases.
 Address mode operations
– Use address modes to simplify code.
Functioning of Peephole
Optimization
 Replacing slow instructions with faster ones
 Removing redundant code
 Removing redundant stack instructions
Functioning (Contd…)
 Replacing slow instructions with faster ones
The following Java byteCode
...
load 1
load 1
mul
...
Can be replaced by
...
load 1
dup
mul
...
Functioning (Contd…)
 Removing redundant code
 Another example is to eliminate redundant load stores.
a = b + c;
d = a + e;
is straightforwardly implemented as
MOV b,
ADD c,
MOV R0, a
MOV a,
ADD e,
MOV R0, d
R0 # Copy b to the register
R0 # Add c to the register, the register is now b+c
# Copy the register to a
R0 # Copy a to the register
R0 # Add e to the register, the register is now a+e [(b+c)+e]
# Copy the register to d
Functioning (Contd…)
 Removing redundant code
but can be optimized to
MOV b,
ADD c,
MOV R0, a
ADD e, R0
MOV R0, d
R0 # Copy b to the register
R0 # Add c to the register, which is now b+c (a)
# Copy the register to a
# Add e to the register, which is now b+c+e [(a)+e]
# Copy the register to d
Functioning (Contd…)
 Removing redundant stack instructions
PUSH AF PUSH AF
PUSH BC PUSH BC
PUSH DE PUSH DE
PUSH HL PUSH HL
POP HL POP HL
POP DE POP DE
POP BC POP BC
POP AF POP AF
CALL _ADDR1 CALL _ADDR2 
PUSH AF
PUSH BC
PUSH DE
PUSH HL
CALL _ADDR1
CALL_ADDR2
POP HL
POP DE
POP BC
POP AF
Functioning (Contd…)
Source Code:
If ( a<b ) {
a = a + b;
}
 Peephole optimization ofjumps
 Eliminate jumps to jumps
 Eliminate jumps after conditional branches
“Adjacent” instructions = “Adjacent in control flow”
IL Code:
PUSH a
PUSH b
CMP a,b
JUMP L1
EXIT
L1:
ADD a,b

Other Considerations
Control-flow operations
 Can clear simplifier’s window at branch or label
 More aggressive approach: combine across branches
 Same considerations arise with predication
Physical versus logical windows
 Can run optimizer over a logical window
 Logical windows (within block) improve effectiveness
Conclusion
So…
 Peephole optimization remains viable
 Post allocation improvements
 Cleans up rough edges
 Peephole technology works for selection
 Description driven matchers
 Used in several important systems
All of this will work equally well in binary-to-binary translation
References
 https://en.wikipedia.org/wiki/Peephole_optimization
 http://www.iosrjournals.org/iosr-jce/papers/Vol9-Issue4/N0948086.pdf?id=255
 https://class.coursera.org/compilers/lecture/76
 https://www.slideshare.net/AnulChaudhary/peephole-optimization-techniques-in-
compiler-design
Peephole Optimization

More Related Content

What's hot

Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
United International University
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
Rajkumar R
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
Anul Chaudhary
 
Basic theorems and properties of boolean algebra
Basic theorems and properties of boolean algebraBasic theorems and properties of boolean algebra
Basic theorems and properties of boolean algebra
Hanu Kavi
 
Pipelining powerpoint presentation
Pipelining powerpoint presentationPipelining powerpoint presentation
Pipelining powerpoint presentation
bhavanadonthi
 
Signal descriptors of 8086
Signal descriptors of 8086Signal descriptors of 8086
Signal descriptors of 8086aviban
 
Csl 202, code converters
Csl 202, code convertersCsl 202, code converters
Csl 202, code converters
CKSunith1
 
Control unit
Control unitControl unit
Control unit
Syed Zaid Irshad
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
Malek Sumaiya
 
Polish Notation In Data Structure
Polish Notation In Data StructurePolish Notation In Data Structure
Polish Notation In Data Structure
Meghaj Mallick
 
Optimization of basic blocks
Optimization of basic blocksOptimization of basic blocks
Optimization of basic blocks
ishwarya516
 
SHIFT REGISTERS
SHIFT REGISTERSSHIFT REGISTERS
SHIFT REGISTERS
kumari36
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
Srichandan Sobhanayak
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
eteaching
 
Control statements
Control statementsControl statements
Control statements
Kanwalpreet Kaur
 
4. block coding
4. block coding 4. block coding
4. block coding
MdFazleRabbi18
 
INSTRUCTION PIPELINING
INSTRUCTION PIPELININGINSTRUCTION PIPELINING
INSTRUCTION PIPELININGrubysistec
 
Recursion
RecursionRecursion
Recursion
Nalin Adhikari
 

What's hot (20)

Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
 
Basic theorems and properties of boolean algebra
Basic theorems and properties of boolean algebraBasic theorems and properties of boolean algebra
Basic theorems and properties of boolean algebra
 
Pipelining powerpoint presentation
Pipelining powerpoint presentationPipelining powerpoint presentation
Pipelining powerpoint presentation
 
Signal descriptors of 8086
Signal descriptors of 8086Signal descriptors of 8086
Signal descriptors of 8086
 
Csl 202, code converters
Csl 202, code convertersCsl 202, code converters
Csl 202, code converters
 
Control unit
Control unitControl unit
Control unit
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
 
Polish Notation In Data Structure
Polish Notation In Data StructurePolish Notation In Data Structure
Polish Notation In Data Structure
 
Optimization of basic blocks
Optimization of basic blocksOptimization of basic blocks
Optimization of basic blocks
 
List
ListList
List
 
SHIFT REGISTERS
SHIFT REGISTERSSHIFT REGISTERS
SHIFT REGISTERS
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
 
Assembler
AssemblerAssembler
Assembler
 
Control statements
Control statementsControl statements
Control statements
 
4. block coding
4. block coding 4. block coding
4. block coding
 
INSTRUCTION PIPELINING
INSTRUCTION PIPELININGINSTRUCTION PIPELINING
INSTRUCTION PIPELINING
 
Recursion
RecursionRecursion
Recursion
 

Similar to Peephole Optimization

Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
Karthik Vivek
 
Compiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCompiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flattening
CAFxX
 
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFunction Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Faisal Shehzad
 
Optimization Techniques
Optimization TechniquesOptimization Techniques
Optimization Techniques
Joud Khattab
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design
LogsAk
 
Computer Architecture Assignment Help
Computer Architecture Assignment HelpComputer Architecture Assignment Help
Computer Architecture Assignment Help
Architecture Assignment Help
 
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization ApproachesPragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Marina Kolpakova
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5PRADEEP
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
ZongYing Lyu
 
Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languages
Ankit Pandey
 
May2010 hex-core-opt
May2010 hex-core-optMay2010 hex-core-opt
May2010 hex-core-optJeff Larkin
 
Cray XT Porting, Scaling, and Optimization Best Practices
Cray XT Porting, Scaling, and Optimization Best PracticesCray XT Porting, Scaling, and Optimization Best Practices
Cray XT Porting, Scaling, and Optimization Best PracticesJeff Larkin
 
Compiler optimization techniques
Compiler optimization techniquesCompiler optimization techniques
Compiler optimization techniques
Hardik Devani
 
Matopt
MatoptMatopt
Compiler presention
Compiler presentionCompiler presention
Compiler presention
Faria Priya
 
ISA.pptx
ISA.pptxISA.pptx
ISA.pptx
FarrukhMuneer2
 
Performance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHPPerformance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHP
Max Romanovsky
 
IUA 2001 Creative Techniques for Application Tuning
IUA 2001   Creative Techniques for Application TuningIUA 2001   Creative Techniques for Application Tuning
IUA 2001 Creative Techniques for Application Tuning
Gary Cherlet
 

Similar to Peephole Optimization (20)

Code optimization
Code optimizationCode optimization
Code optimization
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
 
Compiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCompiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flattening
 
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFunction Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
 
Optimization Techniques
Optimization TechniquesOptimization Techniques
Optimization Techniques
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design
 
Computer Architecture Assignment Help
Computer Architecture Assignment HelpComputer Architecture Assignment Help
Computer Architecture Assignment Help
 
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization ApproachesPragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
 
Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languages
 
May2010 hex-core-opt
May2010 hex-core-optMay2010 hex-core-opt
May2010 hex-core-opt
 
Cray XT Porting, Scaling, and Optimization Best Practices
Cray XT Porting, Scaling, and Optimization Best PracticesCray XT Porting, Scaling, and Optimization Best Practices
Cray XT Porting, Scaling, and Optimization Best Practices
 
Compiler optimization techniques
Compiler optimization techniquesCompiler optimization techniques
Compiler optimization techniques
 
Matopt
MatoptMatopt
Matopt
 
Compiler presention
Compiler presentionCompiler presention
Compiler presention
 
ISA.pptx
ISA.pptxISA.pptx
ISA.pptx
 
Performance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHPPerformance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHP
 
IUA 2001 Creative Techniques for Application Tuning
IUA 2001   Creative Techniques for Application TuningIUA 2001   Creative Techniques for Application Tuning
IUA 2001 Creative Techniques for Application Tuning
 

More from Meghaj Mallick

24 partial-orderings
24 partial-orderings24 partial-orderings
24 partial-orderings
Meghaj Mallick
 
PORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSPORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSS
Meghaj Mallick
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software Testing
Meghaj Mallick
 
Introduction to System Programming
Introduction to System ProgrammingIntroduction to System Programming
Introduction to System Programming
Meghaj Mallick
 
MACRO ASSEBLER
MACRO ASSEBLERMACRO ASSEBLER
MACRO ASSEBLER
Meghaj Mallick
 
Icons, Image & Multimedia
Icons, Image & MultimediaIcons, Image & Multimedia
Icons, Image & Multimedia
Meghaj Mallick
 
Project Tracking & SPC
Project Tracking & SPCProject Tracking & SPC
Project Tracking & SPC
Meghaj Mallick
 
Routing in MANET
Routing in MANETRouting in MANET
Routing in MANET
Meghaj Mallick
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
Meghaj Mallick
 
Architecture and security in Vanet PPT
Architecture and security in Vanet PPTArchitecture and security in Vanet PPT
Architecture and security in Vanet PPT
Meghaj Mallick
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software Engineering
Meghaj Mallick
 
Text Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningText Mining of Twitter in Data Mining
Text Mining of Twitter in Data Mining
Meghaj Mallick
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer Algorithm
Meghaj Mallick
 
Software Development Method
Software Development MethodSoftware Development Method
Software Development Method
Meghaj Mallick
 
Secant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodSecant method in Numerical & Statistical Method
Secant method in Numerical & Statistical Method
Meghaj Mallick
 
Motivation in Organization
Motivation in OrganizationMotivation in Organization
Motivation in Organization
Meghaj Mallick
 
Communication Skill
Communication SkillCommunication Skill
Communication Skill
Meghaj Mallick
 
Partial-Orderings in Discrete Mathematics
 Partial-Orderings in Discrete Mathematics Partial-Orderings in Discrete Mathematics
Partial-Orderings in Discrete Mathematics
Meghaj Mallick
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
Meghaj Mallick
 
Complexity Analysis of Recursive Function
Complexity Analysis of Recursive FunctionComplexity Analysis of Recursive Function
Complexity Analysis of Recursive Function
Meghaj Mallick
 

More from Meghaj Mallick (20)

24 partial-orderings
24 partial-orderings24 partial-orderings
24 partial-orderings
 
PORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSPORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSS
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software Testing
 
Introduction to System Programming
Introduction to System ProgrammingIntroduction to System Programming
Introduction to System Programming
 
MACRO ASSEBLER
MACRO ASSEBLERMACRO ASSEBLER
MACRO ASSEBLER
 
Icons, Image & Multimedia
Icons, Image & MultimediaIcons, Image & Multimedia
Icons, Image & Multimedia
 
Project Tracking & SPC
Project Tracking & SPCProject Tracking & SPC
Project Tracking & SPC
 
Routing in MANET
Routing in MANETRouting in MANET
Routing in MANET
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
 
Architecture and security in Vanet PPT
Architecture and security in Vanet PPTArchitecture and security in Vanet PPT
Architecture and security in Vanet PPT
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software Engineering
 
Text Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningText Mining of Twitter in Data Mining
Text Mining of Twitter in Data Mining
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer Algorithm
 
Software Development Method
Software Development MethodSoftware Development Method
Software Development Method
 
Secant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodSecant method in Numerical & Statistical Method
Secant method in Numerical & Statistical Method
 
Motivation in Organization
Motivation in OrganizationMotivation in Organization
Motivation in Organization
 
Communication Skill
Communication SkillCommunication Skill
Communication Skill
 
Partial-Orderings in Discrete Mathematics
 Partial-Orderings in Discrete Mathematics Partial-Orderings in Discrete Mathematics
Partial-Orderings in Discrete Mathematics
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
 
Complexity Analysis of Recursive Function
Complexity Analysis of Recursive FunctionComplexity Analysis of Recursive Function
Complexity Analysis of Recursive Function
 

Recently uploaded

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 

Recently uploaded (20)

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 

Peephole Optimization

  • 1. BIRLA INSTITUTE OF TECHNOLOGY MESRA, JAIPUR CAMPUS TOPIC : PEEPHOLE OPTIMIZATION BY: MEGHAJ KUMAR MALLICK (MCA/25017/18) 2ND YEAR 3RD SEMESTER
  • 2. CONTENTS 2 What is an Optimization Introduction to Peephole Optimization Working Flow of Peephole Optimization Replacement Rules Functioning of Peephole Optimization & Example Conclusion References
  • 3. What is Optimization ??  Process of transforming a piece of code to make it more efficient (eitherin terms of time or space) without changing its output or side-effects.  Tries to minimize or maximize some attributes of an executable computer program.
  • 4. Introduction to Peephole Optimization ??  Optimization performed over a very small set of instructions in a segment of generated code.  Works by recognizing sets of instructions that can be replaced by shorter or faster sets of instructions.  Goals:  improve performance  reduce code size  reduce memory footprint
  • 5. Why it’s needed ?? After compilation, the code still has some flaws  Scheduling & allocation really are NP-Complete  Optimizer may not implement every needed transformation Curing the problem  More work on scheduling and allocation  Implement more optimizations — or —  Optimize after compilation  Peephole optimization  Link-time optimization
  • 6. Working Flow of Peephole Optimization
  • 7. Replacement Rules Common techniques applied in peephole optimization:-  Constant folding – Evaluate constant sub-expressions in advance.  Strength reduction – Replace slow operations with faster equivalents.  Null sequences – Delete useless operations.  Combine operations – Replace several operations with one equivalent.  Algebraic laws – Use algebraic laws to simplify or reorder instructions.  Special case instructions – Use instructions designed for special operand cases.  Address mode operations – Use address modes to simplify code.
  • 8. Functioning of Peephole Optimization  Replacing slow instructions with faster ones  Removing redundant code  Removing redundant stack instructions
  • 9. Functioning (Contd…)  Replacing slow instructions with faster ones The following Java byteCode ... load 1 load 1 mul ... Can be replaced by ... load 1 dup mul ...
  • 10. Functioning (Contd…)  Removing redundant code  Another example is to eliminate redundant load stores. a = b + c; d = a + e; is straightforwardly implemented as MOV b, ADD c, MOV R0, a MOV a, ADD e, MOV R0, d R0 # Copy b to the register R0 # Add c to the register, the register is now b+c # Copy the register to a R0 # Copy a to the register R0 # Add e to the register, the register is now a+e [(b+c)+e] # Copy the register to d
  • 11. Functioning (Contd…)  Removing redundant code but can be optimized to MOV b, ADD c, MOV R0, a ADD e, R0 MOV R0, d R0 # Copy b to the register R0 # Add c to the register, which is now b+c (a) # Copy the register to a # Add e to the register, which is now b+c+e [(a)+e] # Copy the register to d
  • 12. Functioning (Contd…)  Removing redundant stack instructions PUSH AF PUSH AF PUSH BC PUSH BC PUSH DE PUSH DE PUSH HL PUSH HL POP HL POP HL POP DE POP DE POP BC POP BC POP AF POP AF CALL _ADDR1 CALL _ADDR2  PUSH AF PUSH BC PUSH DE PUSH HL CALL _ADDR1 CALL_ADDR2 POP HL POP DE POP BC POP AF
  • 13. Functioning (Contd…) Source Code: If ( a<b ) { a = a + b; }  Peephole optimization ofjumps  Eliminate jumps to jumps  Eliminate jumps after conditional branches “Adjacent” instructions = “Adjacent in control flow” IL Code: PUSH a PUSH b CMP a,b JUMP L1 EXIT L1: ADD a,b 
  • 14. Other Considerations Control-flow operations  Can clear simplifier’s window at branch or label  More aggressive approach: combine across branches  Same considerations arise with predication Physical versus logical windows  Can run optimizer over a logical window  Logical windows (within block) improve effectiveness
  • 15. Conclusion So…  Peephole optimization remains viable  Post allocation improvements  Cleans up rough edges  Peephole technology works for selection  Description driven matchers  Used in several important systems All of this will work equally well in binary-to-binary translation
  • 16. References  https://en.wikipedia.org/wiki/Peephole_optimization  http://www.iosrjournals.org/iosr-jce/papers/Vol9-Issue4/N0948086.pdf?id=255  https://class.coursera.org/compilers/lecture/76  https://www.slideshare.net/AnulChaudhary/peephole-optimization-techniques-in- compiler-design