Specifies whether to optimize code during compilation, and if so, specifies the optimization level.
.-nooptimize-------------. >>-+- -q--+-optimize--+----------+-+-+------------------------->< | '-=--+-0-+-' | | +-2-+ | | +-3-+ | | +-4-+ | | '-5-' | +- -O0----------------------------+ +- -O-----------------------------+ +- -O2----------------------------+ +- -O3----------------------------+ +- -O4----------------------------+ '- -O5----------------------------'
where optimization settings are:
-O0
-qNOOPTimize -qOPTimize=0 | Performs only quick local optimizations such as constant folding and
elimination of local common subexpressions.
This setting implies -qstrict_induction unless -qnostrict_induction is explicitly specified. |
-O
-qOPTimize | Performs optimizations that the compiler developers considered the best
combination for compilation speed and runtime performance. The
optimizations may change from product release to release. If you need a
specific level of optimization, specify the appropriate numeric value.
This setting implies -qstrict and -qnostrict_induction, unless explicitly negated by -qstrict_induction or -qnostrict. |
-O2
-qOPTimize=2 | Same as -O. |
-O3
-qOPTimize=3 | Performs additional optimizations that are memory intensive, compile-time
intensive, or both. They are recommended when the desire for runtime
improvement outweighs the concern for minimizing compilation resources.
-O3 applies the -O2 level of optimization, but with unbounded time and memory limits. -O3 also performs higher and more aggressive optimizations that have the potential to slightly alter the semantics of your program. The compiler guards against these optimizations at -O2. Use the -qstrict option with -O3 to turn off the aggressive optimizations that might change the semantics of a program. Specifying -qstrict together with -O3 invokes all the optimizations performed at -O2 as well as further loop optimizations. The -qstrict compiler option must appear after the -O3 option, otherwise it is ignored. |
-O3
-qOPTimize=3 (continued) | The aggressive optimizations performed when you specify -O3
are:
|
-O3, -qOPTimize=3 (continued) |
Notes
|
-O4
-qOPTimize=4 | This option is the same as -O3, except that it also:
Note: Later settings of -O, -qcache, -qhot, -qipa, -qarch, and -qtune options will override the settings implied by the -O4 option. |
-O5
-qOPTimize=5 | This option is the same as -O4, except that it:
Note: Later settings of -O, -qcache, -qipa, -qarch, and -qtune options will override the settings implied by the -O5 option. |
You can abbreviate -qoptimize... to -qopt.... For example, -qnoopt is equivalent to -qnooptimize.
Increasing the level of optimization may or may not result in additional performance improvements, depending on whether additional analysis detects further opportunities for optimization.
Compilations with optimizations may require more time and machine resources than other compilations.
Optimization can cause statements to be moved or deleted, and generally should not be specified along with the -g flag for debugging programs. The debugging information produced may not be accurate.
To compile myprogram.C for maximum optimization, enter:
xlc++ myprogram.C -O3
Related references