g++ optimising inlines ... could this be improved ?

Edward Welbourne eddy@opera.no
Fri Nov 22 08:36:00 GMT 2002

Consider the following noddy program: <code>

class Dummy {
	inline Dummy(char *text) {}
	inline void say(char *text) {}

int main(int count, char *args[]) {
	Dummy obj("hello");
	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.

hmm ... initially sent to bug-gcc@gnu.org but bounced because: <quote>

The original message was received at Fri, 22 Nov 2002 10:47:20 -0500
from fencepost.gnu.org []

   ----- The following addresses had permanent fatal errors -----
    (reason: 553 5.3.0 <bug-gcc-in@cygnus.com>... is now part of Red Hat please see www.redhat.com)

   ----- Transcript of session follows -----
... while talking to int-mx1.corp.redhat.com.:
>>> RCPT To:<bug-gcc-in@cygnus.com>
<<< 553 5.3.0 <bug-gcc-in@cygnus.com>... is now part of Red Hat please see www.redhat.com
550 5.1.1 <bug-gcc-in@cygnus.com>... User unknown

Content-Type: message/delivery-status

Reporting-MTA: dns; mx1.redhat.com
Received-From-MTA: DNS; fencepost.gnu.org
Arrival-Date: Fri, 22 Nov 2002 10:47:20 -0500

Final-Recipient: RFC822; bug-gcc-in@cygnus.com
Action: failed
Status: 5.1.3
Remote-MTA: DNS; int-mx1.corp.redhat.com
Diagnostic-Code: SMTP; 553 5.3.0 <bug-gcc-in@cygnus.com>... is now part of Red Hat please see www.redhat.com
Last-Attempt-Date: Fri, 22 Nov 2002 10:47:20 -0500

</quote> and red-hat's web-site didn't provide an obvious link I could
see for gcc bug reporting ... but http://gcc.gnu.org/bugs.html offered
an alternate address ...

More information about the Gcc-bugs mailing list