Reputation: 55579
I know that -O1 automatically turns on certain flags. These flags can be turned on manually though. If I don't specify -O1, it should still be possible to get -O1 optimization by specifying all the flags that -O1 turns on.
I tried
-fthread-jumps -fcprop-registers -fguess-branch-probability
but it still does not do -O1 optimization. I can tell when I use gprof because the performance is not as good.
Which flags do I turn on to get -O1 optimization?
Upvotes: 6
Views: 4833
Reputation: 94485
You can also try to use this pragma (it requires GCC >= 4.4) :
#pragma GCC optimize opt_list
void f()
This pragma allow you to turn on and off specific optimizations for given function. opt_list is list of -f* options without -f.
There is also function attribute to change optimization level:
int f() __attribute__((optimize(1)));
You also can change global optimization level (apply to all subsequent functions):
#pragma GCC optimize 1
#pragma GCC optimize 0
You also can use (apply to all subsequent functions):
#pragma GCC optimization_level n
and for Intel C compiler (doc; applied only for next function)
#pragma intel optimization_level n
Upvotes: 3
Reputation: 13201
One way to find out:
gcc -O1 -c -Q -v dummy.c
(where dummy.c is your filename.) This causes gcc to spew the flags used to the command line.
Edit: Please see kastauyra's answer on this. It appears you cannot simulate full -O1
optimization with -f
flags alone.
Upvotes: 15
Reputation: 10866
Unfortunately, that's impossible. There are a lot of individual optimization flags turned on by -O1, true, however a lot of code in GCC checks global optimization flag value and performs optimizations not specified by any of -f.. options.
Upvotes: 13
Reputation: 2897
From the manual:
-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:
-fauto-inc-dec
-fcprop-registers
-fdce
-fdefer-pop
-fdelayed-branch
-fdse
-fguess-branch-probability
-fif-conversion2
-fif-conversion
-fipa-pure-const
-fipa-reference
-fmerge-constants
-fsplit-wide-types
-ftree-builtin-call-dce
-ftree-ccp
-ftree-ch
-ftree-copyrename
-ftree-dce
-ftree-dominator-opts
-ftree-dse
-ftree-forwprop
-ftree-fre
-ftree-phiprop
-ftree-sra
-ftree-pta
-ftree-ter
-funit-at-a-time
Upvotes: 3
Reputation: 61609
This depends on your version of gcc
. See the gcc
manpage.
On my machine, -O
(which is -O1
) turns on the following optimizations:
-fauto-inc-dec -fcprop-registers -fdce -fdefer-pop -fdelayed-branch
-fdse -fguess-branch-probability -fif-conversion2 -fif-conversion
-finline-small-functions -fipa-pure-const -fipa-reference
-fmerge-constants -fsplit-wide-types -ftree-builtin-call-dce
-ftree-ccp -ftree-ch -ftree-copyrename -ftree-dce
-ftree-dominator-opts -ftree-dse -ftree-fre -ftree-sra -ftree-ter
-funit-at-a-time
-O also turns on -fomit-frame-pointer on machines where doing so
does not interfere with debugging.
Upvotes: 0