http://blog.csdn.net/lanmanck/article/details/5776173
少优化->多优化:
O0 -->> O1 -->> O2 -->> O3
-O0表示没有优化,-O1为缺省值,-O3优化级别最高
英文解析:
`-O '
`-O1 '
Optimize. Optimizing compilation takes somewhat more time, and a
lot more memory for a large function.
With `-O ', the compiler tries to reduce code size and execution
time, without performing any optimizations that take a great deal
of compilation time.
`-O ' turns on the following optimization flags:
-fdefer-pop
-fdelayed-branch
-fguess-branch-probability
-fcprop-registers
-floop-optimize
-fif-conversion
-fif-conversion2
-ftree-ccp
-ftree-dce
-ftree-dominator-opts
-ftree-dse
-ftree-ter
-ftree-lrs
-ftree-sra
-ftree-copyrename
-ftree-fre
-ftree-ch
-funit-at-a-time
-fmerge-constants
`-O ' also turns on `-fomit-frame-pointer ' on machines where doing
so does not interfere with debugging.
`-O ' doesn 't turn on `-ftree-sra ' for the Ada compiler. This
option must be explicitly specified on the command line to be
enabled for the Ada compiler.
`-O2 '
Optimize even more. GCC performs nearly all supported
optimizations that do not involve a space-speed tradeoff. The
compiler does not perform loop unrolling or function inlining when
you specify `-O2 '. As compared to `-O ', this option increases
both compilation time and the performance of the generated code.
`-O2 ' turns on all optimization flags specified by `-O '. It also
turns on the following optimization flags:
-fthread-jumps
-fcrossjumping
-foptimize-sibling-calls
-fcse-follow-jumps -fcse-skip-blocks
-fgcse -fgcse-lm
-fexpensive-optimizations
-fstrength-reduce
-frerun-cse-after-loop -frerun-loop-opt
-fcaller-saves
-fpeephole2
-fschedule-insns -fschedule-insns2
-fsched-interblock -fsched-spec
-fregmove
-fstrict-aliasing
-fdelete-null-pointer-checks
-freorder-blocks -freorder-functions
-falign-functions -falign-jumps
-falign-loops -falign-labels
-ftree-vrp
-ftree-pre
Please note the warning under `-fgcse ' about invoking `-O2 ' on
programs that use computed gotos.
`-O3 '
Optimize yet more. `-O3 ' turns on all optimizations specified by
`-O2 ' and also turns on the `-finline-functions ',
`-funswitch-loops ' and `-fgcse-after-reload ' options.
`-O0 '
Do not optimize. This is the default.
///==================另外还有个Os选项==========================
http://hi.baidu.com/ah__fu/blog/item/cc9fd19b801948bdc9eaf4b3.html
在研究编译驱动的makefile的时候,发现GCC的命令行里面有一个-Os的优化选项。
遍查GCC文档,发现了-O0, -O1, -O2, -O3,就是没有发现-Os。
祭出GOOGLE大法搜了一下,终于发现这篇文章说明了-Os的作用:
http://www.linuxjournal.com/article/7269
原来-Os相当于-O2.5。是使用了所有-O2的优化选项,但又不缩减代码尺寸的方法。
详细的说明如下:
Level 2.5 (-Os)
The special optimization level (-Os or size) enables all -O2 optimizations that do not increase code size; it puts the emphasis on size over speed. This includes all second-level optimizations, except for the alignment optimizations. The alignment optimizations skip space to align functions, loops, jumps and labels to an address that is a multiple of a power of two, in an architecture-dependent manner. Skipping to these boundaries can increase performance as well as the size of the resulting code and data spaces; therefore, these particular optimizations are disabled. The size optimization level is enabled as:
gcc -Os -o test test.c
In gcc 3.2.2, reorder-blocks is enabled at -Os, but in gcc 3.3.2 reorder-blocks is disabled.
==============================
补充:在GCC的官方文档里又发现了关于-Os的说明:
http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Optimize-Options.html#Optimize-Options
//=============================================
http://blog.csdn.net/ison81/archive/2009/05/07/4158576.aspx