3.8.9
Loop Induction Variable Optimizations and Strength Reduction
3.8.10 Loop Rotation
3.8.11 Loop Invariant Code Motion
3.8.12 Inline Expansion of Run−Time-Support Library Functions
Loop induction variables are variables whose value within a loop is directly
related to the number of executions of the loop. Array indices and control vari-
ables for loops are very often induction variables. Strength reduction is the
process of replacing costly expressions involving induction variables with
more efficient expressions. For example, code that indexes into a sequence
of array elements is replaced with code that increments a pointer through the
array. Loops controlled by incrementing a counter are written as
TMS320C2x/C2xx/C5x repeat blocks or by using efficient decrement-and-
branch instructions. Induction variable analysis and strength reduction
together often remove all references to your loop control variable, allowing it
to be eliminated entirely. See Example 3−1 and Example 3−5.
The compiler evaluates loop conditionals at the bottom of loops, saving a
costly extra branch out of the loop. In many cases, the initial entry conditional
check and the branch are optimized out.
This optimization identifies expressions within loops that always compute the
same value. The computation is moved in front of the loop, and each occur-
rence of the expression in the loop is replaced by a reference to the precom-
puted value. See Example 3−5.
The compiler replaces calls to small run-time-support functions with inline
code, saving the overhead associated with a function call, as well as providing
increased opportunities to apply other optimizations. See Example 3−5.
What Kind of Optimization Is Being Performed?
Optimizing Your Code
3-21
Need help?
Do you have a question about the TMS320C2x and is the answer not in the manual?