qdii
qdii

Reputation: 12963

What are GCC’s expensive optimizations?

GCC documentation is not particularly verbose about it. What it says is:

-fexpensive-optimizations:

     Perform a number of minor optimizations that are relatively expensive.

Which kind of optimizations are these? Any example?

Upvotes: 21

Views: 5392

Answers (1)

timday
timday

Reputation: 24892

I'm not enough of a compiler gee^H^H^H expert to be able to make much of this, but maybe someone can build on it...

The relevant bits of gcc can be obtained easily enough (if you don't try and check out the whole thing) with:

svn co --depth=immediates svn://gcc.gnu.org/svn/gcc/trunk/gcc gcc
cd gcc
svn --set-depth infinity update config c cp

(at least that's the subset which seemed relevant to C/C++ which I found stuff in; add other directories if you're interested in other languages gcc supports)

And then

grep -R flag_expensive_optimizations . | grep -v .svn

yields a screen's worth (35 lines) of hits on a small number of files. I'll leave it to someone else to post a more detailed analysis (if anyone actually cares enough).

A couple of them caught my eye. I'll mention that (at time of writing):

  • The sole mention of flag_expensive_optimizations in cp/ (C++ support) is in a section of code commented /* Handle ordinary C++ destructors. */ and seems to influence the setting of a LOOKUP_NONVIRTUAL flag, with associated comment /* Optimize for space over speed here. */

  • There are a few hits within the processor-specific config/ directory (sparc, alpha, sh, i386) . The only i386 one applies for TARGET_AVX when not optimizing for size and is commented /* When not optimize for size, enable vzeroupper optimization for TARGET_AVX with -fexpensive-optimizations and split 32-byte AVX unaligned load/store. */

A glance at a few other hits persuaded me I should just be content to leave my knowledge of this feature at the level of the gcc documentation.

Upvotes: 17

Related Questions