Snipped from "man gcc":
Optimization Options
These options control various sorts of optimizations:
-O1
Optimize. Optimizing compilation takes somewhat more time, and a lot more memory for a large function.
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.
Without `-O', only variables declared register are allocated in registers. The resulting compiled code is a little worse than produced by PCC without `-O'.
With `-O', the compiler tries to reduce code size and execution time.
When you specify `-O', the two options `-fthread-jumps' and `-fdefer-pop' are turned on. On machines that have delay slots, the `-fdelayed-branch' option is turned on. For those machines that can support debugging even without a frame pointer, the `-fomit-frame-pointer' option is turned on. On some machines other flags may also be turned on.
-O2
Optimize even more. Nearly all supported optimizations that do not involve a space-speed tradeoff are performed. Loop unrolling and function inlining are not done, for example. As compared to -O, this option increases both compilation time and the performance of the generated code.
-O3
Optimize yet more. This turns on everything -O2 does, along with also turning on -finline-func*- tions.
-O0
Do not optimize.
If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.