O

Specifies the code optimization for applications.

IDE Equivalent

Windows:
General > Optimization
Optimization > Optimization
Linux: None

Architectures

IA-32, IntelŪ EM64T, IntelŪ ItaniumŪ architecture

Syntax

Linux: -O[n]
Windows:  /O[n]

Arguments

n Is the optimization level. Possible values are 1, 2, or 3. On Linux systems, you can also specify 0.

Default

O2 Optimizes for code speed. This default may change depending on which other compiler options are specified. For details, see below.

Description

This option specifies the code optimization for applications.

Option

Description

O (Linux only) This is the same as specifying O2.

O0 (Linux only)

Disables all optimizations. On IA-32 and IntelŪ EM64T systems, this option sets option -fp and option -fmath-errno. This option causes certain warn options to be ignored. This is the default if you specify option -debug (with no keyword).

O1

Enables optimizations for speed and disables some optimizations that increase code size and affect speed.
To limit code size, this option:

  • Enables global optimization; this includes data-flow analysis, code motion, strength reduction and test replacement, split-lifetime analysis, and instruction scheduling.
  • On ItaniumŪ-based systems, it disables software pipelining, loop unrolling, and global code scheduling.
  • On IA-32 systems, it disables intrinsic recognition and intrinsics inlining.
On IntelŪ ItaniumŪ processors, this option also enables optimizations for server applications (straight-line and branch-like code with a flat profile).
The O1 option sets the following options:
  • On IA-32 Linux systems:
    -unroll0
    , -nofltconsistency (same as -mno-ieee-fp), -fp (same as -fomit-frame-pointer)
  • On ItaniumŪ-based Linux systems:
    -unroll0
    , -nofltconsistency (same as -mno-ieee-fp), -fp (same as -fomit-frame-pointer)
  • On Windows systems:
    /unroll0
    (or /Qunroll0), /Oi, /nofltconsistency (same as /Op-), /Oy, /Os, /Ob1
The O1 option may improve performance for applications with very large code size, many branches, and execution time not dominated by code within loops.

O2

Enables optimizations for speed. This is the generally recommended optimization level.
On Itanium-based systems, this option enables optimizations for speed, including global code scheduling, software pipelining, predication, and speculation.

This option also enables:

  • Inlining of intrinsics
  • Intra-file interprocedural optimizations, which include:

    • inlining

    • constant propagation

    • forward substitution

    • routine attribute propagation

    • variable address-taken analysis

    • dead static function elimination

    • removal of unreferenced variables

  • The following capabilities for performance gain:
    • constant propagation
    • copy propagation
    • dead-code elimination
    • global register allocation
    • global instruction scheduling and control speculation
    • loop unrolling
    • optimized code selection
    • partial redundancy elimination
    • strength reduction/induction variable simplification
    • variable renaming
    • exception handling optimizations
    • tail recursions
    • peephole optimizations
    • structure assignment lowering and optimizations
    • dead store elimination

On Linux systems, this option is the same as the O option.
On Windows systems, this option is the same as the Ox option.
On Windows IA-32 systems, the
O2 option sets options /Og, /Ot, /Oy, /Ob1, and /Gs.
On Linux systems, if
-g is specified, O2 is turned off and O0 is the default unless O2 (or O1 or O3) is explicitly specified in the command line together with -g.

O3 Enables O2 optimizations plus more aggressive optimizations, such as prefetching, scalar replacement, and loop and memory access transformations. Enables optimizations for maximum speed, such as:
  • Loop unrolling, including instruction scheduling
  • Code replication to eliminate branches
  • Padding the size of certain power-of-two arrays to allow more efficient cache use.
The O3 option also does the following:
  • On IA-32 processors, when the O3 option is used with options -ax or -x (Linux) or with options /Qax or /Qx (Windows), it causes the compiler to perform more aggressive data dependency analysis than for O2, which may result in longer compilation times.
  • On Intel Itanium processors, the O3 option enables optimizations for technical computing applications (loop-intensive code): loop optimizations and data prefetch.
On Linux systems, the O3 option sets the -fp option.
The O3 optimizations may not cause higher performance unless loop and memory access transformations take place. The optimizations may slow down code in some cases compared to O2 optimizations.
The O3 option is recommended for applications that have loops that heavily use floating-point calculations and process large data sets.

The last O option specified on the command line takes precedence over any others.

Note

The options set by the O option may change from release to release.

Alternate Options

O0

Linux: None
Windows: /Od, /optimize:0, /nooptimize

O1

Linux: None
Windows: /optimize:1, /optimize:2

O2  Linux: None
Windows: /Ox, /optimize:3, /optimize:4

O3

Linux: None
Windows: /optimize:5

See Also

Optimizing Applications:
Compiler Optimizations Overview

Optimization Options Summary

Efficient Compilation