[Bug c++/29375] New: gcc4.0.3 produces code that copies a structure twice

deb at pixar dot com gcc-bugzilla@gcc.gnu.org
Sat Oct 7 03:34:00 GMT 2006


Using built-in specs.
Target: x86_64-redhat-linux-gnu
Configured with: ../gcc-4.0.3/configure x86_64-redhat-linux-gnu
--with-ld=/pixar/d2/sets/tools-03/bin/ld
--with-as=/pixar/d2/sets/tools-03/bin/as --prefix=/pixar/d2/sets/tools-03
--exec-prefix=/pixar/d2/sets/tools-03 --bindir=/pixar/d2/sets/tools-03/bin
--sbindir=/pixar/d2/sets/tools-03/sbin --sysconfdir=/pixar/d2/sets/tools-03/etc
--datadir=/pixar/d2/sets/tools-03/share
--includedir=/pixar/d2/sets/tools-03/include
--libdir=/pixar/d2/sets/tools-03/lib
--libexecdir=/pixar/d2/sets/tools-03/libexec
--localstatedir=/pixar/d2/sets/tools-03/var
--sharedstatedir=/pixar/d2/sets/tools-03/com
--mandir=/pixar/d2/sets/tools-03/man --infodir=/pixar/d2/sets/tools-03/info
--enable-version-specific-runtime-libs --enable-symvers
--enable-languages=c++,objc,f95 --enable-threads=posix --enable-shared
--enable-mudflap
Thread model: posix
gcc version 4.0.3


----------------------code----------------
struct Big {
    char data[1024];
};

void ByValue(Big);

void MakeACopy() {
    Big stuff;
    ByValue(stuff);
}
-----------------------------------

The relevant assembly code, when compiled as:  g++ -O2 -S prog.cpp


.globl _Z9MakeACopyv
        .type   _Z9MakeACopyv, @function
_Z9MakeACopyv:
.LFB2:
        pushq   %rbx
.LCFI0:
        movl    $1024, %edx
        subq    $3072, %rsp
.LCFI1:
        leaq    2048(%rsp), %rbx
        leaq    1024(%rsp), %rsi
        movq    %rbx, %rdi
        call    memcpy
        movq    %rbx, %rsi
        movq    %rsp, %rdi
        movl    $1024, %edx
        call    memcpy
        call    _Z7ByValue3Big
        addq    $3072, %rsp
        popq    %rbx
        ret
-------------------

I'm far from an export, but it sure looks to me like memcpy is being called
twice to copy the data!
This is supported by the fact that gcc3.3.2 only emits code to copy it once,
and that code runs twice as fast.

Also, gcc3.3.2 inlines the memcpy, while gcc4.0.3 does not.  I assume that's a
regression as well?
If not, what's the best option to tell gcc4.0.3 to inline the copy?


-- 
           Summary: gcc4.0.3 produces code that copies a structure twice
           Product: gcc
           Version: 4.0.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: deb at pixar dot com


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



More information about the Gcc-bugs mailing list