Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Compiler Design  >  Peephole Optimization in Compiler Design

Peephole Optimization in Compiler Design | Compiler Design - Computer Science Engineering (CSE) PDF Download

Introduction

Peephole optimization is a type of code Optimization performed on a small part of the code. It is performed on a very small set of instructions in a segment of code.

The small set of instructions or small part of code on which peephole optimization is performed is known as peephole or window.

It basically works on the theory of replacement in which a part of code is replaced by shorter and faster code without a change in output. The peephole is machine-dependent optimization. 

Objectives of Peephole Optimization: 
The objective of peephole optimization is as follows:

  • To improve performance
  • To reduce memory footprint
  • To reduce code size

Peephole Optimization Techniques

A. Redundant load and store elimination: In this technique, redundancy is eliminated.

Initial code:
y = x + 5;
i = y;
z = i;
w = z * 3;

Optimized code:
y = x + 5;
i = y;
w = y * 3; 

B. Constant folding: The code that can be simplified by the user itself, is simplified.

Initial code:
x = 2 * 3;

Optimized code:
x = 6; 

C. Strength Reduction: The operators that consume higher execution time are replaced by the operators consuming less execution time.

Initial code:
y = x * 2;

Optimized code:
y = x + x;    or     y = x << 1;

Initial code:
y = x / 2;

Optimized code:
y = x >> 1; 

D. Null sequences: Useless operations are deleted.
E. Combine operations: Several operations are replaced by a single equivalent operation.

The document Peephole Optimization in Compiler Design | Compiler Design - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Compiler Design.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
26 videos|66 docs|30 tests

Top Courses for Computer Science Engineering (CSE)

26 videos|66 docs|30 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Peephole Optimization in Compiler Design | Compiler Design - Computer Science Engineering (CSE)

,

Peephole Optimization in Compiler Design | Compiler Design - Computer Science Engineering (CSE)

,

MCQs

,

Sample Paper

,

shortcuts and tricks

,

mock tests for examination

,

practice quizzes

,

Summary

,

study material

,

Peephole Optimization in Compiler Design | Compiler Design - Computer Science Engineering (CSE)

,

Exam

,

video lectures

,

Extra Questions

,

pdf

,

Free

,

Viva Questions

,

ppt

,

Semester Notes

,

Important questions

,

Previous Year Questions with Solutions

,

past year papers

,

Objective type Questions

;