Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out which optimizations are actually applied when using gcc?

Tags:

With IBM's XL compiler family it is possible to supply two options (-qreport and -qlist) to generate reports for each source file that include information on which optimizations were applied, or which parts of the code could not be optimized (and why).

Is it possible to get a similar reporting for GNU's g++ - and if yes, how to do it?

like image 584
Michael Schlottke-Lakemper Avatar asked Feb 06 '13 19:02

Michael Schlottke-Lakemper


People also ask

How do I know if GCC is not optimized?

Compiler specific pragma gcc provides pragma GCC as a way to control temporarily the compiler behavior. By using pragma GCC optimize("O0") , the optimization level can be set to zero, which means absolutely no optimize for gcc.

What are the optimization levels in GCC?

-O1 (optimize minimally) -O2 (optimize more) -O3 (optimize even more) -Ofast (optimize very aggressively to the point of breaking standard compliance)

Is GCC an optimizing compiler?

GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. As compared to -O , this option increases both compilation time and the performance of the generated code.

How do I disable compiler optimization GCC?

Use the command-line option -O0 (-[capital o][zero]) to disable optimization, and -S to get assembly file. Look here to see more gcc command-line options.


1 Answers

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.

like image 107
jmetcalfe Avatar answered Sep 27 '22 19:09

jmetcalfe