The following optimizations occur at any optimization level (/optimize:0 through /optimize:5):
Space optimizations decrease the size of the object or executing program by eliminating unnecessary use of memory, thereby improving speed of execution and system throughput. Visual Fortran space optimizations are as follows:
Only one copy of a given constant value is ever allocated memory space. If that constant value is used in several places in the program, all references point to that value.
If operations will never execute or if data items will never be used, Visual Fortran eliminates them. Dead code includes unreachable code and code that becomes unused as a result of other optimizations, such as value propagation.
Regardless of the optimization level, Visual Fortran inserts arithmetic statement functions directly into a program instead of calling them as functions. This permits other optimizations of the inlined code and eliminates several operations, such as calls and returns or stores and fetches of the actual arguments. For example:
SUM(A,B) = A+B
.
.
.
Y = 3.14
X = SUM(Y,3.0) ! With value propagation, becomes: X = 6.14
Many intrinsic procedures are automatically inlined.
Inlining of other subprograms, such as contained subprograms, occurs at optimization level /optimize:4 or /optimize:5 (or when you specify appropriate /inline keywords at /optimize:1 or higher).
DO loop collapsing reduces a major overhead in I/O processing. Normally, each element in an I/O list generates a separate call to the Visual Fortran RTL. The processing overhead of these calls can be most significant in implied-DO loops.
If Visual Fortran can determine that the format will not change during program execution, it replaces the series of calls in up to seven nested implied-DO loops with a single call to an optimized RTL routine (see Enable Implied-Do Loop Collapsing). The optimized RTL routine can transfer many elements in one operation.
Visual Fortran collapses implied-DO loops in formatted and unformatted I/O operations, but it is more important with unformatted I/O, where the cost of transmitting the elements is a higher fraction of the total cost.
Certain array store operations are optimized. For example, to minimize the creation of array temporaries, Visual Fortran can detect when no overlap occurs between the two sides of an array assignment. This type of optimization occurs for some assignment statements in FORALL constructs.
Certain array operations are also candidates for loop unrolling optimizations (see Loop Unrolling).