[llvm] [RISCV] Preserve call-preserved reg mask for LPAD-aligned calls (PR #210868)

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 20 23:15:32 PDT 2026


================
@@ -0,0 +1,31 @@
+; RUN: llc -mtriple=riscv32 -stop-after=finalize-isel < %s | FileCheck %s
+; RUN: llc -mtriple=riscv64 -stop-after=finalize-isel < %s | FileCheck %s
+
+; PseudoCALLLpadAlign/PseudoCALLIndirectLpadAlign must carry the same
+; call-preserved register mask as PseudoCALL/PseudoCALLIndirect, otherwise
+; values live across a returns_twice call are not spilled/reloaded and get
+; corrupted when the callee clobbers them.
+
+declare i32 @setjmp(ptr) returns_twice
+declare void @use(ptr, ptr)
+
+define void @test_direct_call_preserved_mask(ptr %buf) {
+  ; CHECK-LABEL: name: test_direct_call_preserved_mask
+  ; CHECK: PseudoCALLLpadAlign target-flags(riscv-call) @setjmp, 0, csr_ilp32{{d?}}_lp64{{d?}}, implicit-def dead $x1, implicit $x10, implicit-def $x2, implicit-def $x10
----------------
lenary wrote:

Why is `csr_ilp32{{d?}}_lp64{{d?}}` a regex rather than a literal string?

It might be better to rewrite this test with two sets of check lines, one for rv32 and one for rv64, with appropriate ABIs specified.

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


More information about the llvm-commits mailing list