• In computing, optimization is the process of modifying a
system to make some aspect of it work more efficiently or
use fewer resources.
• Ex: a computer program may be optimized so that it
executes more rapidly or is capable of operating with less
memory storage or other resources, or draw less power.
• The system may be a single computer program, a
collection of computers or even an entire network such as
• Optimization is a program transformation technique,
which tries to improve the code that consume less
resources (i.e. CPU, Memory) and deliver high speed.
• In optimization, high-level general programming
constructs are replaced by very efficient low-level
• Usually done at the end of the development stage since
it reduces readability & adds code that is used to
improve the performance.
Optimized code’s features:-
• Executes faster
• Code size get reduced
• Efficient memory usage
• Yielding better performance
• Reduces the time and space complexity
Optimizations are classified into two categories:
• Machine independent optimizations - improve target
code without taking properties of target machine into
• Machine dependent optimization - improve target
code by checking properties of target machine.
Criteria for Optimization:-
• An optimization must preserve the meaning of a
-Cannot change the output produced for any input.
-Can not introduce an error.
• Optimization should, on average, speed up programs.
• Optimization should itself be fast and should not delay
the overall compiling process.
Optimization can occur at several levels:
1.Design level:- At the highest level, the design may be
optimized to make best use of the available resources.
– The implementation of this design will benefit from the use of
suitable efficient algorithms and the implementation of these
algorithms will benefit from writing good quality code.
2.Compile level:- Use of an optimizing compiler tends to
ensure that the executable program is optimized at least as
much as the compiler can predict
Improvements can be made at various phases:-
• Source Code: Algorithm's transformation can produce
• Intermediate Code: Compiler can improve loops,
procedure calls and address calculations.
-Typically only optimizing compilers include this phase
• Target Code: Compilers can use registers efficiently
• Main techniques of Optimization:-
There are primarily 3 types of optimizations:-
(1) Local optimization - Apply to a basic block in isolation
(2) Global optimization - Apply across basic blocks
(3) Loop optimization – Apply on loops
Another significant optimization can be:-
(4) peep-hole optimization - Apply across boundaries
• Optimization performed within a basic block.
• This is simplest form of optimizations
• No need to analyze the whole procedure body.
• Just analyze the basic blocks of the procedure.
• The local optimization techniques include:
– Constant Folding
– Constant Propagation
– Algebraic Simplification
– Operator Strength Reduction
– Dead Code Elimination
Local Code Optimization
A) Constant folding-
• As the name suggests, this technique involves folding
the constants by evaluating the expressions that
involves the operands having constant values at the
• Ex: Circumference of circle = (22/7) x Diameter
• Replace (22/7) with 3.14 during compile time and save
the execution time.
Local Code Optimization
B) Constant Propagation-
• In this technique, if some variable has been assigned
some constant value, then it replaces that variable with
its constant value in the further program wherever it has
been used during compilation, provided that its value
does not get alter in between.
• Ex: pi = 3.14, radius = 10
• Area of circle = pi x radius x radius
• Substitutes constants value during compile time and
saves the execution time.
Local Code Optimization
C) Algebraic Simplification-
• Use algebraic properties to simplify expressions
• Some expressions can be simplified by replacing them
with an equivalent expression that is more efficient.
D) Strength Reduction-
• As the name suggests, this technique involves
reducing the strength of the expressions by replacing
the expensive and costly operators with the simple and
E) Dead code elimination-
• Those code are eliminated which either never executes
or are not reachable or even if they get execute, their
output is never utilized.
F) Common sub-expressions elimination:
• Eliminates the redundant expressions and avoids their
computation again and again.
Global Code Optimization
• Optimization across basic blocks within a procedure /function
• Could be restricted to a smaller scope, Example: a loop
• Data-flow analysis is done to perform optimization across basic
• Each basic block is a node in the flow graph of the program.
• These optimizations can be extended to an entire control - flow
• Most of compiler implement global optimizations with well
founded theory and practical gains
• Optimization technique that operates on the one or
few instructions at a time.
• Performs machine dependent improvements
• Peeps into a single or sequence of two to three
instructions (peephole) and replaces it by most
efficient alternative (shorter or faster) instructions.
• Peephole is a small moving window on the target
Characteristics of peep-hole optimizations:-
• Redundant-instruction (loads and stores)elimination
• Flow-of-control optimizations - - Elimination of
multiple jumps (i.e. goto statements)
• Elimination of unreachable code
• Algebraic simplifications
• Reducing operator strength
• Use of machine idioms
• Loop optimization plays an important role in
improving the performance of the source code by
reducing overheads associated with executing
• Loop Optimization can be done by removing:
• Removal of Loop Invariant data:-
Parece que tem um bloqueador de anúncios ativo. Ao listar o SlideShare no seu bloqueador de anúncios, está a apoiar a nossa comunidade de criadores de conteúdo.
Atualizámos a nossa política de privacidade.
Atualizámos a nossa política de privacidade de modo a estarmos em conformidade com os regulamentos de privacidade em constante mutação a nível mundial e para lhe fornecer uma visão sobre as formas limitadas de utilização dos seus dados.
Pode ler os detalhes abaixo. Ao aceitar, está a concordar com a política de privacidade atualizada.