This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++ optimising inlines ... could this be improved ?
- From: Edward Welbourne <eddy at opera dot no>
- To: bug-gcc at gnu dot org
- Date: Fri, 22 Nov 2002 17:11:05 +0100
- Subject: g++ optimising inlines ... could this be improved ?
- Reply-to: eddy at opera dot no
Consider the following noddy program: <code>
class Dummy {
public:
inline Dummy(char *text) {}
inline void say(char *text) {}
};
int main(int count, char *args[]) {
Dummy obj("hello");
obj.say("goodbye");
return 0;
}
</code> (actually a caricature of what various bits of code look like
if you undefine _DEBUG while using Maurice J. Fox's Debug class).
Compiling this with g++ -O3 (which allegedly does inlining) I get a
binary which does include the two string arguments of methods with
empty bodies. Perhaps my intuitions are broken (it happens,
especially when C++ and optimisers are involved), but it seemed like
inlining should/could have left us with no references to the two
strings, so they could have been eliminated.
I also tried various command-lines using various of -finline-functions
-fno-keep-static-consts -fexpensive-optimizations -fwritable-strings
and with -Os in place of -O3 (both with and without
-finline-functions) without changing the outcome.
The `bug' is merely a missed optimisation; a minor irritant.
However, the benefits for folk who love -Os should be clear ...
This is with 2.95.4 and 3.0.4 (which actually manages to produce a
smaller executable, even on this frivolous program ;^) on a Debian
GNU/Linux GenuineIntel Pentium III (Coppermine) whose uname -a is:
Linux whorl 2.2.19pre17 #1 Tue Mar 13 22:37:59 EST 2001 i686 unknown
g++ -v says: <quote version="3.0.4">
Reading specs from /usr/lib/gcc-lib/i386-linux/3.0.4/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,proto,objc --prefix=/usr --infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as --with-gnu-ld --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-checking --enable-threads=posix --enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.0.4
</quote> and <quote version="2.95.4">
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20011002 (Debian prerelease)
</quote> (sorry, it says nothing about configure; maybe the debian
maintainer can help). In both cases, this is `out of the box' from
the relevant Debian packages without any local modifications.
Of course, The Right Way to achieve the effects the Debug class is
after is to use a macro so that the compiler never *sees* the strings
(the preprocessor having already discarded them) in the non-_DEBUG
case, and that's what we're now doing ... but the hole in the
optimiser seemed like it might interest you.
Eddy.