On inlining in C++
Diego Novillo
dnovillo@redhat.com
Mon Dec 15 18:49:00 GMT 2003
On Tue, 2003-08-05 at 22:00, Joe Buck wrote:
> 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);
> }
> --------------------------------------
>
Much later than I would've wanted, but this is fixed now on tree-ssa.
Both functions are optimized into 'return 3;'.
Diego.
More information about the Gcc
mailing list