-O

Category

Optimization and tuning

Purpose

Specifies whether to optimize code during compilation and, if so, at which level.

-qOPTimize is the long form of -O.

Syntax

Read syntax diagramSkip visual syntax diagram
Option:

        .-0-.   
>>- -O--+---+--------------------------------------------------><
        +-1-+   
        +-2-+   
        +-3-+   
        +-4-+   
        '-5-'   

@PROCESS:

@PROCESS OPTimize[(level)] | NOOPTimize

Defaults

nooptimize or -O0 or optimize=0

Parameters

not specified
Almost all optimizations are disabled. This is equivalent to specifying -O0 or -qnoopt.
-O
For each release of XL Fortran, -O enables the level of optimization that represents the best tradeoff between compilation speed and runtime performance. If you need a specific level of optimization, specify the appropriate numeric value. Currently, -O is equivalent to -O2.
-O0
Almost all optimizations are disabled. This option is equivalent to –qnoopt.
-O1
Reserved for future use. This form is ignored and has no effect on the outcome of the compilation. In past releases, it was interpreted as a combination of the -O and -1 options, which may have had unintended results.
-O2
Performs a set of optimizations that are intended to offer improved performance without an unreasonable increase in time or storage that is required for compilation.
-O3
Performs additional optimizations that are memory intensive, compile-time intensive, and may change the semantics of the program slightly, unless -qstrict is specified. We recommend these optimizations when the desire for runtime speed improvements outweighs the concern for limiting compile-time resources.

This level of optimization also affects the setting of the -qfloat option, turning on the fltint and rsqrt suboptions by default, and sets -qmaxmem=-1.

Specifying -O3 implies -qhot=level=0, unless you explicitly specify -qhot or -qhot=level=1.

-O4
Aggressively optimizes the source program, trading off additional compile time for potential improvements in the generated code. You can specify the option at compile time or at link time. If you specify it at link time, it will have no effect unless you also specify it at compile time for at least the file that contains the main program.
-O4 implies the following other options:
  • -qhot
  • -qipa
  • -O3 (and all the options and settings that it implies)
  • -qarch=auto
  • -qtune=auto
  • -qcache=auto

Note that the auto setting of -qarch, -qtune, and -qcache implies that the execution environment will be the same as the compilation environment.

This option follows the "last option wins" conflict resolution rule, so any of the options that are modified by -O4 can be subsequently changed. For example, specifying -O4 -qarch=ppc allows aggressive intraprocedural optimization while maintaining code portability.

-O5
Provides all of the functionality of the -O4 option, but also provides the functionality of the -qipa=level=2 option.
Note:

To obtain the same floating-point accuracy for optimized and non-optimized applications, you must specify the -qfloat=nomaf compiler option. In cases where differences in floating-point accuracy still occur after specifying -qfloat=nomaf, the -qstrict compiler option allows you to exert greater control over changes that optimization can cause in floating-point semantics.

Usage

Generally, use the same optimization level for both the compile and link steps. This is important when using either the -O4 or -O5 optimization level to get the best runtime performance. For the -O5 level, all loop transformations (as specified via the -qhot option) are done at the link step.

Increasing the level of optimization may or may not result in additional performance improvements, depending on whether the additional analysis detects any further optimization opportunities.

An optimization level of -O3 or higher can change the behavior of the program and potentially cause exceptions that would not otherwise occur. Use of the -qstrict option maintains the same program behavior as with -O2, at the cost of optimization opportunity. Refer to the -qstrict option for the list of optimizations it disables.

When you use -O or higher optimization, -qtbtable=small is in effect. The traceback table generated has no function name or parameter information.

If the -O option is used in an @PROCESS statement, only an optimization level of 0, 2, or 3 is allowed. Note that unlike using -O3 in command line invocation, specifying @PROCESS OPT(3) does not imply -qhot=level=0.

Compilations with optimization may require more time and machine resources than other compilations.

The more the compiler optimizes a program, the more difficult it is to debug the program with a symbolic debugger.

Related information