Optimization requires additional compilation time, but usually results in a faster run time. XL Fortran allows you to select whether you want optimization to be performed at compile time. By default, the compiler performs very limited optimization (-O0 or -qnoopt).
To enable compiler optimization, specify the -O compiler
option with an optional digit that signifies the level. The following
table summarizes compiler behavior at each optimization level.
Optimization levels | |
Option | Behavior |
---|---|
-qnoopt/-O0 | Fast compilation, debuggable code, conserved program semantics. |
-O2 (same as -O) | Comprehensive low-level optimization; partial debugging support. |
-O3 | More extensive optimization; some precision trade-offs. |
-O4 and -O5 | Interprocedural optimization; loop optimization; automatic machine tuning. |
At optimization level -O2 (same as -O), the compiler performs comprehensive low-level optimization, which includes the following techniques:.
Minimal debugging information at optimization level -O2 consists of the following behaviors:
At optimization level -O3, the compiler performs more extensive optimization than at -O2. The optimizations may be broadened or deepened in the following ways:
Due to the implicit setting of -qnostrict, some precision trade-offs are made by the compiler, such as the following:
-O3 optimizations may:
Use the -O3 option where run-time performance is a crucial factor and machine resources can accommodate the extra compile-time work.
The exact optimizations that are performed depend on a number of factors:
Here is a recommended approach to using optimization levels -O2 and -O3
Ensure that subroutine parameters comply with aliasing rules.
Optimization levels -O4 and -O5 automatically activate several other optimization options. Optimization level -O4 includes:
Optimization level -O5 includes:
If -O5 is specified on the compile step, then it should be specified on the link step, as well. Although the -qipa option is not strictly another optimization level, it extends the optimizations across procedures (even if the procedures are in different files). It enhances the effectiveness of the optimizations that are done by other optimization options, particularly -O (at any level). Because it can also increase compile time substantially, you may want to use it primarily for tuning applications that are already debugged and ready to be used. If your application contains a mixture of Fortran and C or C++ code compiled with IBM XL C/C+ compilers, you can achieve additional optimization by compiling and linking all your code with the -O5 option.