To enable global optimizations, use /optimize:2 or a higher optimization level. Using /optimize:2 or higher also enables local optimizations (/optimize:1).
Global optimizations include:
Data-flow and split lifetime analysis (global data analysis) traces the values of variables and whole arrays as they are created and used in different parts of a program unit. During this analysis, Visual Fortran assumes that any pair of array references to a given array might access the same memory location, unless constant subscripts are used in both cases.
To eliminate unnecessary recomputations of invariant expressions in loops, Visual Fortran hoists them out of the loops so they execute only once.
Global data analysis includes which data items are selected for analysis. Some data items are analyzed as a group and some are analyzed individually. Visual Fortran limits or may disqualify data items that participate in the following constructs, generally because it cannot fully trace their values.
Data items in the following declarations can make global optimizations less effective:
VOLATILE declarations are needed to use certain run-time features of the operating system. Declare a variable as VOLATILE if the variable can be accessed using rules in addition to those provided by the Fortran 95/90 language. Examples include:
As requested by the VOLATILE statement, Visual Fortran disqualifies any volatile variables from global data analysis.
Visual Fortran cannot trace data flow in a called routine that is not part of the program unit being compiled, unless the same DF command compiled multiple program units (see Compile With Appropriate Options and Multiple Source Files). Arguments passed to a called routine that are used again in a calling program are assumed to be modified, unless the proper INTENT is specified in an interface block (the compiler must assume they are referenced by the called routine).
Visual Fortran limits optimizations on data items in common blocks. If common block data items are referenced inside called routines, their values might be altered. In the following example, variable I might be altered by FOO, so Visual Fortran cannot predict its value in subsequent references.
COMMON /X/ I
DO J=1,N
I = J
CALL FOO
A(I) = I
ENDDO
Visual Fortran limits optimizations on variables in Fortran 90 modules. Like common blocks, if the variables in Fortran 90 modules are referenced inside called routines, their values might be altered.
Visual Fortran limits optimizations on variables indirectly referenced by a %LOC function or on variables with the TARGET attribute, because the called routine may dereference a pointer to such a variable.
An equivalence group is formed explicitly with the EQUIVALENCE statement or implicitly by the COMMON statement. A program section is a particular common block or local data area for a particular routine. Visual Fortran combines equivalence groups within the same program section and in the same program unit.
The equivalence groups in separate program sections are analyzed separately, but the data items within each group are not, so some optimizations are limited to the data within each group.