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?
Turning on optimization flags makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program. The compiler performs optimization based on the knowledge it has of the program.
The degree to which the compiler will optimize the code it generates is controlled by the -O flag. In the absence of any version of the -O flag, the compiler generates straightforward code with no instruction reordering or other attempt at performance improvement.
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.
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With