During optimization, the compiler changes the unoptimized code sequences, derived from the source code, into equivalent optimized code sequences. The resulting code runs faster and usually takes less space. However, during optimization, compilation usually takes more time and space.
Because optimization transforms the code, the direct correspondence between source and object code is often lost. Therefore, debugging information is not provided for programs compiled using the optimization option. Optimized code is also more sensitive to subtle coding errors. For these reasons, do not use the optimization options while you are developing your programs. Use the -O optimization options only to compile the final versions of your programs.
Optimization Levels in C or C++
The default is not to optimize your program. To optimize
your program, specify one of the optimizing compiler options:
When you specify optimization, the compiler performs a complete control and data-flow analysis for each function. The compiler also uses global register allocation for the whole function, thereby allowing many variables to be kept in registers rather than in memory. The compiler performs optimizations such as described in Optimization Techniques Used by IBM C and C++ Compilers.
Optimization Techniques Used by IBM C and
C++ Compilers
Special Handling of Math and String
Library Functions
Writing Optimized Code
Inlined Components
Minimizing the Size of Object
Files
-O, optimize Compiler Option