5-8
SC100 C Compiler
Optimization Techniques and Hints
To activate global optimization, specify the
-Og
option in the shell command line, as shown in
Example 5-5 on page 5-7. While you can specify this option together with any of the other optimization
level options, global optimization is generally recommended with optimization level 2. The
-O2
option is
the default and may be omitted.
5.3 Optimization Types and Functions
The optimizer implements two main types of optimization:
High-level optimizations improve the output code without taking into account the properties of the
target machine. These optimizations are described in detail in
Section 5.3.2,
“
High-Level
Optimizations.
”
Low-level optimizations achieve code improvements by exploiting the architecture features of the
target machine.
Section 5.3.3,
“
Low-Level Optimizations,
”
provides a description of these
optimizations.
These two sets of optimizations can be applied with the emphasis on reducing the memory size required by
the program, or on achieving maximum program execution speed. See
Section 5.3.4,
“
Time
Optimizations,
”
and
Section 5.3.5,
“
Space Optimizations,
”
for further detail.
Both sets of optimizations can be applied to individual files and groups of files, in non-global and in global
mode. Refer to
Section 5.2.4,
“
Using Global Optimization,
”
and
Section 5.3.6,
“
Global Optimizations,
”
for more information.
Changes in the code as a result of one optimization may enable another optimization to be applied,
producing an accumulative effect.
5.3.1 Dependencies and Parallelization
Dependency between instructions directly limits how successfully the optimizer can apply the various
optimizations. An instruction is considered to be dependent on another if a change in their order of
execution influences the result of the operation.
The optimizer can group instructions into parallelized execution sets only if these instructions do not
contain dependencies. For a description of parallelized execution sets, refer to
Section 5.1.3,
“
Linear and
Parallelized Code.
”
Parallelization of different parts of the program, or of iterations of the same loop, can
significantly increase the speed of the executable application.
Example 5-6 illustrates a simple dependency between two instructions. The value of
d0
is entirely
different when the order of these instructions is reversed. These instructions cannot be executed in parallel.
Example 5-6. Simple instruction dependency
move.w #5,d0
add d0,d1,d2
; Sets register d0 to 5
; Adds the values in d0 and d1 into register d2