Optimizing at level 2

Benefits at level 2

  • Eliminates redundant code
  • Performs basic loop optimization
  • Structures code to take advantage of -qarch and -qtune settings

After you successfully compile, execute, and debug your application using -O0, recompiling at -O2 opens your application to a set of comprehensive low-level transformations that apply to subprogram or compilation unit scopes and can include some inlining. Optimizations at -O2 attain a relative balance between increasing performance while limiting the impact on compilation time and system resources. You can increase the memory available to some of the optimizations in the -O2 portfolio by providing a larger value for the -qmaxmem option. Specifying -qmaxmem=-1 allows the optimizer to use memory as needed without checking for limits but does not change the transformations the optimizer applies to your application at -O2.

Starting to tune at level 2

Choosing the right hardware architecture target or family of targets becomes even more important at -O2 and higher. By targeting the proper hardware, the optimizer can make the best use of the available hardware facilities. If you choose a family of hardware targets, the -qtune option can direct the compiler to emit code that is consistent with the architecture choice and that can execute optimally on the chosen tuning hardware target. With this option, you can compile for a general set of targets and have the code run best on a particular target.

For details on the -qarch and -qtune options, see Tuning XL compiler applications.

The -O2 option can perform a number of additional optimizations as follows:
  • Common subexpression elimination: Eliminates redundant instructions
  • Constant propagation: Evaluates constant expressions at compile time
  • Dead code elimination: Eliminates instructions that a particular control flow does not reach or that generate an unused result
  • Dead store elimination: Eliminates unnecessary variable assignments
  • Global register allocation: Globally assigns user variables to registers
  • Value numbering: Simplifies algebraic expressions by eliminating redundant computations
  • Instruction scheduling for the target machine
  • Loop unrolling and software pipelining
  • Moving loop-invariant code out of loops
  • Simplifying control flow
  • Strength reduction and effective use of addressing modes
  • Widening: Merges adjacent load/stores and other operations
  • Pointer aliasing improvements to enhance other optimizations

Even with -O2 optimizations, some useful information about your source code is made available to the debugger if you specify -g. Using a higher -g level increases the information provided to the debugger but reduces the optimization that can be done. Conversely, higher optimization levels can transform code to an extent to which debugging information is no longer accurate.

The section on Debugging optimized code discusses other debugging strategies in detail.

See -O for information on the -O level syntax.



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us