How to find out which optimizations are actually applied when using gcc?
From https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Optimize-Options.html#Optimize-Options:
You can invoke GCC with -Q --help=optimizers
to find out the exact set of optimizations that are enabled at each level.
Example: (count number of optimization options enabled) A file is not necessary.
$ g++ -std=c++17 -O2 -Q --help=optimizers 2>&1 |grep enabled |wc -l
135
Note that many optimizations enabled by -O1/2/3 have no individual flags (see also: c++ - g++ O1 is not equal to O0 with all related optimization flags - Stack Overflow)
Use -S -fverbose-asm
to list every silently applied option (including optimization ones) in assembler output header.
Have a look at the -fdump-tree-[switch]
flags. You can use -fdump-tree-all
to get loads of information.
Also in trunk gcc -fopt-info-[options]
will give you access higher level optimization information e.g. when particular optimizations were applied, missed etc e.g.
-fopt-info-inline-optimized-missed
Prints all successful and missed inlining optimizations (to stderr
in this case). This is obviously pretty new functionality so I'm not sure how well supported it is yet.
In earlier releases they had -ftree-vectorizer-verbose=n
which is now being deprecated in favor of opt-info.
All these options are listed here https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html though it can be a bit tricky to pick out the useful ones.