[Bug c++/23372] [4.0/4.1 Regression] Temporary aggregate copy not elided when passing parameters by value

guillaume dot melquiond at ens-lyon dot fr gcc-bugzilla@gcc.gnu.org
Fri Aug 26 17:40:00 GMT 2005


------- Additional Comments From guillaume dot melquiond at ens-lyon dot fr  2005-08-26 17:38 -------
> all of 3.4 and 4.1 produce exactly two temporaries.

Yet I said that g++ 3.4 did not produce any temporary, and I still think so. No
temporaries, only g's stack frame. See the following assembly code for the C
testcase (the generated assembly is the same as for C++, but easier to read
since there is no name mangling nor local labels).

h:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $4008, %esp
        movl    %esp, %eax
        subl    $12, %esp
        pushl   %eax
        call    f
        addl    $12, %esp
        call    g
        leave
        ret

For the sake of completeness, I'm also writing the assembly output for GCC 4.0,
so that the regression with respect to GCC 3.4 is clearly visible. Two
temporaries and two memory copies:

h:
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %esi
        pushl   %ebx
        subl    $8012, %esp
        leal    -8008(%ebp), %ebx
        pushl   %ebx
        call    f
        leal    -4008(%ebp), %esi
        subl    $8, %esp
        pushl   $4000
        pushl   %ebx
        pushl   %esi
        call    memcpy
        subl    $3968, %esp
        movl    %esp, %eax
        pushl   %edx
        pushl   $4000
        pushl   %esi
        pushl   %eax
        call    memcpy
        addl    $16, %esp
        call    g
        addl    $4000, %esp
        leal    -8(%ebp), %esp
        popl    %ebx
        popl    %esi
        popl    %ebp
        ret

The C testcase is almost identical to the C++ testcase:

typedef struct A { int a[1000]; } A;
A f();
void g(A);
void h() { g(f()); }

And this is my version of GCC 3.4:

$ LANG=C gcc-3.4 -v
Reading specs from /usr/lib/gcc/i486-linux-gnu/3.4.5/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,f77,pascal,objc,ada --prefix=/usr --libexecdir=/usr/lib
--with-gxx-include-dir=/usr/include/c++/3.4 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --program-suffix=-3.4
--enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu
--enable-libstdcxx-debug i486-linux-gnu
Thread model: posix
gcc version 3.4.5 20050821 (prerelease) (Debian 3.4.4-8)

Hope it helps.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23372



More information about the Gcc-bugs mailing list