HP-UX Floating-Point Guide

172 Chapter 7
Performance Tuning
Inefficient Code
The most important compiler option affecting efficiency is the
optimization option, +O, which allows you to optimize your program in
several different ways:
Levels of
optimization Optimization levels, numbered from 0 to 4, allow you to
select a broad category of optimizations, from minimal
optimization to full optimization.
Types of
optimization Optimization types allow you to select groups of
optimizations that fall into a particular category. For
example, +Osize suppresses optimizations that
significantly increase code size. If you specify an
optimization type, you must also specify an
optimization level.
Specific
optimizations Specific optimizations allow you to turn on or off
particular optimizations that may be appropriate or
inappropriate for your program. For example,
+Opipeline (the default at optimization levels 2, 3,
and 4) enables software pipelining. If you specify a
specific optimization, you must also specify an
optimization level.
In general, the higher the optimization level, the more efficient the code.
In performing optimizations, the compiler often rearranges code and
makes assumptions about the way variables will be used in other
modules. There is some risk, therefore, in choosing a high optimization
level, since the compiler may make some invalid assumptions that can
cause code to run more slowly. This is particularly true if your code
makes frequent use of pointers. It is always a good idea to compile a
program at different optimization levels and compare the results to
make sure that the optimizations are not affecting either the
performance or the results. See “Compiler Behavior and Compiler
Version” on page 78 and “Compiler Options” on page 79 for information
about how compiler optimizations can affect program results.
The following specific optimizations are particularly relevant to
floating-point programs. Most of them are available at optimization
levels 2, 3, and 4.