Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is C++ whole program optimization done in gcc if I set optimization -O3?

I'm wondering if whole program optimization is done if I just specify optimization level 3 in gcc (version 4.8.1 running on Ubuntu 12.04) or if I have to explicitly specify whole program optimization as a gcc option?

like image 972
Nathan Doromal Avatar asked Nov 05 '13 16:11

Nathan Doromal


People also ask

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.

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.

Does compiler do code optimization?

Compilers are free to optimize code so long as they can guarantee the semantics of the code are not changed.


1 Answers

-fwhole-program (and -flto) are not automatically set by any -O options. Source: http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html . Options that are part of an -O optimization level are marked as such in there, and there is also a list of enabled options for each -O.

like image 181
us2012 Avatar answered Oct 03 '22 21:10

us2012