1 05/28/80  new_fortran optimizer
  2 
  3 With the new_fortran (fortran, ft) command, the -optimize (-ot)
  4 control argument invokes a loop optimizer and a machine dependant
  5 global optimizer (register optimizer).
  6 
  7 
  8 Loop optimizer:
  9 A loop optimizer is an optimizer that is cognizant of the flow of
 10 control in a program and uses that information to improve the code
 11 generated by the compiler.
 12 
 13 
 14 Examples of loop optimization:
 15 Calculations can be moved out of do-loops if the calculation is not
 16 dependent on the do-loop index.  Identical sub-expressions can be
 17 combined, and therefore only be calculated once, if the value of the
 18 sub-expression does not change in between its uses.  Whole assignment
 19 statements can be removed if the variable is assigned a new value
 20 before it is used.  Assignment statements can also be removed if they
 21 set automatic variables and are immediately followed by a return
 22 statement.
 23 
 24 
 25 This optimizer is considerably more powerful than the previous
 26 new_fortran optimizer (New Fortran Release 3 or earlier) and provides
 27 several new types of optimization, including strength reduction, test
 28 replacement, dead assignment removal, expansion of statement functions
 29 in-line, partial evaluation of logical expressions in logical if
 30 statements, removal of unused assignments, removal of invariant code
 31 from do-loops, and combining of identical sub-expressions.
 32 
 33 
 34 Strength reduction:
 35 A variable that is a simple arithmetic function of the do-loop index
 36 can be calculated as repeated additions instead of a multiplication.
 37 
 38 
 39 Test replacement:
 40 If a do-loop index is not used at all, either within the do-loop or
 41 within the extended range of that do-loop, and there is a variable
 42 within the loop that is a simple arithmetic function of the do-loop
 43 index, then the do-loop end condition test is changed to use that
 44 variable, rather than the do-loop index.
 45 
 46 
 47 Dead assignment removal:
 48 Assignments to do-loop index are not performed if the do-loop index is
 49 not used at all, either within the do-loop or within the extended
 50 range of that do-loop.
 51 
 52 
 53 Removal of invariants:
 54 Expressions that are invariant within a do-loop are moved to the next
 55 higher loop.
 56 
 57 
 58 Partial evaluation of expressions:
 59 Expressions in logical if statements are only evaluated until the
 60 truth value of the expression is completely known.
 61 
 62 
 63 Array subscripting has been vastly improved.
 64 
 65 
 66 Statement function references:
 67 References to statement functions are expanded in-line and are
 68 therefore subject to combined sub-expression optimization.
 69 
 70 
 71 Combining identical sub-expressions:
 72 Whenever the flow of the program allows, identical sub-expressions are
 73 pooled, that is, the expression is calculated once and stored in a
 74 temporary where it can be referenced as needed.
 75 
 76 
 77 Assignment removal:
 78 Useless assignment statements are removed from the code entirely!!!
 79 The two major causes of useless assignments are assignments to a
 80 variable that are immediately followed by another assignment to the
 81 same variable and assignment statements referencing automatic
 82 variables immediately preceding a return statement.  The optimizer
 83 warns the user whenever a block of code is removed.
 84 
 85 
 86 Machine dependant optimizations:
 87 In addition to the machine independant optimizations performed by the
 88 loop optimizer, the -optimize (-ot) control argument also invokes a
 89 machine dependant global optimizer (register optimizer) to perform
 90 such optimizations as global register allocation and pulling register
 91 loads out of loops.
 92 
 93 
 94 Pointers to common blocks:
 95 Pointers to frequently used common blocks are loaded into pointer
 96 registers before the loops in which they are frequently used and are
 97 kept loaded throughout these loops.
 98 
 99 
100 Invariant index values:
101 Loop invariant values used in indexing (subscripting) are loaded into
102 index registers before the loops in which they are invariant and are
103 kept loaded throughout these loops.
104 
105 
106 Induction variables:
107 Induction variables that are only used for addressing within a loop
108 are loaded into index registers before the loop and are incremented in
109 the index registers directly.  An induction variable that is globally
110 assigned to an index register in this way is not stored within the
111 loop unless the loop contains contexts which might erase the register,
112 such as a subroutine call, or unless the induction variable's value is
113 needed after loop termination or exit.