7.6.6 Options for Controlling Optimization

The following options control compiler optimizations. Optimization levels available depend on the compiler license (see the Optimizations section).

Table 7-11. General Optimization Options
OptionLicenseDefinition
-O0AllDo not optimize. (This is the default.)

Without -O, the compiler’s goal is to reduce the cost of compilation and to make debugging produce the expected results. Statements are independent: if you stop the program with a breakpoint between statements, you can then assign a new value to any variable or change the program counter to any other statement in the function and get exactly the results you would expect from the source code.

The compiler only allocates variables declared register in registers.

-O

-O1

AllOptimize for both speed and size. Optimizing compilation takes somewhat longer, and a lot more host memory for a large function. With -O, the compiler tries to reduce code size and execution time. The compiler turns on -fthread-jumps and -fdefer-pop and turns on -fomit-frame-pointer.
-O2AllOptimize more for speed. -O2 turns on all optional optimizations except for loop unrolling (-funroll-loops), function inlining (-finline-functions), and strict aliasing optimizations (-fstrict-aliasing). It also turns on Frame Pointer elimination (-fomit-frame-pointer). As compared to -O, this option increases both compilation time and the performance of the generated code.
-O3PROOptimize even more for speed (superset of -O2). -O3 turns on all optimizations specified by -O2 and also turns on the inline-functions option.
-OsPROOptimize even more for size (superset of -O2). -Os enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.