HP aC++/HP C A.06.25 Programmer's Guide

Specifically, level 2 provides the following:
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
default.)
Loop invariant code motion.
Store/copy optimization.
Unused definition elimination.
Software pipelining.
Register reassociation.
Level 2 can produce faster runtime code than level 1 if programs use loops extensively.
Loop-oriented floating-point intensive applications may see run times reduced by 50%.
Operating system and interactive applications that use the already optimized system
libraries can achieve 30% to 50% additional improvement. Level 2 optimization produces
faster programs than level 1 and compiles faster than level 3 optimization.
Level 3 Optimization
Level 3 optimization includes level 2 optimizations, along with full optimization across
all subprograms within a single file. Level 3 also inlines certain subprograms within
the input file. Use +O3 to get level 3 optimization.
Level 3 optimization produces faster runtime code than level 2 on code that does many
procedure calls to small functions. Level 3 links faster than level 4. But level 3 does not
work with the debugger options -g0 and -g1.
Level 4 Optimization
Level 4 optimization includes level 3 optimizations, along with full optimizations across
the entire application program. Level 4 includes global and static variable optimization
and inlining across the entire program. Optimizations are performed at link time rather
than at compile time. Use +O4 to get level 4 optimization.
Level 4 optimization produces faster runtime code than level 3 if programs use many
global variables or if there are many opportunities for inlining procedure calls. But
level 4 does not work with the debugger options -g0 and -g1.
Additional Options for Finer Control
In addition to basic optimization levels, optimization options are provided should you
require a more precise level of control.
Some introductory examples follow:
206 Optimizing HP aC++ Programs