HP C Programmer's Guide (92434-90009)

Chapter 4 85
Optimizing HP C Programs
Level 1 Optimization Modules
Level 1 Optimization Modules
The level 1 optimization modules are:
Branch optimization.
Dead code elimination.
Faster register allocation.
Instruction scheduler.
Peephole optimization.
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. See <Undefined Cross-Reference> for descriptions of the assembly language
instructions used.
Branch Optimization
The branch optimization module traverses the procedure and transforms branch
instruction sequences into more efficient sequences where possible. Examples of possible
transformations are:
Deleting branches whose target is the fall-through instruction; that is, the target is two
instructions away.
When the target of a branch is an unconditional branch, changing the target of the first
branch to be the target of the second unconditional branch.
Transforming an unconditional branch at the bottom of a loop, branching to a
conditional branch at the top of the loop, into a conditional branch at the bottom of the
loop.
Changing an unconditional branch to the exit of a procedure into an exit sequence
where possible.
Changing conditional or unconditional branch instructions that branch over a single
instruction into a conditional nullification in the following instruction.
Looking for conditional branches over unconditional branches, where the sense of the
first branch could be inverted and the second branch deleted. These result from null
then clauses and from then clauses that only contain goto statements. For example,
the code:
if(a) {
&vellip;
statement 1
} else {
goto L1;
}
statement 2
L1: