[LLVMbugs] [Bug 12686] New: useless memcpy when returning struct into local variable

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Apr 27 12:20:14 PDT 2012


             Bug #: 12686
           Summary: useless memcpy when returning struct into local
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: mattiase at acm.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Returning a struct directly into a local variable generates poor code. The
following C code generates a call to memcpy on x86-64:

struct big { int a[50]; };
struct big f(void);
void g(struct big *p};
void h(void) {
    struct big b;  /**/
    b = f();       /**/

The memcpy _is_ optimised away if the local variable is initialised by
replacing the two marked lines with:

    struct big b = f();

This also makes the stack frame smaller, since there is no need for a separate
return buffer. I see no reason why the two versions should not yield identical

clang version 3.1 (trunk 154679)
Target: x86_64-unknown-linux-gnu

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list