HP C Programmer's Guide (92434-90009)

88 Chapter4
Optimizing HP C Programs
Level 2 Optimization Modules
Level 2 Optimization Modules
Level 2 performs optimizations within each procedure. At level 2, the optimizer performs
all optimizations performed at the prior level, with the following additions:
FMAC synthesis.
Coloring register allocation.
Induction variable elimination and strength reduction.
Local and global common subexpression elimination.
Advanced constant folding and propagation. (Simple constant folding is done by level 0
optimization.)
Loop invariant code motion.
Store/copy optimization.
Unused definition elimination.
Software pipelining.
Register reassociation.
Loop unrolling.
The examples in this section are shown at the source code level wherever possible.
Transformations that cannot be shown at the source level are shown in assembly
language.
Coloring Register Allocation
The name of this optimization comes from the similarity to map coloring algorithms in
graph theory. This optimization determines when and how long commonly used variables
and expressions occupy a register. It minimizes the number of references to memory (loads
and stores) a code segment makes. This can improve run-time speed.
You can help the optimizer understand when certain variables are heavily used within a
function by declaring these variables with the register qualifier. The first 10 register
qualified variables encountered in the source are honored. You should pick the ten most
important variables to be most effective.
The coloring register allocator may override your choices and promote to a register a
variable not declared register over one that is, based on estimated speed improvements.
The following code shows the type of optimization the coloring register allocation module
performs. The code:
LDI 2,r104
COPY r104,r103
LDO 5(r103),r106
COPY r106,r105
LDO 10(r105),r107