On inlining in C++

Joe Buck jbuck@synopsys.com
Wed Aug 6 02:15:00 GMT 2003


> > There are tons of messages in this (or related thread) so it might be
> > possible that I missed a message that disagreed with the
> > interpretation of the documentation I quoted.  Can you give reference 
> > to such a message?

On Tue, Aug 05, 2003 at 11:16:56AM -0700, Geoff Keating wrote:
> I would point out that the documentation says "as fast as a macro",
> but it should really say "as fast or faster than a macro".

Ah, but even if we fix the inlining issues, we still aren't keeping the
promise: inline functions are still slower in many cases if struct/class
objects with more than one member are passed by reference.

Compile the following code with "gcc -O2 -S il.C" using the trunk on x86,
and take a look.  The problem is that we prematurely commit the tmp object
to the stack, even though after inlining its address is not taken.

--------------------------------------
struct bar { int i; int j;};

#define MACRO(foo) (foo).i + (foo).j

inline int func(const bar& foo) {
    return foo.i + foo.j;
}

int call_macro()
{
    bar tmp;
    tmp.i = 1;
    tmp.j = 2;
    return MACRO(tmp);
}

int call_func()
{
    bar tmp;
    tmp.i = 1;
    tmp.j = 2;
    return func(tmp);
}
--------------------------------------



More information about the Gcc mailing list