Table 27 Optimization levels (continued)

 

Optimizations

 

 

 

Option

performed

Advantages

Disadvantages

Recommended use

 

 

 

 

 

 

branch optimization,

compiles faster than

 

 

 

dead code

level 2; compatible with

 

 

 

elimination, more

the debugger option

 

 

 

efficient use of

-g.

 

 

 

registers, instruction

 

 

 

 

scheduling, and

 

 

 

 

peephole

 

 

 

 

optimization.

 

 

 

 

 

 

 

 

+O2, -O

Default level

Can significantly

Compiles slower

During program development

 

optimizations,

increase performance

than level 0 and

and when building the

 

including level 1,

over level 1; works with

1.

production version; especially

 

plus coloring register

debugger option-g.

 

effective in optimizing loops that

 

allocation, induction

 

 

perform arithmetic operations

 

variable elimination

 

 

on large float and double

 

and strength

 

 

arrays.

 

reduction, common

 

 

 

 

subexpression

 

 

 

 

elimination, loop

 

 

 

 

invariant code

 

 

 

 

motion, store/copy

 

 

 

 

optimization, unused

 

 

 

 

definition elimination,

 

 

 

 

software pipelining,

 

 

 

 

and register

 

 

 

 

reassociation.

 

 

 

 

 

 

 

 

+O3

Level 2

Can significantly

Compiles slower

When building the production

 

optimizations, plus

increase performance

than lower levels;

version; especially effective

 

loop transforms,

over level 2.

increases object

when used on source files

 

parallelization,

 

code size; not

containing frequently executed

 

vectorization,

 

compatible with

loops and subprograms.

 

cloning, and inlining

 

the debugger

 

 

within a file. Some

 

option -g.

 

 

optimizations may

 

 

 

 

require additional

 

 

 

 

options; see “Using

 

 

 

 

the optimization

 

 

 

 

options” (page 91).

 

 

 

 

 

 

 

 

+O4

Level 3 optimizations

Provides the highest

Can use large

When building the production

 

applied across all

level of optimization;

amounts of

version; especially effective

 

program files

can significantly

system resources;

when used on source files

 

compiled with +O4.

increase performance

may increase

containing frequently executed

 

 

over level 3.

link-time and

loops and subprograms.

 

 

 

object code size;

 

 

 

 

not compatible

 

 

 

 

with the

 

 

 

 

debugger option

 

 

 

 

-g.

 

Using the optimization options

The +Ooptimizationoptions enable you to control the kind of optimizations that are applied to your program at each level. Table on page151 and Table6-3 on page152 list the options. The first column of each table lists each option, the second column gives the optimization level at which the option can be used, and the third column identifies what the option does. When using any of these options except +Oall, you must also use the +Onoption to specify the optimization level listed in the second column of the tables. The +Oalloption automatically invokes the optimizer at the highest level.

Using options to control optimization

91