How many GCC optimization levels are there?
I tried gcc -O1, gcc -O2, gcc -O3, and gcc -O4
If I use a really large number, it won’t work.
However, I have tried
gcc -O100
and it compiled.
How many optimization levels are there?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To be pedantic, there are 8 different valid -O options you can give to gcc, though there are some that mean the same thing.
The original version of this answer stated there were 7 options. GCC has since added
-Ogto bring the total to 8.From the man page:
-O(Same as-O1)-O0(do no optimization, the default if no optimization level is specified)-O1(optimize minimally)-O2(optimize more)-O3(optimize even more)-Ofast(optimize very aggressively to the point of breaking standard compliance)-Og(Optimize debugging experience. -Og enables optimizations that do not interfere with debugging. It should be theoptimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization
while maintaining fast compilation and a good debugging experience.)
-Os(Optimize for size.-Osenables all-O2optimizations that do not typically increase code size. It also performs further optimizationsdesigned to reduce code size.
-Osdisables the following optimization flags:-falign-functions -falign-jumps -falign-loops -falign-labels -freorder-blocks -freorder-blocks-and-partition -fprefetch-loop-arrays -ftree-vect-loop-version)There may also be platform specific optimizations, as @pauldoo notes, OS X has
-Oz.