[llvm] [Codegen] Spill/Restore FP/BP under option (PR #114791)

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 4 12:07:58 PST 2024


rnk wrote:

It seems like there is a general problem with inline asm blobs accessing stack variables, see this example: https://godbolt.org/z/s16MxPME3

```
#include <immintrin.h>
int f() {
    __m512i aligned{};
    asm volatile ("vmovdqa64 %%zmm0, %0" : "=m"(aligned) : "m"(aligned) : "rbp");
    return aligned[0];
}
---->
f():
        push    rbp
        mov     rbp, rsp
        and     rsp, -64
        sub     rsp, 128
....
        push    rbp
        push    rax
        vmovdqa64       zmmword ptr [rsp], zmm0
        add     rsp, 8
        pop     rbp
        mov     rax, qword ptr [rsp]
        mov     rsp, rbp
        pop     rbp
        ret
```

`[rsp]` here looks like it will be misaligned (16 bytes instead of 64), and it will overwrite RBP because we haven't adjusted the memory operands to account for the disturbance to RSP.

That seems like a pretty big design flaw that could break more code than it fixes.

https://github.com/llvm/llvm-project/pull/114791


More information about the llvm-commits mailing list