| Syntax: | Default: |
| opt(level, level) | opt(level, 0) |
Whether the code generated during a build is optimized, and what level of optimization is applied is set by the build option opt(level, level). The default level is 0, or no optimization.
You can specify level 0, 2, 3, or 4. These levels are described below. The optimizations may change from one product release to the next. If you need a specific level of optimization, specify the appropriate numeric value.
Level 0
This is the default level. It performs only quick local
optimizations, such as constant folding and elimination of local
common subexpressions.
Level 2
Performs optimizations that the compiler developers
consider to be the best combination for compilation speed and
runtime performance.
Setting an opt level 2 or greater enables or implies the following options:
Level 3
Performs additional optimizations that are memory
intensive, compile-time intensive, or both. These optimizations
are performed in addition to those performed with opt(level, 2).
They are recommended when the desire for runtime improvement
outweighs the concern for minimizing compilation resources.
This level is the compiler's highest and most aggressive level of optimization. By default opt(level, 3) performs optimizations that have the potential to slightly alter the semantics of your program. It also changes the default maxmem to -1, meaning optimizations may use unbounded memory and may also use more time.
You can use the strict optimizing option with opt(level, 3) to turn off the aggressive optimizations that might change the semantics of a program. The strict option, combined with opt(level, 3), invokes all the optimizations performed at opt(level, 2), as well as further loop optimizations. Note that the strict option must appear after the opt(level, 3) option, otherwise it is ignored.
The aggressive optimizations performed when you specify opt(level, 3) are:
Loads and floating-point computations fall into this category. This optimization is aggressive because it may place such instructions onto execution paths where they will be executed when they may not have been according to the actual semantics of the program.
For example, a loop-invariant floating-point computation that is found on some, but not all, paths through a loop will not be moved at opt(level, 2) because the computation may cause an exception. At opt(level, 3), the compiler will move it because it is not certain to cause an exception. The same is true for motion of loads. Although a load through a pointer is never moved, loads off the static or stack base register are considered movable at opt(level, 3). Loads in general are not considered to be absolutely safe at opt(level, 2) because a program can contain a declaration of a static array a of 10 elements and load a[60000000003], which could cause a segmentation violation.
The same concepts apply to scheduling.
Example: In the following example, at opt(level, 2), the computation of b+c is not moved out of the loop for two reasons:
At opt(level, 3), the code is moved.
...
int i ;
float a[100], b, c ;
for (i = 0 ; i < 100 ; i++)
{
if (a[i] < a[i+1])
a[i] = b + c ;
}
...
With opt(strict,yes) (implied by opt(level,2)), certain optimizations are not performed because they may produce an incorrect sign in cases with a zero result, and because they remove an arithmetic operation that may cause some type of floating-point exception.
For example, (X + 0.0) is not folded to X because, under IEEE rules, (-0.0 + 0.0) = 0.0, which is -X. In some other cases, some optimizations may perform optimizations that yield a zero result with the wrong sign. For example, if X is 0.0, replacing (X-Y*Z) with (-Y*Z) may result in a -0.0 where the original computation would result in 0.0.
In most cases the difference in the results is not important to an application and opt(level, 3) allows these optimizations.
Computations such as ( a*b*c ) may be rewritten as ( a*c*b ) if, for example, an opportunity exists to get a common subexpression by such rearrangement. Replacing a divide with a multiply by the reciprocal is another example of reassociating floating-point computations.
Setting an opt level 3 or greater enables or implies the following options:
The following notes also apply when setting opt(level, 3):
Level 4
This option is the same as opt(level, 3), except that it also
sets the arch and tune optimizing options to the
architecture of the compiling machine.
Subsequent settings of level, arch, and tune options override the settings implied by the opt(level, 4) option.
