Level 1 optimizations, Constant folding, Dead object removal – Zilog Z80380 User Manual
Page 44: Simple jump optimization, Level 2 optimizations, Constant propagation, Copy propagation, Dead code elimination, Common sub expression elimination
Optimization Levels
C-Compiler Overview
2–10
UM004001-COR1103
Level 1 Optimizations
The following is a description of the optimizations that are performed during a level 1 opti-
mization.
Constant Folding
The compiler simplifies expressions by folding them into equivalent forms that require fewer
instructions.
E
XAMPLE
:
Before optimization: a=(b+2) +(c+3); After optimization:
a=b+c+5
Dead Object Removal
Local and static variables that are declared but never used are removed
Simple Jump Optimization
Jump to next instruction is removed. Unreachable code is also removed.
L
EVEL
2 O
PTIMIZATIONS
Level 2 optimization performs all the optimizations in Level 1 plus the following new opti-
mizations.
Constant Propagation
Unaliased local variables are replaced by their assigned constant.
Copy Propagation
The compiler replaces references to the variable with its value. The value could be another
variable, a constant, or a common sub-expression. This replacement increases the chances for
constant folding, common sub-expression elimination, or total elimination of the variable.
Dead Code Elimination
Useless code is removed or changed.
For example:
assignments to local variables that are not
used afterwards are removed.
Common Sub Expression Elimination
When the same value is produced by two or more expressions, the compiler computes the
value once, saves it, and reuses it.