Each of the command-line options: -O,-O1, -O2 and -O3 turn on several compiler capabilities. -O and -O1 are practically the same and mentioned both for compatibility with other compilers. The following table summarizes the optimizations that the compiler applies when you invoke -O1 and-or -O2, and -O3 optimizations.
Option |
Optimization |
Affected Aspect of Program |
-O1, -O2 |
global register allocation |
register use |
-O1, -O2 |
instruction scheduling |
instruction reordering |
-O1, -O2 |
register variable detection |
register use |
-O1, -O2 |
common subexpression elimination |
constants and expression evaluation |
-O1, -O2 |
dead-code elimination |
instruction sequencing |
-O1, -O2 |
variable renaming |
register use |
-O1, -O2 |
copy propagation |
register use |
-O1, -O2 |
constant propagation |
constants and expression evaluation |
-O1, -O2 |
strength reduction-induction variable |
simplification instruction, |
-O1, -O2 |
tail recursion elimination |
calls, further optimization |
-O1, -O2 |
software pipelining |
calls, further optimization |
-O3 |
prefetching, scalar replacement, |
memory access, instruction parallelism, predication, software pipelining |
For IA-32 and Itanium architectures, the options can behave in a different way. To specify the optimizations for your program, use options depending on the target architecture as follows.
IA-32 and Itanium(TM) compilers |
|
-O2 |
ON by default. Enables options -Oi and -fp. Confines optimizations to the procedural level. -O2 turns ON intrinsics inlining. |
-O3 |
Enables -O2 option with more aggressive optimization, for example, prefetching, scalar replacement, and loop transformations. Optimizes for maximum speed, but may not improve performance for some programs. |
IA-32 compiler |
|
-O,-O1 or -O2 |
Enable options -Oi, and -fp. However, -O1 disables intrinsics inlining to reduce code size. In most cases, -O2 is recommended over -O1. |
Itanium compiler |
|
-O or -O1 |
Enable the same optimizations as -O2 except for loop unrolling. In most cases, -O2 is recommended over -O1. |