O

Specifies the code optimization for applications.

IDE Equivalent

Windows: Optimization > Optimization

Linux: General > Optimization Level

Mac OS X: General > Optimization Level

Architectures

IA-32, Intel® 64, IA-64 architectures

Syntax

Linux and Mac OS X:

-O[n]

Windows:

/O[n]

Arguments

n

Is the optimization level. Possible values are 1, 2, or 3. On Linux and Mac OS X 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 and Mac OS X)

This is the same as specifying O2.

O0 (Linux and Mac OS X)

Disables all optimizations. On systems using IA-32 architecture and Intel® 64 architecture, this option sets option -fno-omit-frame-pointer and option -fmath-errno.

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.

  • Disables intrinsic recognition and intrinsics inlining.

  • On systems using IA-64 architecture, it disables software pipelining, loop unrolling, and global code scheduling.

On systems using IA-64 architecture, 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 Linux and Mac OS X systems using IA-32 architecture and Intel® 64 architecture:
    -funroll-loops0, -fno-builtin, -mno-ieee-fp, -fomit-frame-pointer, -ffunction-sections, -ftz

  • On Linux systems using IA-64 architecture:
    -funroll-loops0, -fbuiltin, -mno-ieee-fp, -fomit-frame-pointer, -ffunction-sections, -ftz

  • On Windows systems using IA-32 architecture:
    /Qunroll0, /Oi-, /Op-, /Oy, /Gy, /Os, /GF (/Qvc7 and above), /Gf (/Qvc6 and below), /Ob2, /Og, /Qftz

  • On Windows systems using Intel® 64 architecture and IA-64 architecture:
    /Qunroll0, /Oi-, /Op-, /Gy, /Os, /GF (/Qvc7 and above), /Gf (/Qvc6 and below), /Ob2, /Og, /Qftz

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.
Vectorization is enabled at O2 and higher levels.
On systems using IA-64 architecture, 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 optimization, which includes:

    • 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

The O2 option sets the following options:

  • On Windows systems using IA-32 architecture:
    /Og, /Oi-, /Os, /Oy, /Ob2, /GF (/Qvc7 and above), /Gf (/Qvc6 and below), /Gs, /Gy, and /Qftz

  • On Windows systems using Intel® 64 architecture:
    /Og, /Oi-, /Os, /Ob2, /GF (/Qvc7 and above), /Gf (/Qvc6 and below), /Gs, /Gy, and /Qftz

This option sets other options that optimize for code speed. The options set are determined by the compiler depending on which architecture and operating system you are using.

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.

On Windows systems, the O3 option sets the /GF (/Qvc7 and above), /Gf (/Qvc6 and below), and /Ob2 option.

On Linux and Mac OS X systems, the O3 option sets option -fomit-frame-pointer.

On systems using IA-32 architecture or Intel® 64 architecture, when O3 is used with options -ax or -x (Linux) or with options /Qax or /Qx (Windows), the compiler performs more aggressive data dependency analysis than for O2, which may result in longer compilation times.
On systems using IA-64 architecture, the O3 option enables optimizations for technical computing applications (loop-intensive code): loop optimizations and data prefetch.

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 iconNote

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

Alternate Options

O1

Linux and Mac OS X: None
Windows: /Od

See Also

See Also