http://llvm.org/bugs/show_bug.cgi?id=12686

             Bug #: 12686
           Summary: useless memcpy when returning struct into local
                    variable
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]
    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();       /**/
    g(&b);
}

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
code.

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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to