
Optimization Types and Functions
SC100 C Compiler
5-9
An example of dependency arising from an algorithm is shown in Example 5-7. The value of the variable
sum
must be calculated before it can be used in the
L_mac
instruction.
Example 5-7. Algorithm instruction dependency
sum = mpy(a,b);
result = L_mac(sum,c,d);
The optimizer can operate most effectively with code which contains as few dependencies as possible.
Section 5.4,
“
Guidelines for Using the Optimizer,
”
provides more detailed advice for writing code that
avoids dependencies and makes the best use of the optimizations.
The sections that follow describe the operation of individual optimizations in detail, and are intended for
advanced users of the SC100 C compiler. If you do not require this level of detail, you may wish to skip
these sections, and turn directly to
Section 5.4,
“
Guidelines for Using the Optimizer.
”
5.3.2 High-Level Optimizations
In the High-Level optimization phase, a number of general, hardware-independent optimizations are
implemented. All high-level optimizations are applied when either optimization level 1 (option -O1) or the
default optimization level 2 (option -O2) is selected. These high-level optimizations are summarized in
Table 5-2 below, and are described in detail in the sections that follow.
The output from the high-level optimization phase is in the form of linear assembly code.
Table 5-2. Summary of High-Level Optimizations
Optimization
Description
Section
Page
Strength reduction (loop transformations)
Transforms array access patterns and induction
variables in loops, and replaces them with pointer
accesses
5.3.2.1
5-10
Function inlining
Substitutes a function call with the code of the
function
5.3.2.2
5-16
Common subexpression elimination
Replaces an expression with its value if it occurs
more than once
5.3.2.3
5-17
Loop invariant code
Moves code outside a loop if its value is unchanged
by the loop
5.3.2.4
5-17
Constant folding and propagation
Calculates the value of an expression at
compilation time if it contains known static
constants
5.3.2.5
5-17
Jump-to-jump elimination
Combines jump instructions
5.3.2.6
5-18
Dead code elimination
Removes code that is never executed
5.3.2.7
5-18
Dead storage/assignment elimination
Removes redundant variables and value
assignments
5.3.2.8
5-18