[llvm-bugs] [Bug 46798] New: Unnecessary spills when passing a struct argument by value

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jul 21 16:24:06 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46798

            Bug ID: 46798
           Summary: Unnecessary spills when passing a struct argument by
                    value
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: riyaz at synopsys.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at rotateright.com

Created attachment 23763
  --> https://bugs.llvm.org/attachment.cgi?id=23763&action=edit
C test case to reproduce the problem

Clang generates unnecessary spills of %xmm0 and %rax for the attached test
case. See below (and attached test) for details. 

The issue goes away if an __attribute__((align(8)) is added to the variable
blah.

// Test case:
// compile: clang -O3 -S -emit-llvm -o test.s test.c 

typedef struct { int a; int b; int c; int d; int e; int f; } T;
extern int foo(T a);

extern T blah;

int boo() {
    return foo(blah);
}

Code generated by gcc:

        subq    $40, %rsp
        movq    blah+16(%rip), %rax
        movdqu  blah(%rip), %xmm0
        movq    %rax, 16(%rsp)
        movups  %xmm0, (%rsp)
        call    foo
        addq    $40, %rsp
        ret

Code generated by "clang -O3"

        subq    $56, %rsp
        movq    blah+16(%rip), %rax
        movq    %rax, 48(%rsp)      ; unnecessary
        movups  blah(%rip), %xmm0
        movaps  %xmm0, 32(%rsp)     ; unnecessary
        movq    48(%rsp), %rax      ; unnecessary
        movq    %rax, 16(%rsp)
        movaps  32(%rsp), %xmm0     ; unnecessary
        movups  %xmm0, (%rsp)
        callq   foo
        addq    $56, %rsp
        retq

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200721/ab207996/attachment.html>


More information about the llvm-bugs mailing list