Options That Control Optimization
These options control various sorts of optimizations.
Without any optimization option, 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.
Turning on optimization flags makes the compiler attempt to improve the
performance and/or code size at the expense of compilation time and
possibly the ability to debug the program.
Not all optimizations are controlled directly by a flag. Only opti-
mizations that have a flag are listed.
-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 com-
pilation time.
In Apple's version of GCC, -fstrict-aliasing, -freorder-blocks, and
-fsched-interblock are disabled by default when optimizing.
-O2 Optimize even more. GCC performs nearly all supported optimiza-
tions that do not involve a space-speed tradeoff. The compiler
does not perform loop unrolling or function inlining when you spec-
ify -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-sib-
ling-calls -fstrength-reduce -fcse-follow-jumps -fcse-skip-blocks
-frerun-cse-after-loop -frerun-loop-opt -fgcse -fgcse-lm
-fgcse-sm -fdelete-null-pointer-checks -fexpensive-optimizations
-fregmove -fschedule-insns -fschedule-insns2 -fsched-interblock
-fsched-spec -fcaller-saves -fpeephole2 -freorder-blocks -fre-
order-functions -fstrict-aliasing -falign-functions -falign-jumps
-falign-loops -falign-labels
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 and -frename-registers
options.
-O0 Do not optimize. This is the default.
|