Download MSP430 Optimizing C/C++ Compiler User`s Guide

Transcript
What Kind of Optimization Is Being Performed?
www.ti.com
3.11.8 Induction Variables and Strength Reduction
Induction variables are variables whose value within a loop is directly related to the number of executions
of the loop. Array indices and control variables for loops are often induction variables.
Strength reduction is the process of replacing inefficient 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.
Induction variable analysis and strength reduction together often remove all references to your loopcontrol variable, allowing its elimination.
3.11.9 Loop-Invariant Code Motion
This optimization identifies expressions within loops that always compute to the same value. The
computation is moved in front of the loop, and each occurrence of the expression in the loop is replaced
by a reference to the precomputed value.
3.11.10 Loop Rotation
The compiler evaluates loop conditionals at the bottom of loops, saving an extra branch out of the loop. In
many cases, the initial entry conditional check and the branch are optimized out.
3.11.11 Instruction Scheduling
The compiler performs instruction scheduling, which is the rearranging of machine instructions in such a
way that improves performance while maintaining the semantics of the original order. Instruction
scheduling is used to improve instruction parallelism and hide latencies. It can also be used to reduce
code size.
3.11.12 Tail Merging
If you are optimizing for code size, tail merging can be very effective for some functions. Tail merging finds
basic blocks that end in an identical sequence of instructions and have a common destination. If such a
set of blocks is found, the sequence of identical instructions is made into its own block. These instructions
are then removed from the set of blocks and replaced with branches to the newly created block. Thus,
there is only one copy of the sequence of instructions, rather than one for each block in the set.
3.11.13 Integer Division With Constant Divisor
The optimizer attempts to rewrite integer divide operations with constant divisors. The integer divides are
rewritten as a multiply with the reciprocal of the divisor. This occurs at optimization level 2 (--opt_level=2
or -O2) and higher. You must also compile with the --opt_for_speed option, which selects compile for
speed.
SLAU132K – September 2015
Submit Documentation Feedback
Optimizing Your Code
Copyright © 2015, Texas Instruments Incorporated
65