Compilers: GNU GCC 4.1, 4.3, 4.4, 4.7
Compilers: IBM Advance Toolchain 5.0
Compilers: IBM Advance Toolchain 6.0
Operating systems: SUSE Linux Enterprise 10, SUSE Linux Enterprise 11, and Red Hat Enterprise Linux Advanced Platform 5 and 6
Last updated: October 2012
Selecting one of the following will take you directly to that section:
Do not optimize. This is the default.
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 -fmerge-constants -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: -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 -funit-at-a-time -falign-functions -falign-jumps -falign-loops -falign-labels -ftree-vrp -ftree-pre
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.
Tune to cpu-type everything applicable about the generated code, except for the ABI and the set of available instructions.
A sample list of supported values for this flag are
Align the start of functions to the next power-of-two greater than n, skipping up to n bytes. For instance, -falign-functions=32 aligns functions to the next 32-byte boundary, but -falign-functions=24 would align to the next 32-byte boundary only if this can be done by skipping 23 bytes or less.
-fno-align-functions and -falign-functions=1 are equivalent and mean that functions will not be aligned.
Some assemblers only support this flag when n is a power of two; in that case, it is rounded up.
If n is not specified, use a machine-dependent default.
Align loops to a power-of-two boundary, skipping up to n bytes like -falign-functions. The hope is that the loop will be executed many times, which will make up for any execution of the dummy operations.
When aligning loops to a power-of-two boundary, only do so if can skip by up to n bytes.
If n is not specified, use a machine-dependent default.
Align branch targets to a power-of-two boundary, for branch targets where the targets can only be reached by jumping, skipping up to n bytes like -falign-functions. In this case, no dummy operations need be executed.
When aligning branch targets to a power-of-two boundary, only do so if can skip by up to n bytes.
If n is not specified, use a machine-dependent default.
Hey! What does this flag do? It's not in the man page.
Well, I know that you, as the well informed and well- connected (with your compiler vendor) will be able to document ALL of your implicitly included flags.
Schedule instructions across basic blocks. This is enabled by default when scheduling before register allocation, i.e. with -fschedule-insns or at -O2 or higher.
Allows the compiler to assume the strictest aliasing rules applicable to the language being compiled. For C (and C++), this activates optimizations based on the type of expressions. In particular, an object of one type is assumed never to reside at the same address as an object of a different type, unless the types are almost the same. For example, an "unsigned int" can alias an "int", but not a "void*" or a "double". A character type may alias any other type.
Pay special attention to code like this:
union a_union { int i; double d; }; int f() { a_union t; t.d = 3.0; return t.i; }
The practice of reading from a different union member than the one most recently written to (called ``type-punning'') is common. Even with -fstrict-aliasing, type-punning is allowed, provided the memory is accessed through the union type. So, the code above will work as expected. However, this code might not:
int f() { a_union t; int* ip; t.d = 3.0; ip = &t.i; return *ip; }
Does not allow the compiler to assume the strictest aliasing rules applicable to the language being compiled. For C (and C++), optimizations based on the type of expressions are not activated.
Unroll loops whose number of iterations can be determined at compile time or upon entry to the loop. -funroll-loops implies both -fstrength-reduce and -frerun-cse-after-loop. This option makes code larger, and may or may not make it run faster.
Sets the following flags:
Aligns larger data types such as doubles on their natural boundaries.
Sets the instruction scheduling parameters for a particular machine type, but does not set the architecture type, register usage, or choice of mnemonics, as -mcpu=cpu_type would. The same values for cpu_type are used for -mtune as for -mcpu. If both are specified, the code generated will use the architecture, registers, and mnemonics set by -mcpu, but the scheduling parameters set by -mtune.
Compile code so that it is not relocatable, but that its external references are relocatable. The resulting code is suitable for applications, but not shared libraries.
Compile code assuming that floating-point operations cannot generate user-visible traps. These traps include division by zero, overflow, underflow, inexact result and invalid operation. This option implies -fno-signaling-nans. Setting this option may allow faster code if one relies on `non-stop' IEEE arithmetic, for example.
Use of this option can result in incorrect output for programs which depend on an exact implementation of IEEE or ISO rules/specifications for math functions.
Compile code assuming that IEEE signaling NaNs may not generate user-visible traps during floating-point operations. Setting this option enabled optimizations that may change the number of exceptions visible with signaling NaNs.
Allow optimizations for floating-point arithmetic that (a) assume that arguments and results are valid and (b) may violate IEEE or ANSI standards. When used at link-time, it may include libraries or startup files that change the default FPU control word or other similar optimizations.
Use of this option may result in incorrect output for programs which depend on an exact implementation of IEEE or ISO rules/specifications for math functions.
Allow optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or +-Infs.
Use of this option may result in incorrect output for programs which depend on an exact implementation of IEEE or ISO rules/specifications for math functions.
Do not set ERRNO after calling math functions that are executed with a single instruction, e.g., sqrt. A program that relies on IEEE exceptions for math error handling may want to use this flag for speed while maintaining IEEE arithmetic compatibility.
Use of this option may result in incorrect output for programs which depend on an exact implementation of IEEE or ISO rules/specifications for math functions.
Re-run common subexpression elimination after loop optimizations have been performed.
Integrate all simple functions into their callers. The compiler heuristically decides which functions are simple enough to be worth integrating in this way.
If all calls to a given function are integrated, and the function is declared "static", then the function is normally not output as assembler code in its own right.
Do not integrate all simple functions into their callers. The compiler heuristically decides which functions are simple enough to be worth integrating in this way.
If all calls to a given function are integrated, and the function is declared "static", then the function is normally not output as assembler code in its own right.
Attempt to avoid false dependencies in scheduled code by making use of registers left over after register allocation. This optimization will most benefit processors with lots of registers. It can, however, make debugging impossible, since variables will no longer stay in a `home register'.
When -fgcse-after-reload is enabled, a redundant load elimination pass is performed after reload. The purpose of this pass is to cleanup redundant spilling.
Move branches with loop invariant conditions out of the loop, with duplicates of the loop on both branches (modified according to result of the condition).
Generate code for a 32-bit environment. The 32-bit environment sets int, long and pointer to 32 bits and generates code that runs on 32 bits system.
Always pop the arguments to each function call as soon as that function returns. For machines which must pop arguments after a function call, the compiler normally lets arguments accumulate on the stack for several function calls and pops them all at once. -fnodefer-pop is disabled at levels -O, -O2, -O3, -Os.
If supported for the target machine, attempt to reorder instructions to exploit instruction slots available after delayed branch instructions. Enabled at levels -O, -O2, -O3, -Os.
If supported for the target machine, attempt to reorder instructions to exploit instruction slots available after delayed branch instructions. -fnoguess-branch-probability is enabled at levels -O, -O2, -O3, -Os.
After register allocation and post-register allocation instruction splitting, we perform a copy-propagation pass to try to reduce scheduling dependencies and occasionally eliminate the copy. -fno-cprop-registers is disabled at levels -O, -O2, -O3, -Os.
Perform loop optimizations: move constant expressions out of loops, simplify exit test conditions and optionally do strength-reduction as well. Enabled at levels -O, -O2, -O3, -Os.
Attempt to transform conditional jumps into branch-less equivalents. This include use of conditional moves, min, max, set flags and abs instructions, and some tricks doable by standard arithmetics. The use of conditional execution on chips where it is available is controlled by if-conversion2. Enabled at levels -O, -O2, -O3, -Os.
Use conditional execution (where available) to transform conditional jumps into branch-less equivalents. Enabled at levels -O, -O2, -O3, -Os.
Perform sparse conditional constant propagation (CCP) on trees. This pass only operates on local scalar variables and is enabled by default at -O and higher.
Perform dead code elimination (DCE) on trees. This flag is enabled by default at -O and higher.
Perform a variety of simple scalar cleanups (constant/copy propagation, redundancy elimination, range propagation and expression simplification) based on a dominator tree traversal. This also performs jump threading (to reduce jumps to jumps). This flag is enabled by default at -O and higher.
Not described in Manual for gcc 4.1
Perform temporary expression replacement during the SSA->normal phase. Single use/single def temporaries are replaced at their use location with their defining expression. This results in non-GIMPLE code, but gives the expanders much more complex trees to work on resulting in better RTL generation. This is enabled by default at -O and higher.
Perform live range splitting during the SSA->normal phase. Distinct live ranges of a variable are split into unique variables, allowing for better optimization later. This is enabled by default at -O and higher.
Perform scalar replacement of aggregates. This pass replaces structure references with scalars to prevent committing structures to memory too early. This flag is enabled by default at -O and higher.
Perform copy renaming on trees. This pass attempts to rename compiler temporaries to other variables at copy locations, usually resulting in variable names which more closely resemble the original variables. This flag is enabled by default at -O and higher.
Perform Full Redundancy Elimination (FRE) on trees. The difference between FRE and PRE is that FRE only considers expressions that are computed on all paths leading to the redundant computation. This analysis faster than PRE, though it exposes fewer redundancies. This flag is enabled by default at -O and higher.
Perform loop header copying on trees. This is beneficial since it increases effectiveness of code motion optimizations. It also saves one jump. This flag is enabled by default at -O and higher. It is not enabled for -Os, since it usually increases code size.
Attempt to merge identical constants (string constants and floating point constants) across compilation units. This option is the default for optimized compilation if the assembler and linker support it. Use -fno-merge-constants to inhibit this behavior. Enabled at levels -O, -O2, -O3, -Os.
Don't keep the frame pointer in a register for functions that don't need one. This avoids the instructions to save, set up and restore frame pointers; it also makes an extra register available in many functions. It also makes debugging impossible on some machines. On some machines, such as the VAX, this flag has no effect, because the standard calling sequence automatically handles the frame pointer and nothing is saved by pretending it doesn't exist. The machine-description macro FRAME_POINTER_REQUIRED controls whether a target machine supports this flag. See Register Usage. Enabled at levels -O, -O2, -O3, -Os.
Perform optimizations where we check to see if a jump branches to a location where another comparison subsumed by the first is found. If so, the first branch is redirected to either the destination of the second branch or a point immediately following it, depending on whether the condition is known to be true or false. Enabled at levels -O2, -O3, -Os.
Perform cross-jumping transformation. This transformation unifies equivalent code and save code size. The resulting code may or may not perform better than without cross-jumping. Enabled at levels -O2, -O3, -Os.
Optimize sibling and tail recursive calls. Enabled at levels -O2, -O3, -Os.
In common subexpression elimination, scan through jump instructions when the target of the jump is not reached by any other path. For example, when CSE encounters an if statement with an else clause, CSE will follow the jump when the condition tested is false. Enabled at levels -O2, -O3, -Os.
This is similar to -fcse-follow-jumps, but causes CSE to follow jumps which conditionally skip over blocks. When CSE encounters a simple if statement with no else clause, -fcse-skip-blocks causes CSE to follow the jump around the body of the if. Enabled at levels -O2, -O3, -Os.
Perform a global common subexpression elimination pass. This pass also performs global constant and copy propagation. Note: When compiling a program using computed gotos, a GCC extension, you may get better runtime performance if you disable the global common subexpression elimination pass by adding -fno-gcse to the command line. Enabled at levels -O2, -O3, -Os.
When -fgcse-lm is enabled, global common subexpression elimination will attempt to move loads which are only killed by stores into themselves. This allows a loop containing a load/store sequence to be changed to a load outside the loop, and a copy/store within the loop. Enabled by default when gcse is enabled.
Perform a number of minor optimizations that are relatively expensive. Enabled at levels -O2, -O3, -Os.
Perform the optimizations of loop strength reduction and elimination of iteration variables. Enabled at levels -O2, -O3, -Os.
Run the loop optimizer twice. Enabled at levels -O2, -O3, -Os.
Enable values to be allocated in registers that will be clobbered by function calls, by emitting extra instructions to save and restore the registers around such calls. Such allocation is done only when it seems to result in better code than would otherwise be produced. This option is always enabled by default on certain machines, usually those which have no call-preserved registers to use instead. Enabled at levels -O2, -O3, -Os.
Disable any machine-specific peephole optimizations. The difference between -fno-peephole and -fno-peephole2 is in how they are implemented in the compiler; some targets use one, some use the other, a few use both. -fpeephole is enabled by default. -fpeephole2 enabled at levels -O2, -O3, -Os.
If supported for the target machine, attempt to reorder instructions to eliminate execution stalls due to required data being unavailable. This helps machines that have slow floating point or memory load instructions by allowing other instructions to be issued until the result of the load or floating point instruction is required. Enabled at levels -O2, -O3, -Os
Similar to -fschedule-insns, but requests an additional pass of instruction scheduling after register allocation has been done. This is especially useful on machines with a relatively small number of registers and where memory load instructions take more than one cycle. Enabled at levels -O2, -O3, -Os.
Don't schedule instructions across basic blocks. This is normally enabled by default when scheduling before register allocation, i.e. with -fschedule-insns or at -O2 or higher.
Don't allow speculative motion of non-load instructions. This is normally enabled by default when scheduling before register allocation, i.e. with -fschedule-insns or at -O2 or higher.
Use global dataflow analysis to identify and eliminate useless checks for null pointers. The compiler assumes that dereferencing a null pointer would have halted the program. If a pointer is checked after it has already been dereferenced, it cannot be null. In some environments, this assumption is not true, and programs can safely dereference null pointers. Use -fno-delete-null-pointer-checks to disable this optimization for programs which depend on that behavior. Enabled at levels -O2, -O3, -Os.
Reorder basic blocks in the compiled function in order to reduce number of taken branches and improve code locality. Enabled at levels -O2, -O3.
Reorder functions in the object file in order to improve code locality. This is implemented by using special subsections .text.hot for most frequently executed functions and .text.unlikely for unlikely executed functions. Reordering is done by the linker so object file format must support named sections and linker must place them in a reasonable way. Also profile feedback must be available in to make this option effective. See -fprofile-arcs for details. Enabled at levels -O2, -O3, -Os.
Parse the whole compilation unit before starting to produce code. This allows some extra optimizations to take place but consumes more memory (in general). There are some compatibility issues with unit-at-at-time mode: * enabling unit-at-a-time mode may change the order in which functions, variables, and top-level asm statements are emitted, and will likely break code relying on some particular ordering. The majority of such top-level asm statements, though, can be replaced by section attributes. * unit-at-a-time mode removes unreferenced static variables and functions. This may result in undefined references when an asm statement refers directly to variables or functions that are otherwise unused. In that case either the variable/function shall be listed as an operand of the asm statement operand or, in the case of top-level asm statements the attribute used shall be used on the declaration. * Static functions now can use non-standard passing conventions that may break asm statements calling functions directly. Again, attribute used will prevent this behavior. As a temporary workaround, -fno-unit-at-a-time can be used, but this scheme may not be supported by future releases of GCC. Enabled at levels -O2, -O3.
-falign-labels=n Align all branch targets to a power-of-two boundary, skipping up to n bytes like -falign-functions. This option can easily make code slower, because it must insert dummy operations for when the branch target is reached in the usual flow of the code. -fno-align-labels and -falign-labels=1 are equivalent and mean that labels will not be aligned. If -falign-loops or -falign-jumps are applicable and are greater than this value, then their values are used instead. If n is not specified or is zero, use a machine-dependent default which is very likely to be `1', meaning no alignment. Enabled at levels -O2, -O3.
Perform Value Range Propagation on trees. This is similar to the constant propagation pass, but instead of values, ranges of values are propagated. This allows the optimizers to remove unnecessary range checks like array bound checks and null pointer checks. This is enabled by default at -O2 and higher. Null pointer check elimination is only done if -fdelete-null-pointer-checks is enabled.
Perform Partial Redundancy Elimination (PRE) on trees. This flag is enabled by default at -O2 and -O3.
Peels the loops for that there is enough information that they do not roll much (from profile feedback). It also turns on complete loop peeling (i.e. complete removal of loops with small constant number of iterations). Enabled with -fprofile-use
Perform loop vectorization on trees.
Perform linear loop transformations on tree. This flag can improve cache performance and allow further loop optimizations to take place.
Generate code that uses vector/scalar (VSX) instructions, and also enable the use of built-in functions that allow more direct access to the VSX instruction set.
Generate code that uses AltiVec instructions, and also enable the use of built-in functions that allow more direct access to the AltiVec instruction set.
Allows GCC to generate the popcount instruction implemented on the POWER7 processor and other processors that support the PowerPC V2.06 architecture.
This option will enable GCC to use RCPSS and RSQRTSS instructions (and their vectorized variants RCPPS and RSQRTPS) with an additional Newton-Raphson step to increase precision instead of DIVSS and SQRTSS (and their vectorized variants) for single precision floating point arguments. These instructions are generated only when -funsafe-math-optimizations is enabled together with -finite-math-only and -fno-trapping-math.
Assume that the current compilation unit represents whole program being compiled. All public functions and variables with the exception of "main" and those merged by attribute "externally_visible" become static functions and in a affect gets more aggressively optimized by interprocedural optimizers.
Enables the use of linker plugin during link time optimization. This option relies on the linker plugin support in linker that is available in gold or in GNU ld 2.21 or newer. This option enables the extraction of object files with GIMPLE bytecode out of library archives. This improves the quality of optimization by exposing more code the the link time optimizer. This information specify what symbols can be accessed externally (by non-LTO object or during dynamic linking). Resulting code quality improvements on binaries (and shared libraries that do use hidden visibility) is similar to -fwhole-program. See -flto for a description on the effect of this flag and how to use it. Enabled by default when LTO support in GCC is enabled and GCC was compiled with a linker supporting plugins (GNU ld 2.21 or newer or gold).
This option runs the standard link-time optimizer. When invoked with source code, it generates GIMPLE (one of GCC's internal representations) and writes it to special ELF sections in the object file. When the object files are linked together, all the function bodies are read from these ELF sections and instantiated as if they had been part of the same translation unit.
Link with libhugetlbfs.so. This enables heap to be backed by the 16 Megabyte pages.
Pass the --hugetlbfs-link=BDT flag to the linker so that the text, initialized data, and BSS segments of the application are backed by hugepages.
Pass the --hugetlbfs-link=B flag to the linker so that the BSS segment of the application are backed by hugepages.
Inform the compiler to use the linker located under /usr/share/libhugetlbfs. This is needed when we pass the --hugeltlbfs-link option to the linker.
Link with tcmalloc's library for Linux on POWER. This is a library that optimizes calls to new, delete, malloc and free.
Link with MicroQuill's SmartHeap (32-bit) library for Linux on POWER. This is a library that optimizes calls to new, delete, malloc and free.
Link with MicroQuill's SmartHeap (64-bit) library for Linux on POWER. This is a library that optimizes calls to new, delete, malloc and free.
Process FILE as if `#include "file"' appeared as the first line of the primary source file. However, the first directory searched for FILE is the preprocessor's working directory _instead of_ the directory containing the main source file. If not found there, it is searched for in the remainder of the `#include "..."' search chain as normal. If multiple `-include' options are given, the files are included in the order they appear on the command line.
Let the type "char" be signed, like "signed char".
Invoke the GCC C compiler. By default this will generate code for a 64-bit environment.
Invoke the Advance Toolchain C compiler. By default this will generate code for a 64-bit environment.
Invoke the GCC C++ compiler. By default this will generate code for a 64-bit environment.
Invoke the Advance Toolchain C++ compiler. By default this will generate code for a 64-bit environment.
Invoke the GCC fortran compiler. By default this will generate code for a 64-bit environment.
Invoke the Advance Toolchain fortran compiler. By default this will generate code for a 64-bit environment.
Fortran appends an underscore to external names. If this option is not used, \s-1GNU\s0 Fortran appends two underscores to names with underscores and one underscore to external names with no underscores. \s-1GNU\s0 Fortran also appends two underscores to internal names with underscores to avoid naming collisions with external names. With this option the second underscore is not used,
Let the type `char' be unsigned, like `unsigned char'. Each kind of machine has a default for what `char' should be. It is either like `unsigned char' by default or like `signed char' by default. Ideally, a portable program should always use `signed char' or `unsigned char' when it depends on the signedness of an object. But many programs have been written to use plain `char' and expect it to be signed, or expect it to be unsigned, depending on the machines they were written for. This option, and its inverse, let you make such a program work with the opposite default. The type `char' is always a distinct type from each of `signed char' or `unsigned char', even though its behavior is always just like one of those two.
Deprecated define from the SPEC CPU2006 development kits. It was accidentally left in the benchmark runs. This is not defined anywhere in the benchmark code and does not affect reproducibility of the results.