[llvm] [RISCV] Add preserve_none calling convention support (PR #223920)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 23:11:34 PDT 2026


https://github.com/vincent-163 created https://github.com/llvm/llvm-project/pull/223920

### Summary

`preserve_none` is implemented for x86-64, AArch64 and LoongArch.  This
implements it for RISC-V: arguments and return values are assigned to every GPR
that is neither hardwired nor required by the ABI, that is `x5`-`x7`, `x9`,
`x10`-`x31` in that order.

Current behaviour:

```console
$ llc -mtriple=riscv64 -mattr=+d preserve_nonecc.ll -o -
LLVM ERROR: Unsupported calling convention
```

### Details

* Non-volatile registers are assigned first, so that a function can call a
  regular function without having to save and reload its arguments: everything
  after `x5` in the assignment order is caller-saved in the standard convention.
* No GPR is preserved by a `preserve_none` callee, so `CSR_NoneRegs` only
  contains the return address and the frame pointer, which a function still has
  to save if it uses them, and `getCallPreservedMask()` reports the same set for
  calls to a `preserve_none` function.
* Return values are returned in the argument registers, so a `preserve_none`
  function can return up to 26 values in registers instead of being limited to
  two by the standard convention.  A return value that runs out of registers
  cannot be passed on the stack -- there is no stack return area in this
  convention, and a caller that expects one would not agree with the callee on
  its location -- so such a value fails its register assignment and is returned
  indirectly through a hidden pointer, like an `sret` argument.
* Variadic functions keep the standard argument layout, since the `va_arg`
  implementation relies on it.
* With the `+d` extension floating point values keep the standard FP argument
  and return registers.

### Testing

* New test `llvm/test/CodeGen/RISCV/preserve_nonecc.ll` covers the register
  assignment order, the callee-saved set, calls to and from `preserve_none`
  functions, indirect returns and variadic functions.
* Full `llvm/test/CodeGen/RISCV` suite passes (847 + 1829 tests, 0 failures).


>From 4ff316478062ec972ce0f368b2c505c9c450fd4c Mon Sep 17 00:00:00 2001
From: vincent163 <vincent.163 at outlook.com>
Date: Wed, 16 Sep 2026 13:05:59 +0800
Subject: [PATCH] [RISCV] Add preserve_none calling convention support

preserve_none is currently implemented for x86-64, AArch64 and LoongArch.
Implement it for RISC-V: arguments and return values are assigned to every
GPR that is neither hardwired nor required by the ABI, that is x9, x18-x27,
x10-x17, x6, x7, x28-x31 and x5, in that order.

Non-volatile registers are assigned first so that a function can call a
regular function without having to save and reload its arguments: everything
after x5 in the list is caller-saved in the standard convention.

No GPR is preserved by a preserve_none callee, so CSR_NoneRegs only contains
the return address and the frame pointer, which a function still has to save
if it uses them, and getCallPreservedMask() reports the same set for calls
to a preserve_none function.

Return values are returned in the argument registers, so a preserve_none
function can return up to 26 values in registers instead of being limited to
two by the standard convention. A return value that runs out of registers
cannot be passed on the stack -- there is no stack return area in this
convention, and a caller that expects one would not agree with the callee on
its location -- so such a value fails its register assignment and is returned
indirectly through a hidden pointer, like an sret argument.

Variadic functions keep the standard argument layout, since the va_arg
implementation relies on it.
---
 llvm/docs/LangRef.md                        |   3 +-
 llvm/lib/Target/RISCV/RISCVCallingConv.cpp  |  67 +++-
 llvm/lib/Target/RISCV/RISCVCallingConv.td   |   5 +
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp |   1 +
 llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp |   4 +
 llvm/test/CodeGen/RISCV/preserve_nonecc.ll  | 340 ++++++++++++++++++++
 6 files changed, 414 insertions(+), 6 deletions(-)
 create mode 100644 llvm/test/CodeGen/RISCV/preserve_nonecc.ll

diff --git a/llvm/docs/LangRef.md b/llvm/docs/LangRef.md
index 68ca8b99ede85..90dd0ac5c09b4 100644
--- a/llvm/docs/LangRef.md
+++ b/llvm/docs/LangRef.md
@@ -472,7 +472,8 @@ added in the future:
     registers to pass arguments. This attribute doesn't impact non-general
     purpose registers (e.g., floating point registers, on X86 XMMs/YMMs).
     Non-general purpose registers still follow the standard C calling
-    convention. Currently it is for x86_64, AArch64 and LoongArch only.
+    convention. Currently it is for x86_64, AArch64, LoongArch and RISC-V
+    only.
 
 "`cxx_fast_tlscc`" - The `CXX_FAST_TLS` calling convention for access functions
 :   Clang generates an access function to access C++-style Thread Local Storage
diff --git a/llvm/lib/Target/RISCV/RISCVCallingConv.cpp b/llvm/lib/Target/RISCV/RISCVCallingConv.cpp
index b21adaddb4934..351b1aa785380 100644
--- a/llvm/lib/Target/RISCV/RISCVCallingConv.cpp
+++ b/llvm/lib/Target/RISCV/RISCVCallingConv.cpp
@@ -245,6 +245,52 @@ static ArrayRef<MCPhysReg> getArgGPR32s(const RISCVABI::ABI ABI) {
   return ArrayRef(ArgIGPRs);
 }
 
+// Arguments and return values of a preserve_none function may be assigned to
+// any GPR except:
+// - X0, the hardwired zero,
+// - X1, the return address,
+// - X2, the stack pointer,
+// - X3, the global pointer,
+// - X4, the thread pointer,
+// - X8, the frame pointer.
+//
+// No GPR is preserved by a preserve_none callee (see CSR_NoneRegs in
+// RISCVCallingConv.td), so all of them are caller-saved. Variadic functions
+// are passed using the standard convention instead (see
+// getAllocatableArgGPRs): the va_start/va_arg implementation assumes the
+// standard argument register layout.
+//
+// Non-volatile registers are used first, so that a function may call normal
+// functions without having to save and reload its arguments. The registers are
+// listed in the order in which they are assigned; X5 is assigned last as it is
+// the first choice for a scratch register in the frame lowering.
+static const MCPhysReg PreserveNoneArgGPRs[] = {
+    RISCV::X9,  RISCV::X18, RISCV::X19, RISCV::X20, RISCV::X21, RISCV::X22,
+    RISCV::X23, RISCV::X24, RISCV::X25, RISCV::X26, RISCV::X27, RISCV::X10,
+    RISCV::X11, RISCV::X12, RISCV::X13, RISCV::X14, RISCV::X15, RISCV::X16,
+    RISCV::X17, RISCV::X6,  RISCV::X7,  RISCV::X28, RISCV::X29, RISCV::X30,
+    RISCV::X31, RISCV::X5};
+
+/// Return the GPRs that may be used for arguments (and return values) in the
+/// current calling convention.
+static ArrayRef<MCPhysReg> getAllocatableArgGPRs(CCState &State,
+                                                 const RISCVSubtarget &STI) {
+  if (State.getCallingConv() == CallingConv::PreserveNone &&
+      !State.isVarArg())
+    return ArrayRef(PreserveNoneArgGPRs);
+  return RISCV::getArgGPRs(STI);
+}
+
+/// Return true if a preserve_none return value that ran out of registers has to
+/// fail its assignment instead of being passed on the stack.  The standard
+/// calling conventions reserve a stack area for return values, but there is no
+/// such area for preserve_none: a value that does not fit in a register must be
+/// returned indirectly instead, and the caller is responsible for passing the
+/// return slot (sret).
+static bool cannotReturnOnStack(CCState &State, bool IsRet) {
+  return IsRet && State.getCallingConv() == CallingConv::PreserveNone;
+}
+
 static ArrayRef<MCPhysReg> getFastCCArgGPRs(const RISCVABI::ABI ABI) {
   // The GPRs used for passing arguments in the FastCC, X5 and X6 might be used
   // for save-restore libcall, so we don't use them.
@@ -309,19 +355,22 @@ static bool CC_RISCVAssign2XLen(CCState &State, CCValAssign VA1,
                                 ISD::ArgFlagsTy ArgFlags1, unsigned ValNo2,
                                 MVT ValVT2, MVT LocVT2,
                                 ISD::ArgFlagsTy ArgFlags2,
-                                const RISCVSubtarget &Subtarget) {
+                                const RISCVSubtarget &Subtarget, bool IsRet) {
   unsigned XLen = Subtarget.getXLen();
   unsigned XLenInBytes = XLen / 8;
   RISCVABI::ABI ABI = Subtarget.getTargetABI();
   bool EABI = ABI == RISCVABI::ABI_ILP32E || ABI == RISCVABI::ABI_LP64E;
 
-  ArrayRef<MCPhysReg> ArgGPRs = RISCV::getArgGPRs(Subtarget);
+  ArrayRef<MCPhysReg> ArgGPRs = getAllocatableArgGPRs(State, Subtarget);
 
   if (MCRegister Reg = State.AllocateReg(ArgGPRs)) {
     // At least one half can be passed via register.
     State.addLoc(CCValAssign::getReg(VA1.getValNo(), VA1.getValVT(), Reg,
                                      VA1.getLocVT(), CCValAssign::Full));
   } else {
+    if (cannotReturnOnStack(State, IsRet))
+      return true;
+
     // Both halves must be passed on the stack, with proper alignment.
     // TODO: To be compatible with GCC's behaviors, we force them to have 4-byte
     // alignment. This behavior may be changed when RV32E/ILP32E is ratified.
@@ -435,8 +484,10 @@ static bool CC_RISCV_Impl(unsigned ValNo, MVT ValVT, MVT LocVT,
 
   // Any return value split in to more than two values can't be returned
   // directly. Vectors are returned via the available vector registers.
+  // preserve_none is the exception: each resulting value is returned in its
+  // own register.
   if ((!LocVT.isVector() || Subtarget.isPExtPackedType(LocVT)) && IsRet &&
-      ValNo > 1)
+      ValNo > 1 && State.getCallingConv() != CallingConv::PreserveNone)
     return true;
 
   // Double wide packed types require 2 GPRs so we can only return 1 of them.
@@ -503,7 +554,7 @@ static bool CC_RISCV_Impl(unsigned ValNo, MVT ValVT, MVT LocVT,
     }
   }
 
-  ArrayRef<MCPhysReg> ArgGPRs = RISCV::getArgGPRs(Subtarget);
+  ArrayRef<MCPhysReg> ArgGPRs = getAllocatableArgGPRs(State, Subtarget);
 
   // Zdinx use GPR without a bitcast when possible.
   if (LocVT == MVT::f64 && XLen == 64 && Subtarget.hasStdExtZdinx()) {
@@ -606,7 +657,7 @@ static bool CC_RISCV_Impl(unsigned ValNo, MVT ValVT, MVT LocVT,
     PendingLocs.clear();
     PendingArgFlags.clear();
     return CC_RISCVAssign2XLen(State, VA, AF, ValNo, ValVT, LocVT, ArgFlags,
-                               Subtarget);
+                               Subtarget, IsRet);
   }
 
   // Split arguments might be passed indirectly, so keep track of the pending
@@ -674,6 +725,9 @@ static bool CC_RISCV_Impl(unsigned ValNo, MVT ValVT, MVT LocVT,
     assert(ArgFlags.isSplitEnd() && "Expected ArgFlags.isSplitEnd()");
     assert(PendingLocs.size() > 1 && "Unexpected PendingLocs.size()");
 
+    if (!Reg && cannotReturnOnStack(State, IsRet))
+      return true;
+
     for (auto &It : PendingLocs) {
       if (Reg)
         State.addLoc(CCValAssign::getReg(It.getValNo(), It.getValVT(), Reg,
@@ -699,6 +753,9 @@ static bool CC_RISCV_Impl(unsigned ValNo, MVT ValVT, MVT LocVT,
     return false;
   }
 
+  if (cannotReturnOnStack(State, IsRet))
+    return true;
+
   State.addLoc(CCValAssign::getMem(ValNo, ValVT, StackOffset, LocVT, LocInfo));
   return false;
 }
diff --git a/llvm/lib/Target/RISCV/RISCVCallingConv.td b/llvm/lib/Target/RISCV/RISCVCallingConv.td
index da6b95da12160..757802e66db80 100644
--- a/llvm/lib/Target/RISCV/RISCVCallingConv.td
+++ b/llvm/lib/Target/RISCV/RISCVCallingConv.td
@@ -42,6 +42,11 @@ def CSR_ILP32D_LP64D_V
 // Needed for implementation of RISCVRegisterInfo::getNoPreservedMask()
 def CSR_NoRegs : CalleeSavedRegs<(add)>;
 
+// preserve_none does not preserve any general purpose register, but the return
+// address and the frame pointer must still be saved by functions that clobber
+// them, just as in the standard calling conventions.
+def CSR_NoneRegs : CalleeSavedRegs<(add X1, X8)>;
+
 def CSR_IPRA : CalleeSavedRegs<(add X1)>;
 
 // Interrupt handler needs to save/restore all registers that are used,
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index d05e1f85afb69..62220c936ec86 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -27320,6 +27320,7 @@ SDValue RISCVTargetLowering::LowerFormalArguments(
     reportFatalUsageError("Unsupported calling convention");
   case CallingConv::C:
   case CallingConv::Fast:
+  case CallingConv::PreserveNone:
   case CallingConv::PreserveMost:
   case CallingConv::GRAAL:
   case CallingConv::RISCV_VectorCall:
diff --git a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
index adc6eadee2e35..1c11becc04798 100644
--- a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
@@ -68,6 +68,8 @@ RISCVRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
   auto &Subtarget = MF->getSubtarget<RISCVSubtarget>();
   if (MF->getFunction().getCallingConv() == CallingConv::GHC)
     return CSR_NoRegs_SaveList;
+  if (MF->getFunction().getCallingConv() == CallingConv::PreserveNone)
+    return CSR_NoneRegs_SaveList;
   if (MF->getFunction().getCallingConv() == CallingConv::PreserveMost)
     return Subtarget.hasStdExtE() ? CSR_RT_MostRegs_RVE_SaveList
                                   : CSR_RT_MostRegs_SaveList;
@@ -907,6 +909,8 @@ RISCVRegisterInfo::getCallPreservedMask(const MachineFunction & MF,
 
   if (CC == CallingConv::GHC)
     return CSR_NoRegs_RegMask;
+  if (CC == CallingConv::PreserveNone)
+    return CSR_NoneRegs_RegMask;
   RISCVABI::ABI ABI = Subtarget.getTargetABI();
   if (CC == CallingConv::PreserveMost) {
     if (ABI == RISCVABI::ABI_ILP32E || ABI == RISCVABI::ABI_LP64E)
diff --git a/llvm/test/CodeGen/RISCV/preserve_nonecc.ll b/llvm/test/CodeGen/RISCV/preserve_nonecc.ll
new file mode 100644
index 0000000000000..bf1355666fa8f
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/preserve_nonecc.ll
@@ -0,0 +1,340 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv64 -mattr=+d < %s | FileCheck %s
+
+;; Arguments and return values of a preserve_none function are assigned to
+;; x9, x18-x27, x10-x17, x6, x7, x28-x31 and x5, in this order: the 26 GPRs
+;; that are neither hardwired nor reserved for the ABI.  No register is
+;; preserved by a preserve_none callee, so there is no callee-save or
+;; register-restore code in the function itself, and all live registers have to
+;; be saved by the caller.
+
+; The incoming argument registers are already the outgoing return
+; registers: the function compiles to a bare ret.
+define preserve_nonecc {i64, i64, i64, i64} @forward_4(i64 %a0, i64 %a1, i64 %a2, i64 %a3) {
+; CHECK-LABEL: forward_4:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    ret
+  %v0 = insertvalue {i64, i64, i64, i64} poison, i64 %a0, 0
+  %v1 = insertvalue {i64, i64, i64, i64} %v0, i64 %a1, 1
+  %v2 = insertvalue {i64, i64, i64, i64} %v1, i64 %a2, 2
+  %v3 = insertvalue {i64, i64, i64, i64} %v2, i64 %a3, 3
+  ret {i64, i64, i64, i64} %v3
+}
+
+; The 27th argument does not fit in the register pool and is passed on
+; the stack instead.
+define preserve_nonecc i64 @arg_27(i64 %a0, i64 %a1, i64 %a2, i64 %a3, i64 %a4, i64 %a5, i64 %a6, i64 %a7, i64 %a8, i64 %a9, i64 %a10, i64 %a11, i64 %a12, i64 %a13, i64 %a14, i64 %a15, i64 %a16, i64 %a17, i64 %a18, i64 %a19, i64 %a20, i64 %a21, i64 %a22, i64 %a23, i64 %a24, i64 %a25, i64 %a26) {
+; CHECK-LABEL: arg_27:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    ld s1, 0(sp)
+; CHECK-NEXT:    ret
+  ret i64 %a26
+}
+
+; A struct of 26 values is returned in the first 26 registers of the pool,
+; in order, instead of being returned indirectly.
+define preserve_nonecc {i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64} @ret_26() {
+; CHECK-LABEL: ret_26:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    li s1, 1
+; CHECK-NEXT:    li s2, 2
+; CHECK-NEXT:    li s3, 3
+; CHECK-NEXT:    li s4, 4
+; CHECK-NEXT:    li s5, 5
+; CHECK-NEXT:    li s6, 6
+; CHECK-NEXT:    li s7, 7
+; CHECK-NEXT:    li s8, 8
+; CHECK-NEXT:    li s9, 9
+; CHECK-NEXT:    li s10, 10
+; CHECK-NEXT:    li s11, 11
+; CHECK-NEXT:    li a0, 12
+; CHECK-NEXT:    li a1, 13
+; CHECK-NEXT:    li a2, 14
+; CHECK-NEXT:    li a3, 15
+; CHECK-NEXT:    li a4, 16
+; CHECK-NEXT:    li a5, 17
+; CHECK-NEXT:    li a6, 18
+; CHECK-NEXT:    li a7, 19
+; CHECK-NEXT:    li t1, 20
+; CHECK-NEXT:    li t2, 21
+; CHECK-NEXT:    li t3, 22
+; CHECK-NEXT:    li t4, 23
+; CHECK-NEXT:    li t5, 24
+; CHECK-NEXT:    li t6, 25
+; CHECK-NEXT:    li t0, 26
+; CHECK-NEXT:    ret
+  ret {i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64} {i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9, i64 10, i64 11, i64 12, i64 13, i64 14, i64 15, i64 16, i64 17, i64 18, i64 19, i64 20, i64 21, i64 22, i64 23, i64 24, i64 25, i64 26}
+}
+
+; A struct of 2 values is returned in the first 2 registers of the pool,
+; in order, instead of being returned indirectly.
+define preserve_nonecc {i64, i64} @ret_2() {
+; CHECK-LABEL: ret_2:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    li s1, 1
+; CHECK-NEXT:    li s2, 2
+; CHECK-NEXT:    ret
+  ret {i64, i64} {i64 1, i64 2}
+}
+
+; A preserve_none function does not save any register: the inline asm
+; clobbers every register of the pool.
+define preserve_nonecc void @no_callee_saves() {
+; CHECK-LABEL: no_callee_saves:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    #APP
+; CHECK-NEXT:    #NO_APP
+; CHECK-NEXT:    ret
+  call void asm sideeffect "", "~{x5},~{x6},~{x7},~{x9},~{x10},~{x11},~{x12},~{x13},~{x14},~{x15},~{x16},~{x17},~{x18},~{x19},~{x20},~{x21},~{x22},~{x23},~{x24},~{x25},~{x26},~{x27},~{x28},~{x29},~{x30},~{x31}"()
+  ret void
+}
+
+; Conversely, all registers that are live across a preserve_none call have to
+; be saved and restored by the caller.
+declare preserve_nonecc void @callee()
+define void @caller() {
+; CHECK-LABEL: caller:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -224
+; CHECK-NEXT:    .cfi_def_cfa_offset 224
+; CHECK-NEXT:    sd ra, 216(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sd s0, 208(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sd s1, 200(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sd s2, 192(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sd s3, 184(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sd s4, 176(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sd s5, 168(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sd s6, 160(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sd s7, 152(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sd s8, 144(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sd s9, 136(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sd s10, 128(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sd s11, 120(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    fsd fs0, 112(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    fsd fs1, 104(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    fsd fs2, 96(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    fsd fs3, 88(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    fsd fs4, 80(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    fsd fs5, 72(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    fsd fs6, 64(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    fsd fs7, 56(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    fsd fs8, 48(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    fsd fs9, 40(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    fsd fs10, 32(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    fsd fs11, 24(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    .cfi_offset ra, -8
+; CHECK-NEXT:    .cfi_offset s0, -16
+; CHECK-NEXT:    .cfi_offset s1, -24
+; CHECK-NEXT:    .cfi_offset s2, -32
+; CHECK-NEXT:    .cfi_offset s3, -40
+; CHECK-NEXT:    .cfi_offset s4, -48
+; CHECK-NEXT:    .cfi_offset s5, -56
+; CHECK-NEXT:    .cfi_offset s6, -64
+; CHECK-NEXT:    .cfi_offset s7, -72
+; CHECK-NEXT:    .cfi_offset s8, -80
+; CHECK-NEXT:    .cfi_offset s9, -88
+; CHECK-NEXT:    .cfi_offset s10, -96
+; CHECK-NEXT:    .cfi_offset s11, -104
+; CHECK-NEXT:    .cfi_offset fs0, -112
+; CHECK-NEXT:    .cfi_offset fs1, -120
+; CHECK-NEXT:    .cfi_offset fs2, -128
+; CHECK-NEXT:    .cfi_offset fs3, -136
+; CHECK-NEXT:    .cfi_offset fs4, -144
+; CHECK-NEXT:    .cfi_offset fs5, -152
+; CHECK-NEXT:    .cfi_offset fs6, -160
+; CHECK-NEXT:    .cfi_offset fs7, -168
+; CHECK-NEXT:    .cfi_offset fs8, -176
+; CHECK-NEXT:    .cfi_offset fs9, -184
+; CHECK-NEXT:    .cfi_offset fs10, -192
+; CHECK-NEXT:    .cfi_offset fs11, -200
+; CHECK-NEXT:    #APP
+; CHECK-NEXT:    #NO_APP
+; CHECK-NEXT:    sd t0, 16(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    #APP
+; CHECK-NEXT:    #NO_APP
+; CHECK-NEXT:    sd t1, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    #APP
+; CHECK-NEXT:    #NO_APP
+; CHECK-NEXT:    mv s0, t6
+; CHECK-NEXT:    call callee
+; CHECK-NEXT:    ld t0, 16(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld t1, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    mv t6, s0
+; CHECK-NEXT:    #APP
+; CHECK-NEXT:    #NO_APP
+; CHECK-NEXT:    ld ra, 216(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld s0, 208(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld s1, 200(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld s2, 192(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld s3, 184(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld s4, 176(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld s5, 168(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld s6, 160(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld s7, 152(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld s8, 144(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld s9, 136(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld s10, 128(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld s11, 120(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    fld fs0, 112(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    fld fs1, 104(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    fld fs2, 96(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    fld fs3, 88(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    fld fs4, 80(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    fld fs5, 72(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    fld fs6, 64(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    fld fs7, 56(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    fld fs8, 48(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    fld fs9, 40(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    fld fs10, 32(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    fld fs11, 24(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    .cfi_restore ra
+; CHECK-NEXT:    .cfi_restore s0
+; CHECK-NEXT:    .cfi_restore s1
+; CHECK-NEXT:    .cfi_restore s2
+; CHECK-NEXT:    .cfi_restore s3
+; CHECK-NEXT:    .cfi_restore s4
+; CHECK-NEXT:    .cfi_restore s5
+; CHECK-NEXT:    .cfi_restore s6
+; CHECK-NEXT:    .cfi_restore s7
+; CHECK-NEXT:    .cfi_restore s8
+; CHECK-NEXT:    .cfi_restore s9
+; CHECK-NEXT:    .cfi_restore s10
+; CHECK-NEXT:    .cfi_restore s11
+; CHECK-NEXT:    .cfi_restore fs0
+; CHECK-NEXT:    .cfi_restore fs1
+; CHECK-NEXT:    .cfi_restore fs2
+; CHECK-NEXT:    .cfi_restore fs3
+; CHECK-NEXT:    .cfi_restore fs4
+; CHECK-NEXT:    .cfi_restore fs5
+; CHECK-NEXT:    .cfi_restore fs6
+; CHECK-NEXT:    .cfi_restore fs7
+; CHECK-NEXT:    .cfi_restore fs8
+; CHECK-NEXT:    .cfi_restore fs9
+; CHECK-NEXT:    .cfi_restore fs10
+; CHECK-NEXT:    .cfi_restore fs11
+; CHECK-NEXT:    addi sp, sp, 224
+; CHECK-NEXT:    .cfi_def_cfa_offset 0
+; CHECK-NEXT:    ret
+  %a0 = call i64 asm sideeffect "", "={x5}"()
+  %a1 = call i64 asm sideeffect "", "={x6}"()
+  %a2 = call i64 asm sideeffect "", "={x31}"()
+  call preserve_nonecc void @callee()
+  call void asm sideeffect "", "{x5},{x6},{x31}"(i64 %a0, i64 %a1, i64 %a2)
+  ret void
+}
+
+; Variadic functions are passed using the standard calling convention, since
+; va_start/va_arg assume the standard argument register layout.
+define preserve_nonecc i64 @varargs(i64 %a0, i64 %a1, ...) {
+; CHECK-LABEL: varargs:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -48
+; CHECK-NEXT:    .cfi_def_cfa_offset 48
+; CHECK-NEXT:    sd a6, 32(sp)
+; CHECK-NEXT:    sd a7, 40(sp)
+; CHECK-NEXT:    add a0, a0, a1
+; CHECK-NEXT:    sd a2, 0(sp)
+; CHECK-NEXT:    sd a3, 8(sp)
+; CHECK-NEXT:    sd a4, 16(sp)
+; CHECK-NEXT:    sd a5, 24(sp)
+; CHECK-NEXT:    addi sp, sp, 48
+; CHECK-NEXT:    .cfi_def_cfa_offset 0
+; CHECK-NEXT:    ret
+  %r = add i64 %a0, %a1
+  ret i64 %r
+}
+
+
+; A struct of 27 values does not fit in the 26 registers of the pool, so it is
+; returned indirectly: the caller passes a hidden pointer to the return slot in
+; the first register of the pool, and the callee writes through it.  A
+; preserve_none return never uses a return stack area, since the caller cannot
+; know the size of the area the callee would have to use.
+define preserve_nonecc i64 @caller_ret_27(i64 %a) {
+; CHECK-LABEL: caller_ret_27:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    addi sp, sp, -240
+; CHECK-NEXT:    .cfi_def_cfa_offset 240
+; CHECK-NEXT:    sd ra, 232(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    sd s0, 224(sp) # 8-byte Folded Spill
+; CHECK-NEXT:    .cfi_offset ra, -8
+; CHECK-NEXT:    .cfi_offset s0, -16
+; CHECK-NEXT:    mv s0, s1
+; CHECK-NEXT:    addi s1, sp, 8
+; CHECK-NEXT:    call callee_ret_27
+; CHECK-NEXT:    ld s1, 32(sp)
+; CHECK-NEXT:    add s1, s1, s0
+; CHECK-NEXT:    ld ra, 232(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    ld s0, 224(sp) # 8-byte Folded Reload
+; CHECK-NEXT:    .cfi_restore ra
+; CHECK-NEXT:    .cfi_restore s0
+; CHECK-NEXT:    addi sp, sp, 240
+; CHECK-NEXT:    .cfi_def_cfa_offset 0
+; CHECK-NEXT:    ret
+  %r = call preserve_nonecc {i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64} @callee_ret_27()
+  %e = extractvalue {i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64} %r, 3
+  %s = add i64 %e, %a
+  ret i64 %s
+}
+
+define preserve_nonecc {i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64} @callee_ret_27() {
+; CHECK-LABEL: callee_ret_27:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    li a0, 27
+; CHECK-NEXT:    li a1, 25
+; CHECK-NEXT:    li a2, 26
+; CHECK-NEXT:    sd a1, 192(s1)
+; CHECK-NEXT:    sd a2, 200(s1)
+; CHECK-NEXT:    sd a0, 208(s1)
+; CHECK-NEXT:    li a0, 24
+; CHECK-NEXT:    li a1, 23
+; CHECK-NEXT:    li a2, 22
+; CHECK-NEXT:    li a3, 21
+; CHECK-NEXT:    sd a3, 160(s1)
+; CHECK-NEXT:    sd a2, 168(s1)
+; CHECK-NEXT:    sd a1, 176(s1)
+; CHECK-NEXT:    sd a0, 184(s1)
+; CHECK-NEXT:    li a0, 20
+; CHECK-NEXT:    li a1, 19
+; CHECK-NEXT:    li a2, 18
+; CHECK-NEXT:    li a3, 17
+; CHECK-NEXT:    sd a3, 128(s1)
+; CHECK-NEXT:    sd a2, 136(s1)
+; CHECK-NEXT:    sd a1, 144(s1)
+; CHECK-NEXT:    sd a0, 152(s1)
+; CHECK-NEXT:    li a0, 16
+; CHECK-NEXT:    li a1, 15
+; CHECK-NEXT:    li a2, 14
+; CHECK-NEXT:    li a3, 13
+; CHECK-NEXT:    sd a3, 96(s1)
+; CHECK-NEXT:    sd a2, 104(s1)
+; CHECK-NEXT:    sd a1, 112(s1)
+; CHECK-NEXT:    sd a0, 120(s1)
+; CHECK-NEXT:    li a0, 12
+; CHECK-NEXT:    li a1, 11
+; CHECK-NEXT:    li a2, 10
+; CHECK-NEXT:    li a3, 9
+; CHECK-NEXT:    sd a3, 64(s1)
+; CHECK-NEXT:    sd a2, 72(s1)
+; CHECK-NEXT:    sd a1, 80(s1)
+; CHECK-NEXT:    sd a0, 88(s1)
+; CHECK-NEXT:    li a0, 8
+; CHECK-NEXT:    li a1, 7
+; CHECK-NEXT:    li a2, 6
+; CHECK-NEXT:    li a3, 5
+; CHECK-NEXT:    sd a3, 32(s1)
+; CHECK-NEXT:    sd a2, 40(s1)
+; CHECK-NEXT:    sd a1, 48(s1)
+; CHECK-NEXT:    sd a0, 56(s1)
+; CHECK-NEXT:    li a0, 4
+; CHECK-NEXT:    li a1, 3
+; CHECK-NEXT:    li a2, 2
+; CHECK-NEXT:    li a3, 1
+; CHECK-NEXT:    sd a3, 0(s1)
+; CHECK-NEXT:    sd a2, 8(s1)
+; CHECK-NEXT:    sd a1, 16(s1)
+; CHECK-NEXT:    sd a0, 24(s1)
+; CHECK-NEXT:    ret
+  ret {i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64} {i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9, i64 10, i64 11, i64 12, i64 13, i64 14, i64 15, i64 16, i64 17, i64 18, i64 19, i64 20, i64 21, i64 22, i64 23, i64 24, i64 25, i64 26, i64 27}
+}
+



More information about the llvm-commits mailing list