Chapter 4. GCC Command Options
lation unit. Sometimes this is useful, such as if, in the debugger, you want to cast a value to a type
that is not actually used in your program (but is declared). More often, however, this results in a
significant amount of wasted space. With this option, GCC will avoid producing debug symbol
output for types that are nowhere used in the source file being compiled.
4.10. 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 optimizations 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
, the compiler tries to reduce code size and execution time, without performing any
-O
optimizations that take a great deal of compilation time.
turns on the following optimization flags:
-O
-fdefer-pop
-fmerge-constants
-fthread-jumps
-floop-optimize
-fcrossjumping
-fif-conversion
-fif-conversion2
-fdelayed-branch
-fguess-branch-probability
-fcprop-registers
also turns on
-O
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
mance of the generated code.
turns on all optimization flags specified by
-O2
flags:
-fforce-mem
-foptimize-sibling-calls
-fstrength-reduce
-fcse-follow-jumps
-frerun-cse-after-loop
-fgcse
-fgcse-lm
-fdelete-null-pointer-checks
-fexpensive-optimizations
-fomit-frame-pointer
. As compared to
, this option increases both compilation time and the perfor-
-O
-fcse-skip-blocks
-frerun-loop-opt
-fgcse-sm
on machines where doing so does not interfere with
. It also turns on the following optimization
-O
47
Need help?
Do you have a question about the ENTERPRISE LINUX 3 - USING GCC and is the answer not in the manual?
Questions and answers