[llvm-dev] Clang generating unnecessary spills(?) when passing a struct argument by value

Riyaz Puthiyapurayil via llvm-dev llvm-dev at lists.llvm.org
Sun Jul 19 19:46:52 PDT 2020


// Test case:
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);
}

// Generated code (Clang -O3) - trunk, 10.0.0 (https://godbolt.org/):
boo:                                    # @boo
        subq    $56, %rsp
        movq    blah+16(%rip), %rax
        movq    %rax, 48(%rsp)
        movups  blah(%rip), %xmm0
        movaps  %xmm0, 32(%rsp)
        movq    48(%rsp), %rax
        movq    %rax, 16(%rsp)
        movaps  32(%rsp), %xmm0
        movups  %xmm0, (%rsp)
        callq   foo
        addq    $56, %rsp
        retq

// Generated code (gcc -O3) - 7.3.0 (https://godbolt.org/):
boo:
        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

Why is clang generating all those instructions (which seem to be just unnecessary spills of the registers: %rax and %xmm0)?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200720/99b64c15/attachment.html>


More information about the llvm-dev mailing list