[llvm] [RISCV] Modify RegMask Settings of Scalar Library Functions to Reduce Spills (PR #163311)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 15 08:47:17 PDT 2025


topperc wrote:

> According to [the RISC-V ELF psABI documentation](https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#vector-register-convention):
> 
> > the contents of all callee-saved registers must be restored to what was set on entry,
> > It must ensure that the entire contents of v1–v7 and v24–v31 are preserved across the call,
> > Functions that use vector registers to pass arguments and return values must follow this calling convention.
> 
> In other words, library functions **must strictly follow the calling convention**, saving and restoring all **callee-saved registers**.
> 
> This behavior is defined by the **ISA**, and is **independent of any specific compiler or version** :)
> 
> > What if the library code is compiled with gcc? Or an older version of clang/gcc that doesn't have this patch?

The rules you are quoting are for the vector register calling convention variant. This is for function that have vector arguments/returns or are declare with the `riscv_vector_cc` attribute. This does not apply to scalar library functions.

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


More information about the llvm-commits mailing list