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

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 4 12:57:21 PST 2024


weiguozhi wrote:

Suppose we haven't protected rbp around the inline asm, then following code should be generated

```
#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
....
        vmovdqa64       zmmword ptr [rsp], zmm0          // clobber rbp
        mov     rax, qword ptr [rsp]
        mov     rsp, rbp                                 // store a garbage value to rsp
        pop     rbp
        ret
```
Because rbp is clobbered by the inline asm, at the end of the function, we still can't restore rsp correctly.

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


More information about the llvm-commits mailing list