Sun WorkShop Compiler C 5.0 User's Guide

-xO[1|2|3|4|5]

Optimizes the object code. Specifying -xO is equivalent to specifying -xO2.

When -xO is used with the -g option, a limited amount of debugging is available.

The levels (1, 2, 3, 4, or 5) you can use with -xO differ according to the platform you are using.

(SPARC)

-xO1

Does basic local optimization (peephole).

-xO2

Does basic local and global optimization. This is induction variable elimination, local and global common subexpression elimination, algebraic simplification, copy propagation, constant propagation, loop-invariant optimization, register allocation, basic block merging, tail recursion elimination, dead code elimination, tail call elimination, and complex expression expansion.

The -xO2 level does not assign global, external, or indirect references or definitions to registers. It treats these references and definitions as if they were declared volatile. In general, the -xO2 level results in minimum code size.

-xO3

Performs like -xO2, but also optimizes references or definitions for external variables. Loop unrolling and software pipelining are also performed. This level does not trace the effects of pointer assignments. When compiling either device drivers, or programs that modify external variables from within signal handlers, you may need to use the volatile type qualifier to protect the object from optimization. In general, the -xO3 level results in increased code size.

-xO4

Performs like -xO3, but also automatically inlines functions contained in the same file; this usually improves execution speed. This level traces the effects of pointer assignments, and usually results in increased code size.

-xO5

Generates the highest level of optimization. Uses optimization algorithms that take more compilation time or that do not have as high a certainty of improving execution time. Optimization at this level is more likely to improve performance if it is done with profile feedback. See "-xprofile=p".

(Intel)

-xO1

Preloads arguments from memory, cross-jumping (tail-merging), as well as the single pass of the default optimization.

-xO2

Schedules both high- and low-level instructions and performs improved spill analysis, loop memory-reference elimination, register lifetime analysis, enhanced register allocation, and elimination of global common subexpressions.

-xO3

Performs loop strength reduction, induction variable elimination, as well as the optimization done by level 2.

-xO4

Performs loop unrolling, avoids creating stack frames when possible, and automatically inlines functions contained in the same file, as well as the optimization done by levels 2 and 3. Note that this optimization level can cause stack traces from adb and dbx to be incorrect.

-xO5

Generates the highest level of optimization. Uses optimization algorithms that take more compilation time or that do not have as high a certainty of improving execution time. Some of these include generating local calling convention entry points for exported functions, further optimizing spill code and adding analysis to improve instruction scheduling.

If the optimizer runs out of memory, it tries to recover by retrying the current procedure at a lower level of optimization and resumes subsequent procedures at the original level specified in the command-line option.

If you optimize at -xO3 or -xO4 with very large procedures (thousands of lines of code in the same procedure), the optimizer may require a large amount of virtual memory. In such cases, machine performance may degrade.