Optimization levels

The degree to which the compiler will optimize the code it generates is controlled by the -O flag.

No optimization
In the absence of any version of the -O flag, the compiler generates straightforward code with no instruction reordering or other attempt at performance improvement.
-O or -O2
These equivalent flags cause the compiler to optimize on the basis of conservative assumptions about code reordering. Only explicit relaxations such as the #pragma directives are used. This level performs no software pipelining, loop unrolling, or simple predictive commoning. It also constrains the amount of memory the compiler can use.
-O3
This flag directs the compiler to be aggressive about the optimization techniques used and to use as much memory as necessary for maximum optimization. This level of optimization may result in functional changes to the program if the program is sensitive to floating-point exceptions, the sign of zero, or precision effects of reordering calculations. These side effects can be avoided, at some performance cost, by using the -qstrict option in combination with -O3. The -qhot option, in combination with -O3, enables predictive commoning and some unrolling. The result of these changes is that large or complex routines should have the same or better performance with the -O3 option (possibly in conjunction with -qstrict or -qhot) that they had with the -O option in earlier versions of the compiler.
-O4
This flag is equivalent to -O3 -qipa with automatic generation of architecture and tuning option ideal for that platform.
-O5
This flag is similiar to -O4, except in this case,-qipa = level = 2.