[llvm] [RISCV][WIP] Let RA do the CSR saves. (PR #90819)

Shreeyash Pandey via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 4 03:12:07 PDT 2026


bojle wrote:

Hi @mgudim,

Consider this simple example that contains just the frame record for prologue: https://godbolt.org/z/7o1jEe9s5

Both clang (trunk) and gcc (trunk) (as seen in compiler explorer) sink the prologue and keep the hot path clean. 

When I run this example with this patch, I am seeing that frame record is being nailed at entry:

```
; -target riscv64 -O3 -fno-pic -mllvm --riscv-enable-save-csr-in-ra
f3():
        addi    sp, sp, -16 ; this is sunk in trunk
        lui     a0, %hi(cond)
        ld      a0, %lo(cond)(a0)
        sd      s1, 8(sp)
        mv      s1, ra
        beqz    a0, .LBB2_2
        call    ext()
.LBB2_2:
        li      a0, 42
        mv      ra, s1
        ld      s1, 8(sp)
        addi    sp, sp, 16
        ret
```
Similar behavior on aarch64 (I've ported this patch locally). This could certainly lead to regressions.


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


More information about the llvm-commits mailing list