Optimization of Basic Block
Optimization of Basic Block
• Constant folding
– 2*pi can be replaced with 6.28 (2*3.14)
Interchange of statements
• Suppose we have a block with two adjacent
statements
– a = b+ c + d
– e = b+c
• We can interchange them as
– e = b+c
–a=e+d
• Hence less registers will be required.
Applications of DAG
• Common sub expression can be detected
automatically.
• Identifiers whose values are used in block can
be determined
• Determine which statements compute values
that could be used outside block .
Peephole Optimization
• A simple but effective technique for locally improving
the target code is peephole optimization, which is
done by examining a sliding window of target
instructions (called the peephole) and replacing
instruction sequences within the peephole by a
shorter or faster sequence, whenever possible.
• Peephole optimization can also be applied directly
after intermediate code generation to improve the
intermediate representation.
• The peephole is a small, sliding window on a program.