
Code: Select all
-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
-fmerge-constants
-fthread-jumps
-floop-optimize
-fif-conversion
-fif-conversion2
-fdelayed-branch
-fguess-branch-probability
-fcprop-registers
-O also turns on -fomit-frame-pointer on machines where doing so does not interfere with debugging.
-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:
-fforce-mem
-foptimize-sibling-calls
-fstrength-reduce
-fcse-follow-jumps -fcse-skip-blocks
-frerun-cse-after-loop -frerun-loop-opt
-fgcse -fgcse-lm -fgcse-sm -fgcse-las
-fdelete-null-pointer-checks
-fexpensive-optimizations
-fregmove
-fschedule-insns -fschedule-insns2
-fsched-interblock -fsched-spec
-fcaller-saves
-fpeephole2
-freorder-blocks -freorder-functions
-fstrict-aliasing
-funit-at-a-time
-falign-functions -falign-jumps
-falign-loops -falign-labels
-fcrossjumping
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, -fweb, -frename-registers and -funswitch-loops options.-mmmx, -msse, -msse2, -m3dnow are all redundant, get rid of them.eyeL wrote:err, wait, I thought -fomit-frame-pointer was in there as well?
EDIT:
Ok, here's my cflags now.
CFLAGS="-O3 -march=athlon64 -mmmx -msse -msse2 -m3dnow -funroll-all-loops -fpeel -loops -ftracer -fforce-addr -pipe"
Thoughts, comments, suggestions, ideas?
slycordinator wrote:One small thing with that...
There might be a good reason to leave redundant CFLAGS in.
Lets say one ebuild automatically strips CFLAGS and changes O3 to O2 (since O2 is "safer"). Lets then say that one of the options that O3 provides is perfectly safe. If you add it in redundantly, then you'll still get the effect of it after the ebuild does the change.
Food for thought.
Where do you notice the performance in? Run times, compiling code, or just emerging?Vann wrote:I generally find that my system runs slightly better with -Os than with -O2 or -O3. I imagine it is because it allows for better use of the CPU cache. My CFLAGS are very simple: CFLAGS="-march=athlon-xp -pipe -Os"