HP C Programmer's Guide (92434-90009)

90 Chapter4
Optimizing HP C Programs
Level 2 Optimization Modules
A = 10;
B = 15;
C = 60;
Loop Invariant Code Motion
The loop invariant code motion module recognizes instructions inside a loop whose results
do not change and moves them outside the loop. This ensures that the invariant code is
only executed once.
For example, the code:
x=z;
for(i=0; i<10; i)
{
a[i]=4*x+i;
}
becomes:
x=z;
t1=4*x;
for(i=0; i<10; i)
{
a[i]=t1+i;
}
Store/Copy Optimization
Where possible, the store/copy optimization module substitutes registers for memory
locations, by replacing store instructions with copy instructions and deleting load
instructions.
For example, the following HP C code:
a=x+23;
where
a is a local variable
return a;
produces the following code for the unoptimized case:
LDO 23(r26),r1
STW r1,-52(0,sp)
LDW -52(0,sp),ret0
and this code for the optimized case:
LDO 23(r26),ret0
Unused Definition Elimination
The unused definition elimination module removes unused memory location and register
definitions. These definitions are often a result of transformations made by other
optimization modules.
For example, the function: