OPTIMIZE

Use OPTIMIZE to reduce the run time of your object program. Optimization might also reduce the amount of storage your object program uses.

Read syntax diagramSkip visual syntax diagram
OPTIMIZE option syntax

              .-0-.     
>>-OPTIMIZE-(-+-1-+-)------------------------------------------><
              '-2-'     

Default is: OPTIMIZE(0)

Abbreviations are: OPT(0), OPT(1), or OPT(2)

Optimizations are performed under the assumption that the program and data are valid, given the compiler options. For example, external decimal data that has USAGE DISPLAY must be valid unless ZONEDATA(MIG|NOPFD) is used to allow invalid zone bits. Digits and sign codes must be valid no matter what options are used. If the program or data is invalid, programs might behave differently at different levels of optimization or between different versions of Enterprise COBOL.
  • OPTIMIZE(0) specifies limited optimizations, which result in the shortest compilation time. When the TEST option is specified, full debug capabilities are available.
  • OPTIMIZE(1) specifies optimizations that improve application runtime performance. Optimizations at this level include basic inlining, strength reduction, simplification of complex operations into equivalent simpler operations, removal of some unreachable code and block rearrangement. Also, OPTIMIZE(1) includes some intrablock optimizations such as common subexpression elimination and value propagation. When the TEST option is specified, most debug capabilities are available.
  • OPTIMIZE(2) specifies further optimizations, which include more aggressive simplifications and instruction scheduling. Also, some interblock optimizations such as global value propagation and loop invariant code motion are included. When the TEST option is specified, some debug capabilities are available.

When OPTIMIZE(1) or OPTIMIZE(2) is used without the TEST compiler option, care must be taken with user-written condition handlers registered via the Language Environment service CEEHDLR. In particular, if a condition handler accesses data items that are not defined local to the condition handler program themselves (for example, data items defined in the application as EXTERNAL), such data items must be defined with the VOLATILE clause to ensure that the handler uses the latest value of the data item, or the condition handler program can be compiled with the TEST compiler option. The use of the VOLATILE clause is preferred over the use of the TEST option because the use of the TEST option can reduce optimization for the entire program, while VOLATILE localizes the reduced optimization.

For more information about the VOLATILE clause, see VOLATILE clause.

Note: Since Enterprise COBOL V5, the NOOPTIMIZE, OPTIMIZE, OPTIMIZE(STD), and OPTIMIZE(FULL) options are removed but are tolerated for compatibility. If one of those options is specified, it is mapped to the new option or options as follows:
Table 1. Mapping of removed options to new options
Removed options New options
NOOPTIMIZE OPTIMIZE(0)
OPTIMIZE OPTIMIZE(1)
OPTIMIZE(STD) OPTIMIZE(1)
OPTIMIZE(FULL) OPTIMIZE(1) and STGOPT

related concepts  
Optimization

related references  
Conflicting compiler options  
MAXPCF
TEST  
STGOPT   
VOLATILE clause (Enterprise COBOL for z/OS Language Reference)