Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What extra optimisation does g++ do with -Ofast?

In g++ 4.6 (or later), what extra optimisations does -Ofast enable other than -ffast-math?

The man page says this option "also enables optimizations that are not valid for all standard compliant programs". Where can I find more information about whether this might affect my program or not?

like image 974
Scott Smedley Avatar asked May 04 '12 05:05

Scott Smedley


People also ask

What optimization does GCC do?

The compiler optimizes to reduce the size of the binary instead of execution speed. If you do not specify an optimization option, gcc attempts to reduce the compilation time and to make debugging always yield the result expected from reading the source code.

What does optimize code do?

We say that code optimization is writing or rewriting code so a program uses the least possible memory or disk space, minimizes its CPU time or network bandwidth, or makes the best use of additional cores. In practice, we sometimes default to another definition: Writing less code.

How many optimization levels are there in GCC?

GCC has since added -Og to bring the total to 8. From the man page: -O0 (do no optimization, the default if no optimization level is specified) -O1 (optimize minimally)


Video Answer


2 Answers

Here's a command for checking what options are enabled with -Ofast:

$ g++ -c -Q -Ofast --help=optimizers | grep enabled

Since I only have g++ 4.4 that doesn't support -Ofast, I can't show you the output.

like image 128
Daniel Näslund Avatar answered Sep 22 '22 02:09

Daniel Näslund


The -Ofast options might silently enable the gcc C++ extensions. You should check your sources to see if you make any use of them. In addition, the compiler might turn off some obscure and rarely encountered syntax checking for digraphs and trigraphs (this only improves compiler performance, not the speed of the compiled code).

like image 30
TemplateRex Avatar answered Sep 21 '22 02:09

TemplateRex