[clang] [llvm] [RISCV] Add Codegen support for ACLIC (PR #238325)
Zeyi Xu via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 8 20:25:08 PST 2026
https://github.com/zeyi2 updated https://github.com/llvm/llvm-project/pull/238325
>From 2198ba043f734ee9a85fa12e528b976ae270553a Mon Sep 17 00:00:00 2001
From: Zeyi Xu <mitchell.xu2 at gmail.com>
Date: Tue, 3 Nov 2026 21:18:57 +0800
Subject: [PATCH 1/3] [RISCV] Add Codegen support for ACLIC
---
clang/docs/ReleaseNotes.md | 3 +
clang/include/clang/Basic/Attr.td | 4 +
clang/include/clang/Basic/AttrDocs.td | 14 +-
clang/lib/CodeGen/Targets/RISCV.cpp | 14 +-
clang/lib/Sema/SemaRISCV.cpp | 52 +-
clang/test/Sema/riscv-interrupt-attr-aclic.c | 43 +
llvm/lib/Target/RISCV/RISCVCallingConv.td | 55 +
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 191 ++-
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 32 +-
llvm/lib/Target/RISCV/RISCVInstrInfo.td | 4 +
llvm/lib/Target/RISCV/RISCVInstrInfoSmip.td | 30 +-
.../Target/RISCV/RISCVMachineFunctionInfo.cpp | 14 +
.../Target/RISCV/RISCVMachineFunctionInfo.h | 51 +-
llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp | 45 +-
.../RISCV/aclic-interrupt-attr-error.ll | 35 +
.../CodeGen/RISCV/aclic-interrupt-attr.ll | 1265 +++++++++++++++++
.../RISCV/aclic-interrupt-frame-pointer.ll | 264 ++++
17 files changed, 2046 insertions(+), 70 deletions(-)
create mode 100644 clang/test/Sema/riscv-interrupt-attr-aclic.c
create mode 100644 llvm/test/CodeGen/RISCV/aclic-interrupt-attr-error.ll
create mode 100644 llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
create mode 100644 llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 743c1ead8ec789..75b6218657a20d 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1330,6 +1330,9 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and
#### RISC-V Support
+- Added CodeGen support for the ACLIC v0.20 `preemptible` and `push-pop`
+ interrupt attribute kinds.
+
- Fixed a bug where the `interrupt` attribute did not accept `machine` together
with both `SiFive-CLIC-preemptible` and `SiFive-CLIC-stack-swap`.
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 5de5059cc18c0e..9e9e4edfd6165e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2485,6 +2485,8 @@ def RISCVInterrupt : InheritableAttr, TargetSpecificAttr<TargetRISCV> {
"qci-nonest",
"SiFive-CLIC-preemptible",
"SiFive-CLIC-stack-swap",
+ "preemptible",
+ "push-pop",
],
[
"supervisor",
@@ -2494,6 +2496,8 @@ def RISCVInterrupt : InheritableAttr, TargetSpecificAttr<TargetRISCV> {
"qcinonest",
"SiFiveCLICPreemptible",
"SiFiveCLICStackSwap",
+ "preemptible",
+ "pushpop",
]>];
let ParseKind = "Interrupt";
let Documentation = [RISCVInterruptDocs];
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 687e022c7bd61f..93c09420a5bf62 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3291,8 +3291,8 @@ used directly as an interrupt service routine.
Permissible values for this parameter are `machine`, `supervisor`,
`rnmi`, `qci-nest`, `qci-nonest`, `SiFive-CLIC-preemptible`, and
-`SiFive-CLIC-stack-swap`. If there is no parameter, then it defaults to
-`machine`.
+`SiFive-CLIC-stack-swap`, `preemptible`, and `push-pop`. If there is no
+parameter, then it defaults to `machine`.
The `rnmi` value is used for resumable non-maskable interrupts. It requires the
standard Smrnmi extension.
@@ -3314,6 +3314,15 @@ swapped with `mscratch` before its first use and after its last use.
The SiFive CLIC values may be combined with each other and with the `machine`
attribute value. Any other combination of different values is not allowed.
+The `preemptible` and `push-pop` values are used with the ACLIC fast Interrupt
+extensions. The `preemptible` value requires `Smnip` for machine-mode
+interrupts or `Ssnip` for supervisor-mode interrupts. It saves the interrupt
+status and exception PC before re-enabling interrupts. The `push-pop` value
+requires `Smip` for machine-mode interrupts or `Ssip` for supervisor-mode
+interrupts. It assumes that `a0`-`a5` were saved by the interrupt trap and
+returns with `mipopret` or `sipopret`. These values may be combined with each
+other and with either `machine` or `supervisor`.
+
Repeated interrupt attribute on the same declaration will cause a warning
to be emitted. In case of repeated declarations, the last one prevails.
@@ -3322,6 +3331,7 @@ References:
- [The RISC-V Instruction Set Manual Volume II: Privileged Architecture Version 1.10](https://docs.riscv.org/reference/isa/v1.10/_attachments/riscv-privileged.pdf)
- [Xqci extension v0.13](https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.13.0)
- [SiFive Interrupt Cookbook Version 1.2](https://sifive.cdn.prismic.io/sifive/d1984d2b-c9b9-4c91-8de0-d68a5e64fa0f_sifive-interrupt-cookbook-v1p2.pdf)
+- [RISC-V Fast Interrupt v0.20](https://github.com/riscv/riscv-fast-interrupt/releases/tag/v0.20)
}];
}
diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp
index 4bac5711a2dd66..8902c34057259e 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -1115,9 +1115,11 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
if (!Attr)
return;
- StringRef Kind = "machine";
+ std::string Kind = "machine";
bool HasSiFiveCLICPreemptible = false;
bool HasSiFiveCLICStackSwap = false;
+ bool HasPreemptible = false;
+ bool HasPushPop = false;
for (RISCVInterruptAttr::InterruptType type : Attr->interrupt()) {
switch (type) {
case RISCVInterruptAttr::machine:
@@ -1150,9 +1152,19 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
: "SiFive-CLIC-stack-swap";
break;
}
+ case RISCVInterruptAttr::preemptible:
+ HasPreemptible = true;
+ break;
+ case RISCVInterruptAttr::pushpop:
+ HasPushPop = true;
+ break;
}
}
+ if (HasPreemptible)
+ Kind += "-preemptible";
+ if (HasPushPop)
+ Kind += "-push-pop";
Fn->addFnAttr("interrupt", Kind);
}
};
diff --git a/clang/lib/Sema/SemaRISCV.cpp b/clang/lib/Sema/SemaRISCV.cpp
index a1ba3b3934daa6..0213d9f78fc61e 100644
--- a/clang/lib/Sema/SemaRISCV.cpp
+++ b/clang/lib/Sema/SemaRISCV.cpp
@@ -1680,7 +1680,11 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
if (!AL.checkAtMostNumArgs(SemaRef, 3))
return;
+ bool HasMachine = false;
+ bool HasSupervisor = false;
bool HasSiFiveCLICType = false;
+ bool HasPreemptible = false;
+ bool HasPushPop = false;
bool HasUnaryType = false;
bool ReportedDuplicateType = false;
@@ -1702,20 +1706,28 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
switch (Type) {
case RISCVInterruptAttr::machine:
- // "machine" could be combined with the SiFive CLIC types, or could be
- // just "machine".
+ // "machine" can be used alone, with SiFive CLIC types, or with ACLIC
+ // modifiers.
+ HasMachine = true;
+ break;
+ case RISCVInterruptAttr::supervisor:
+ HasSupervisor = true;
break;
case RISCVInterruptAttr::SiFiveCLICPreemptible:
case RISCVInterruptAttr::SiFiveCLICStackSwap:
// SiFive-CLIC types can be combined with each other and "machine"
HasSiFiveCLICType = true;
break;
- case RISCVInterruptAttr::supervisor:
+ case RISCVInterruptAttr::preemptible:
+ HasPreemptible = true;
+ break;
+ case RISCVInterruptAttr::pushpop:
+ HasPushPop = true;
+ break;
case RISCVInterruptAttr::rnmi:
case RISCVInterruptAttr::qcinest:
case RISCVInterruptAttr::qcinonest:
- // "supervisor", "rnmi" and "qci-(no)nest" cannot be combined with any
- // other types
+ // "rnmi" and "qci-(no)nest" cannot be combined with any other types.
HasUnaryType = true;
break;
}
@@ -1737,6 +1749,16 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
return;
}
+ if (HasMachine && HasSupervisor) {
+ Diag(AL.getLoc(), diag::err_riscv_attribute_interrupt_invalid_combination);
+ return;
+ }
+
+ if (HasSiFiveCLICType && (HasSupervisor || HasPreemptible || HasPushPop)) {
+ Diag(AL.getLoc(), diag::err_riscv_attribute_interrupt_invalid_combination);
+ return;
+ }
+
// "machine" is the default, if nothing is specified.
if (AL.getNumArgs() == 0)
Types.insert(RISCVInterruptAttr::machine);
@@ -1781,6 +1803,26 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
return;
}
} break;
+ case RISCVInterruptAttr::preemptible: {
+ if (!HasFeature(HasSupervisor ? "experimental-ssnip"
+ : "experimental-smnip")) {
+ Diag(AL.getLoc(),
+ diag::err_riscv_attribute_interrupt_requires_extension)
+ << RISCVInterruptAttr::ConvertInterruptTypeToStr(Type)
+ << (HasSupervisor ? "Ssnip" : "Smnip");
+ return;
+ }
+ } break;
+ case RISCVInterruptAttr::pushpop: {
+ if (!HasFeature(HasSupervisor ? "experimental-ssip"
+ : "experimental-smip")) {
+ Diag(AL.getLoc(),
+ diag::err_riscv_attribute_interrupt_requires_extension)
+ << RISCVInterruptAttr::ConvertInterruptTypeToStr(Type)
+ << (HasSupervisor ? "Ssip" : "Smip");
+ return;
+ }
+ } break;
default:
break;
}
diff --git a/clang/test/Sema/riscv-interrupt-attr-aclic.c b/clang/test/Sema/riscv-interrupt-attr-aclic.c
new file mode 100644
index 00000000000000..1a1b3edadc6e31
--- /dev/null
+++ b/clang/test/Sema/riscv-interrupt-attr-aclic.c
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple riscv64-unknown-elf \
+// RUN: -target-feature +experimental-smnip \
+// RUN: -target-feature +experimental-ssnip \
+// RUN: -target-feature +experimental-smip \
+// RUN: -target-feature +experimental-ssip -emit-llvm -DCHECK_IR %s -o - \
+// RUN: | FileCheck %s
+// RUN: %clang_cc1 -triple riscv64-unknown-elf \
+// RUN: -target-feature +experimental-smnip \
+// RUN: -target-feature +experimental-ssnip \
+// RUN: -target-feature +experimental-smip \
+// RUN: -target-feature +experimental-ssip -verify=enabled,both \
+// RUN: -fsyntax-only %s
+// RUN: %clang_cc1 -triple riscv64-unknown-elf -verify=disabled,both \
+// RUN: -fsyntax-only %s
+
+#ifdef CHECK_IR
+__attribute__((interrupt("preemptible"))) void m_preemptible(void) {}
+__attribute__((interrupt("supervisor", "preemptible")))
+void s_preemptible(void) {}
+__attribute__((interrupt("push-pop"))) void m_push_pop(void) {}
+__attribute__((interrupt("supervisor", "push-pop"))) void s_push_pop(void) {}
+__attribute__((interrupt("machine", "preemptible", "push-pop")))
+void m_combined(void) {}
+__attribute__((interrupt("push-pop", "supervisor", "preemptible")))
+void s_combined(void) {}
+
+// CHECK: attributes #0 = {{.*}}"interrupt"="machine-preemptible"
+// CHECK: attributes #1 = {{.*}}"interrupt"="supervisor-preemptible"
+// CHECK: attributes #2 = {{.*}}"interrupt"="machine-push-pop"
+// CHECK: attributes #3 = {{.*}}"interrupt"="supervisor-push-pop"
+// CHECK: attributes #4 = {{.*}}"interrupt"="machine-preemptible-push-pop"
+// CHECK: attributes #5 = {{.*}}"interrupt"="supervisor-preemptible-push-pop"
+#else
+__attribute__((interrupt("preemptible"))) void m_preemptible(void) {} // disabled-error {{RISC-V 'interrupt' attribute 'preemptible' requires extension 'Smnip'}}
+__attribute__((interrupt("supervisor", "preemptible"))) void s_preemptible(void) {} // disabled-error {{RISC-V 'interrupt' attribute 'preemptible' requires extension 'Ssnip'}}
+__attribute__((interrupt("push-pop"))) void m_push_pop(void) {} // disabled-error {{RISC-V 'interrupt' attribute 'push-pop' requires extension 'Smip'}}
+__attribute__((interrupt("supervisor", "push-pop"))) void s_push_pop(void) {} // disabled-error {{RISC-V 'interrupt' attribute 'push-pop' requires extension 'Ssip'}}
+
+__attribute__((interrupt("machine", "supervisor", "preemptible"))) void bad_modes(void) {} // both-error {{RISC-V 'interrupt' attribute contains invalid combination of interrupt types}}
+__attribute__((interrupt("preemptible", "SiFive-CLIC-preemptible"))) void bad_sifive(void) {} // both-error {{RISC-V 'interrupt' attribute contains invalid combination of interrupt types}}
+__attribute__((interrupt("push-pop", "rnmi"))) void bad_rnmi(void) {} // both-error {{RISC-V 'interrupt' attribute contains invalid combination of interrupt types}}
+__attribute__((interrupt("preemptible", "qci-nest"))) void bad_qci(void) {} // both-error {{RISC-V 'interrupt' attribute contains invalid combination of interrupt types}}
+#endif
diff --git a/llvm/lib/Target/RISCV/RISCVCallingConv.td b/llvm/lib/Target/RISCV/RISCVCallingConv.td
index a5cf7ab27c4091..ad9ebb554ff077 100644
--- a/llvm/lib/Target/RISCV/RISCVCallingConv.td
+++ b/llvm/lib/Target/RISCV/RISCVCallingConv.td
@@ -96,6 +96,61 @@ def CSR_XLEN_F32_V_Interrupt_RVE: CalleeSavedRegs<(sub CSR_XLEN_F32_V_Interrupt,
def CSR_XLEN_F64_V_Interrupt_RVE: CalleeSavedRegs<(sub CSR_XLEN_F64_V_Interrupt,
(sequence "X%u", 16, 31))>;
+// For Smip/Ssip interrupt handlers, the compiler may assume that X10-X15
+// (a0-a5) have been saved and does not need to restore them.
+def CSR_Interrupt_PushPop
+ : CalleeSavedRegs<(sub CSR_Interrupt, (sequence "X%u", 10, 15))>;
+
+def CSR_XLEN_F32_Interrupt_PushPop
+ : CalleeSavedRegs<(sub CSR_XLEN_F32_Interrupt,
+ (sequence "X%u", 10, 15))>;
+
+def CSR_XLEN_F64_Interrupt_PushPop
+ : CalleeSavedRegs<(sub CSR_XLEN_F64_Interrupt,
+ (sequence "X%u", 10, 15))>;
+
+def CSR_XLEN_V_Interrupt_PushPop
+ : CalleeSavedRegs<(sub CSR_XLEN_V_Interrupt,
+ (sequence "X%u", 10, 15))>;
+
+def CSR_XLEN_F32_V_Interrupt_PushPop
+ : CalleeSavedRegs<(sub CSR_XLEN_F32_V_Interrupt,
+ (sequence "X%u", 10, 15))>;
+
+def CSR_XLEN_F64_V_Interrupt_PushPop
+ : CalleeSavedRegs<(sub CSR_XLEN_F64_V_Interrupt,
+ (sequence "X%u", 10, 15))>;
+
+// Same as CSR_Interrupt_PushPop, but excluding X16-X31.
+def CSR_Interrupt_PushPop_RVE
+ : CalleeSavedRegs<(sub CSR_Interrupt_PushPop,
+ (sequence "X%u", 16, 31))>;
+
+// Same as CSR_XLEN_F32_Interrupt_PushPop, but excluding X16-X31.
+def CSR_XLEN_F32_Interrupt_PushPop_RVE
+ : CalleeSavedRegs<(sub CSR_XLEN_F32_Interrupt_PushPop,
+ (sequence "X%u", 16, 31))>;
+
+// Same as CSR_XLEN_F64_Interrupt_PushPop, but excluding X16-X31.
+def CSR_XLEN_F64_Interrupt_PushPop_RVE
+ : CalleeSavedRegs<(sub CSR_XLEN_F64_Interrupt_PushPop,
+ (sequence "X%u", 16, 31))>;
+
+// Same as CSR_XLEN_V_Interrupt_PushPop, but excluding X16-X31.
+def CSR_XLEN_V_Interrupt_PushPop_RVE
+ : CalleeSavedRegs<(sub CSR_XLEN_V_Interrupt_PushPop,
+ (sequence "X%u", 16, 31))>;
+
+// Same as CSR_XLEN_F32_V_Interrupt_PushPop, but excluding X16-X31.
+def CSR_XLEN_F32_V_Interrupt_PushPop_RVE
+ : CalleeSavedRegs<(sub CSR_XLEN_F32_V_Interrupt_PushPop,
+ (sequence "X%u", 16, 31))>;
+
+// Same as CSR_XLEN_F64_V_Interrupt_PushPop, but excluding X16-X31.
+def CSR_XLEN_F64_V_Interrupt_PushPop_RVE
+ : CalleeSavedRegs<(sub CSR_XLEN_F64_V_Interrupt_PushPop,
+ (sequence "X%u", 16, 31))>;
+
def CSR_RT_MostRegs : CalleeSavedRegs<(sub CSR_Interrupt, X5, X6, X7, X28)>;
def CSR_RT_MostRegs_RVE : CalleeSavedRegs<(sub CSR_RT_MostRegs,
(sequence "X%u", 16, 31))>;
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 89c7eb1338c712..a2e293c3fb500d 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -74,6 +74,15 @@ static const MCPhysReg FixedCSRFIMap[] = {
// `QC.C.MILEAVERET`.
static constexpr uint64_t QCIInterruptPushAmount = 96;
+// Smip/Ssip push six registers. ACLIC specifies a 24-byte frame for RV32E,
+// a 32-byte frame for RV32I, and a 48-byte frame for RV64.
+static uint64_t getACLICInterruptPushAmount(const MachineFunction &MF) {
+ const auto &STI = MF.getSubtarget<RISCVSubtarget>();
+ if (STI.is64Bit())
+ return 48;
+ return STI.getTargetABI() == RISCVABI::ABI_ILP32E ? 24 : 32;
+}
+
static const std::pair<MCPhysReg, int8_t> FixedCSRFIQCIInterruptMap[] = {
/* -1 is a gap for mepc/mnepc */
{/*fp*/ FPReg, -2},
@@ -251,9 +260,10 @@ static void emitSiFiveCLICStackSwap(MachineFunction &MF, MachineBasicBlock &MBB,
}
static void
-createSiFivePreemptibleInterruptFrameEntries(MachineFunction &MF,
- RISCVMachineFunctionInfo &RVFI) {
- if (!RVFI.isSiFivePreemptibleInterrupt(MF))
+createPreemptibleInterruptFrameEntries(MachineFunction &MF,
+ RISCVMachineFunctionInfo &RVFI) {
+ if (!RVFI.isSiFivePreemptibleInterrupt(MF) &&
+ !RVFI.isACLICPreemptibleInterrupt(MF))
return;
const TargetRegisterClass &RC = RISCV::GPRRegClass;
@@ -261,7 +271,7 @@ createSiFivePreemptibleInterruptFrameEntries(MachineFunction &MF,
*MF.getSubtarget<RISCVSubtarget>().getRegisterInfo();
MachineFrameInfo &MFI = MF.getFrameInfo();
- // Create two frame objects for saving `mcause` and `mepc`.
+ // Each preemptible interrupt kind saves two CSRs in dedicated frame objects.
for (int I = 0; I < 2; ++I) {
int FI = MFI.CreateStackObject(TRI.getSpillSize(RC), TRI.getSpillAlign(RC),
true);
@@ -269,13 +279,13 @@ createSiFivePreemptibleInterruptFrameEntries(MachineFunction &MF,
}
}
-// The scratch register retains an ordinary CSI slot, but its save and restore
-// are emitted explicitly as part of the SiFive CLIC interrupt sequence.
-static int getSiFiveCLICScratchFrameIndex(const MachineFunction &MF) {
+// X5 retains an ordinary CSI slot, but preemptible interrupt handlers save
+// and restore it explicitly around their CSR sequences.
+static int getPreemptibleInterruptScratchFrameIndex(const MachineFunction &MF) {
const auto &CSI = MF.getFrameInfo().getCalleeSavedInfo();
auto ScratchCS = llvm::find_if(
CSI, [](const CalleeSavedInfo &CS) { return CS.getReg() == RISCV::X5; });
- assert(ScratchCS != CSI.end() && "Missing SiFive CLIC scratch spill slot");
+ assert(ScratchCS != CSI.end() && "Missing interrupt scratch spill slot");
return ScratchCS->getFrameIdx();
}
@@ -295,7 +305,7 @@ static void emitSiFiveCLICPreemptibleSaves(MachineFunction &MF,
// Preserve X5 before using it to save the interrupt CSRs. Other GPRs
// are saved by the ordinary spill sequence after preemption is enabled.
- int ScratchFI = getSiFiveCLICScratchFrameIndex(MF);
+ int ScratchFI = getPreemptibleInterruptScratchFrameIndex(MF);
TII->storeRegToStackSlot(MBB, MBBI, RISCV::X5, /*IsKill=*/true, ScratchFI,
&RISCV::GPRRegClass, Register(),
MachineInstr::FrameSetup);
@@ -375,7 +385,99 @@ static void emitSiFiveCLICPreemptibleRestores(MachineFunction &MF,
// The ordinary reloads have finished. Recover the interrupted value of X5
// only after it has restored both CSRs.
TII->loadRegFromStackSlot(MBB, MBBI, RISCV::X5,
- getSiFiveCLICScratchFrameIndex(MF),
+ getPreemptibleInterruptScratchFrameIndex(MF),
+ &RISCV::GPRRegClass, Register(),
+ RISCV::NoSubRegister, MachineInstr::FrameDestroy);
+ if (needsDwarfCFI(MF))
+ CFIBuilder.buildRestore(RISCV::X5);
+}
+
+static void emitACLICPreemptibleSaves(MachineFunction &MF,
+ MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator MBBI,
+ const DebugLoc &DL) {
+ auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
+ const auto &STI = MF.getSubtarget<RISCVSubtarget>();
+ if (!RVFI->isACLICPreemptibleInterrupt(MF))
+ return;
+
+ const RISCVInstrInfo *TII = STI.getInstrInfo();
+ const bool IsSupervisor = RVFI->isACLICSupervisorInterrupt(MF);
+ const unsigned StatusCSR =
+ IsSupervisor ? RISCVSysReg::sistatus : RISCVSysReg::mistatus;
+ const unsigned EpcCSR = IsSupervisor ? RISCVSysReg::sepc : RISCVSysReg::mepc;
+
+ // Preserve X5 before using it to save the interrupt CSRs. The ordinary
+ // GPR spills follow after preemption is enabled.
+ int ScratchFI = getPreemptibleInterruptScratchFrameIndex(MF);
+ TII->storeRegToStackSlot(MBB, MBBI, RISCV::X5, /*IsKill=*/true, ScratchFI,
+ &RISCV::GPRRegClass, Register(),
+ MachineInstr::FrameSetup);
+ if (needsDwarfCFI(MF))
+ CFIInstBuilder(MBB, MBBI, MachineInstr::FrameSetup)
+ .buildOffset(RISCV::X5, MF.getFrameInfo().getObjectOffset(ScratchFI));
+
+ BuildMI(MBB, MBBI, DL, TII->get(RISCV::CSRRS))
+ .addReg(RISCV::X5, RegState::Define)
+ .addImm(EpcCSR)
+ .addReg(RISCV::X0)
+ .setMIFlag(MachineInstr::FrameSetup);
+ TII->storeRegToStackSlot(
+ MBB, MBBI, RISCV::X5, /*IsKill=*/true, RVFI->getInterruptCSRFrameIndex(0),
+ &RISCV::GPRRegClass, Register(), MachineInstr::FrameSetup);
+
+ // xistatus.xie is bit zero. CSRRSI returns the old status in X5 and enables
+ // interrupts after that value has been captured.
+ BuildMI(MBB, MBBI, DL, TII->get(RISCV::CSRRSI))
+ .addReg(RISCV::X5, RegState::Define)
+ .addImm(StatusCSR)
+ .addImm(1)
+ .setMIFlag(MachineInstr::FrameSetup);
+ TII->storeRegToStackSlot(
+ MBB, MBBI, RISCV::X5, /*IsKill=*/true, RVFI->getInterruptCSRFrameIndex(1),
+ &RISCV::GPRRegClass, Register(), MachineInstr::FrameSetup);
+}
+
+static void emitACLICPreemptibleRestores(MachineFunction &MF,
+ MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator MBBI,
+ CFIInstBuilder &CFIBuilder,
+ const DebugLoc &DL) {
+ auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
+ const auto &STI = MF.getSubtarget<RISCVSubtarget>();
+ if (!RVFI->isACLICPreemptibleInterrupt(MF))
+ return;
+
+ const RISCVInstrInfo *TII = STI.getInstrInfo();
+ const bool IsSupervisor = RVFI->isACLICSupervisorInterrupt(MF);
+ const unsigned StatusCSR =
+ IsSupervisor ? RISCVSysReg::sistatus : RISCVSysReg::mistatus;
+ const unsigned EpcCSR = IsSupervisor ? RISCVSysReg::sepc : RISCVSysReg::mepc;
+
+ // Loading xistatus while preemption is enabled is safe because nested
+ // handlers preserve X5. Restoring the entry value disables preemption.
+ TII->loadRegFromStackSlot(MBB, MBBI, RISCV::X5,
+ RVFI->getInterruptCSRFrameIndex(1),
+ &RISCV::GPRRegClass, Register(),
+ RISCV::NoSubRegister, MachineInstr::FrameDestroy);
+ BuildMI(MBB, MBBI, DL, TII->get(RISCV::CSRRW))
+ .addReg(RISCV::X0, RegState::Define)
+ .addImm(StatusCSR)
+ .addReg(RISCV::X5, RegState::Kill)
+ .setMIFlag(MachineInstr::FrameDestroy);
+
+ TII->loadRegFromStackSlot(MBB, MBBI, RISCV::X5,
+ RVFI->getInterruptCSRFrameIndex(0),
+ &RISCV::GPRRegClass, Register(),
+ RISCV::NoSubRegister, MachineInstr::FrameDestroy);
+ BuildMI(MBB, MBBI, DL, TII->get(RISCV::CSRRW))
+ .addReg(RISCV::X0, RegState::Define)
+ .addImm(EpcCSR)
+ .addReg(RISCV::X5, RegState::Kill)
+ .setMIFlag(MachineInstr::FrameDestroy);
+
+ TII->loadRegFromStackSlot(MBB, MBBI, RISCV::X5,
+ getPreemptibleInterruptScratchFrameIndex(MF),
&RISCV::GPRRegClass, Register(),
RISCV::NoSubRegister, MachineInstr::FrameDestroy);
if (needsDwarfCFI(MF))
@@ -604,14 +706,16 @@ getUnmanagedCSI(const MachineFunction &MF,
return NonLibcallCSI;
}
-// Exclude X5 from ordinary spills and restores for SiFive CLIC preemptible
-// handlers, which save and restore it explicitly.
+// Exclude X5 from ordinary spills and restores for preemptible interrupt
+// handlers, which save and restore it explicitly before the other GPRs.
static SmallVector<CalleeSavedInfo, 8>
getUnmanagedInterruptCSI(const MachineFunction &MF,
const std::vector<CalleeSavedInfo> &CSI,
bool ReverseOrder = false) {
auto InterruptCSI = getUnmanagedCSI(MF, CSI, ReverseOrder);
- if (MF.getInfo<RISCVMachineFunctionInfo>()->isSiFivePreemptibleInterrupt(MF))
+ const auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
+ if (RVFI->isSiFivePreemptibleInterrupt(MF) ||
+ RVFI->isACLICPreemptibleInterrupt(MF))
llvm::erase_if(InterruptCSI, [](const CalleeSavedInfo &CS) {
return CS.getReg() == RISCV::X5;
});
@@ -1057,6 +1161,12 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
CFIInstBuilder CFIBuilder(MBB, MBBI, MachineInstr::FrameSetup);
bool NeedsDwarfCFI = needsDwarfCFI(MF);
+ // Smip/Ssip have already adjusted SP before the first handler instruction.
+ // The locations of the six saved registers are implementation-defined, so
+ // only describe the CFA adjustment here.
+ if (NeedsDwarfCFI && RVFI->isACLICPushPopInterrupt(MF))
+ CFIBuilder.buildDefCFAOffset(RVFI->getACLICInterruptStackSize());
+
if (unsigned LibCallFrameSize = RVFI->getLibCallStackSize()) {
if (NeedsDwarfCFI) {
CFIBuilder.buildDefCFAOffset(LibCallFrameSize);
@@ -1085,7 +1195,7 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
uint64_t FirstSPAdjustAmount = getFirstSPAdjustAmount(MF);
// Split the SP adjustment to reduce the offsets of callee saved spill.
if (FirstSPAdjustAmount) {
- StackSize = FirstSPAdjustAmount;
+ StackSize = FirstSPAdjustAmount - RVFI->getACLICInterruptStackSize();
RealStackSize = FirstSPAdjustAmount;
}
@@ -1138,6 +1248,8 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
NeedProbe, ProbeSize, DynAllocation,
MachineInstr::FrameSetup);
+ emitACLICPreemptibleSaves(MF, MBB, MBBI, DL);
+
// Save SiFive CLIC CSRs into Stack
emitSiFiveCLICPreemptibleSaves(MF, MBB, MBBI, DL);
@@ -1342,9 +1454,10 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
uint64_t FirstSPAdjustAmount = getFirstSPAdjustAmount(MF);
uint64_t RealStackSize = FirstSPAdjustAmount ? FirstSPAdjustAmount
: getStackSizeWithRVVPadding(MF);
- uint64_t StackSize = FirstSPAdjustAmount ? FirstSPAdjustAmount
- : getStackSizeWithRVVPadding(MF) -
- RVFI->getReservedSpillsSize();
+ uint64_t StackSize =
+ FirstSPAdjustAmount
+ ? FirstSPAdjustAmount - RVFI->getACLICInterruptStackSize()
+ : getStackSizeWithRVVPadding(MF) - RVFI->getReservedSpillsSize();
uint64_t FPOffset = RealStackSize - RVFI->getVarArgsSaveSize();
uint64_t RVVStackSize = RVFI->getRVVStackSize();
@@ -1409,6 +1522,7 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
getUnmanagedInterruptCSI(MF, CSI, PreferAscendingLS).size());
CFIBuilder.setInsertPoint(MBBI);
emitSiFiveCLICPreemptibleRestores(MF, MBB, MBBI, CFIBuilder, DL);
+ emitACLICPreemptibleRestores(MF, MBB, MBBI, CFIBuilder, DL);
auto emitRestoreCFI = [&](auto CSInfo) {
for (auto &CS : CSInfo) {
@@ -1489,12 +1603,12 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
}
}
- // Deallocate stack if StackSize isn't a zero yet. If this is a QCI interrupt
- // function, there will be a leftover offset which is deallocated by
- // `QC.C.MILEAVERET`, otherwise getQCIInterruptStackSize() will be 0.
+ // Deallocate the software-managed stack. Hardware interrupt return
+ // instructions deallocate any remaining interrupt entry frame.
if (StackSize != 0)
deallocateStack(MF, MBB, MBBI, DL, StackSize,
- RVFI->getQCIInterruptStackSize());
+ RVFI->getQCIInterruptStackSize() +
+ RVFI->getACLICInterruptStackSize());
// Emit epilogue for shadow call stack.
emitSCSEpilogue(MF, MBB, MBBI, DL);
@@ -1673,9 +1787,7 @@ RISCVFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI,
return FI == CS.getFrameIdx();
};
- bool IsInterruptCSR = RVFI->isSiFivePreemptibleInterrupt(MF) &&
- (FI == RVFI->getInterruptCSRFrameIndex(0) ||
- FI == RVFI->getInterruptCSRFrameIndex(1));
+ bool IsInterruptCSR = RVFI->isInterruptCSRFrameIndex(FI);
bool IsInlineRestoredLibcallCSR = llvm::any_of(
getPushOrLibCallsSavedInfo(MF, MFI.getCalleeSavedInfo()), FIIsCalleeSave);
if ((FI >= MinCSFI && FI <= MaxCSFI) || IsInterruptCSR ||
@@ -1898,8 +2010,9 @@ void RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
SavedRegs.set(RISCVABI::getBPReg());
auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
- // X5 is used as a temporary for saving and restoring `mcause` and `mepc`.
- if (RVFI->isSiFivePreemptibleInterrupt(MF))
+ // X5 is used as a temporary for saving and restoring interrupt CSRs.
+ if (RVFI->isSiFivePreemptibleInterrupt(MF) ||
+ RVFI->isACLICPreemptibleInterrupt(MF))
SavedRegs.set(RISCV::X5);
// When using cm.push/pop we must save X27 if we save X26.
@@ -1967,8 +2080,8 @@ void RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
SavedRegs.set(CSReg);
}
- // SiFive Preemptible Interrupt Handlers need additional frame entries
- createSiFivePreemptibleInterruptFrameEntries(MF, *RVFI);
+ // Preemptible interrupt handlers need additional frame entries.
+ createPreemptibleInterruptFrameEntries(MF, *RVFI);
}
std::pair<int64_t, Align>
@@ -2282,7 +2395,8 @@ RISCVFrameLowering::getFirstSPAdjustAmount(const MachineFunction &MF) const {
// Disable SplitSPAdjust if save-restore libcall, push/pop or QCI interrupts
// are used. The callee-saved registers will be pushed by the save-restore
// libcalls, so we don't have to split the SP adjustment in this case.
- if (RVFI->getReservedSpillsSize())
+ if (RVFI->getLibCallStackSize() || RVFI->getRVPushStackSize() ||
+ RVFI->getQCIInterruptStackSize())
return 0;
// Return the FirstSPAdjustAmount if the StackSize can not fit in a signed
@@ -2347,13 +2461,19 @@ bool RISCVFrameLowering::assignCalleeSavedSpillSlots(
MachineFrameInfo &MFI = MF.getFrameInfo();
const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
+ if (RVFI->isACLICPushPopInterrupt(MF)) {
+ uint64_t PushAmount = getACLICInterruptPushAmount(MF);
+ RVFI->setACLICInterruptStackSize(PushAmount);
+ MFI.CreateFixedSpillStackObject(PushAmount,
+ -static_cast<int64_t>(PushAmount));
+ }
+
// Preemptible Interrupts have two additional Callee-save Frame Indexes,
// not tracked by `CSI`.
- if (RVFI->isSiFivePreemptibleInterrupt(MF)) {
- for (int I = 0; I < 2; ++I) {
- int FI = RVFI->getInterruptCSRFrameIndex(I);
- MFI.setIsCalleeSavedObjectIndex(FI, true);
- }
+ if (RVFI->isSiFivePreemptibleInterrupt(MF) ||
+ RVFI->isACLICPreemptibleInterrupt(MF)) {
+ for (int I = 0; I < 2; ++I)
+ MFI.setIsCalleeSavedObjectIndex(RVFI->getInterruptCSRFrameIndex(I), true);
}
// Early exit if no callee saved registers are modified!
@@ -2712,6 +2832,9 @@ bool RISCVFrameLowering::restoreCalleeSavedRegisters(
}
bool RISCVFrameLowering::enableShrinkWrapping(const MachineFunction &MF) const {
+ if (MF.getInfo<RISCVMachineFunctionInfo>()->isACLICPreemptibleInterrupt(MF))
+ return false;
+
// Keep the conventional code flow when not optimizing.
if (MF.getFunction().hasOptNone())
return false;
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 5b0ae94d805a3b..8a8f9bcf8e12ac 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -28589,6 +28589,12 @@ SDValue RISCVTargetLowering::LowerFormalArguments(
"SiFive-CLIC-preemptible",
"SiFive-CLIC-stack-swap",
"SiFive-CLIC-preemptible-stack-swap",
+ "machine-preemptible",
+ "supervisor-preemptible",
+ "machine-push-pop",
+ "supervisor-push-pop",
+ "machine-preemptible-push-pop",
+ "supervisor-preemptible-push-pop",
};
if (!llvm::is_contained(SupportedInterruptKinds, Kind))
reportFatalUsageError(
@@ -28602,6 +28608,20 @@ SDValue RISCVTargetLowering::LowerFormalArguments(
reportFatalUsageError(
"'SiFive-CLIC-*' interrupt kinds require XSfmclic extension");
+ const auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
+ const bool IsACLICPreemptible = RVFI->isACLICPreemptibleInterrupt(MF);
+ const bool IsACLICPushPop = RVFI->isACLICPushPopInterrupt(MF);
+ const bool IsACLICSupervisor = RVFI->isACLICSupervisorInterrupt(MF);
+ if (IsACLICPreemptible && (IsACLICSupervisor ? !Subtarget.hasStdExtSsnip()
+ : !Subtarget.hasStdExtSmnip()))
+ reportFatalUsageError(
+ "'preemptible' interrupt kinds require Smnip/Ssnip extension");
+
+ if (IsACLICPushPop && (IsACLICSupervisor ? !Subtarget.hasStdExtSsip()
+ : !Subtarget.hasStdExtSmip()))
+ reportFatalUsageError(
+ "'push-pop' interrupt kinds require Smip/Ssip extension");
+
if (Kind == "rnmi" && !Subtarget.hasStdExtSmrnmi())
reportFatalUsageError("'rnmi' interrupt kind requires Srnmi extension");
}
@@ -29491,9 +29511,11 @@ RISCVTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
StringRef Kind =
MF.getFunction().getFnAttribute("interrupt").getValueAsString();
- if (Kind == "supervisor")
- RetOpc = RISCVISD::SRET_GLUE;
- else if (Kind == "rnmi") {
+ const bool IsSupervisor = Kind.starts_with("supervisor");
+ const bool IsPushPop =
+ MF.getInfo<RISCVMachineFunctionInfo>()->isACLICPushPopInterrupt(MF);
+
+ if (Kind == "rnmi") {
assert(Subtarget.hasFeature(RISCV::FeatureStdExtSmrnmi) &&
"Need Smrnmi extension for rnmi");
RetOpc = RISCVISD::MNRET_GLUE;
@@ -29501,6 +29523,10 @@ RISCVTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
assert(Subtarget.hasFeature(RISCV::FeatureVendorXqciint) &&
"Need Xqciint for qci-(no)nest");
RetOpc = RISCVISD::QC_C_MILEAVERET_GLUE;
+ } else if (IsPushPop) {
+ RetOpc = IsSupervisor ? RISCVISD::SIPOPRET_GLUE : RISCVISD::MIPOPRET_GLUE;
+ } else if (IsSupervisor) {
+ RetOpc = RISCVISD::SRET_GLUE;
} else
RetOpc = RISCVISD::MRET_GLUE;
}
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
index d3bdb1ce202e3b..d5a4925524ea45 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -84,6 +84,10 @@ def riscv_mnret_glue : RVSDNode<"MNRET_GLUE", SDTNone,
[SDNPHasChain, SDNPOptInGlue]>;
def riscv_mileaveret_glue : RVSDNode<"QC_C_MILEAVERET_GLUE", SDTNone,
[SDNPHasChain, SDNPOptInGlue]>;
+def riscv_mipopret_glue : RVSDNode<"MIPOPRET_GLUE", SDTNone,
+ [SDNPHasChain, SDNPOptInGlue]>;
+def riscv_sipopret_glue : RVSDNode<"SIPOPRET_GLUE", SDTNone,
+ [SDNPHasChain, SDNPOptInGlue]>;
// Select with condition operator - This selects between a true value and
// a false value (ops #3 and #4) based on the boolean result of comparing
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoSmip.td b/llvm/lib/Target/RISCV/RISCVInstrInfoSmip.td
index 19d27003042be3..b3e1b6ba77121d 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoSmip.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoSmip.td
@@ -6,16 +6,24 @@
//
//===----------------------------------------------------------------------===//
-let Predicates = [HasStdExtSmip] in
-def MIPOPRET : Priv<"mipopret", 0b0011000>, Sched<[]> {
- let rd = 0;
- let rs1 = 0;
- let rs2 = 0b01000;
-}
+let mayLoad = 1, Uses = [X2], Defs = [X2, X10, X11, X12, X13, X14, X15],
+ isBarrier = 1, isReturn = 1, isTerminator = 1 in {
+ let Predicates = [HasStdExtSmip] in
+ def MIPOPRET : Priv<"mipopret", 0b0011000>, Sched<[]> {
+ let rd = 0;
+ let rs1 = 0;
+ let rs2 = 0b01000;
+ }
+
+ let Predicates = [HasStdExtSsip] in
+ def SIPOPRET : Priv<"sipopret", 0b0001000>, Sched<[]> {
+ let rd = 0;
+ let rs1 = 0;
+ let rs2 = 0b01000;
+ }
+} // isBarrier = 1, isReturn = 1, isTerminator = 1
+let Predicates = [HasStdExtSmip] in
+def : Pat<(riscv_mipopret_glue), (MIPOPRET)>;
let Predicates = [HasStdExtSsip] in
-def SIPOPRET : Priv<"sipopret", 0b0001000>, Sched<[]> {
- let rd = 0;
- let rs1 = 0;
- let rs2 = 0b01000;
-}
+def : Pat<(riscv_sipopret_glue), (SIPOPRET)>;
diff --git a/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp b/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp
index f96a8dce3d8489..c25d02a52f2de3 100644
--- a/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp
@@ -80,6 +80,15 @@ RISCVMachineFunctionInfo::getInterruptStackKind(
.Case("SiFive-CLIC-stack-swap", InterruptStackKind::SiFiveCLICStackSwap)
.Case("SiFive-CLIC-preemptible-stack-swap",
InterruptStackKind::SiFiveCLICPreemptibleStackSwap)
+ .Case("machine-preemptible", InterruptStackKind::ACLICPreemptible)
+ .Case("supervisor-preemptible",
+ InterruptStackKind::ACLICSupervisorPreemptible)
+ .Case("machine-push-pop", InterruptStackKind::ACLICPushPop)
+ .Case("supervisor-push-pop", InterruptStackKind::ACLICSupervisorPushPop)
+ .Case("machine-preemptible-push-pop",
+ InterruptStackKind::ACLICPreemptiblePushPop)
+ .Case("supervisor-preemptible-push-pop",
+ InterruptStackKind::ACLICSupervisorPreemptiblePushPop)
.Default(InterruptStackKind::None);
}
@@ -117,6 +126,11 @@ RISCVMachineFunctionInfo::getPushPopKind(const MachineFunction &MF) const {
if (useSiFiveInterrupt(MF))
return PushPopKind::None;
+ // ACLIC push-pop uses a separate hardware frame restored by
+ // mipopret/sipopret.
+ if (isACLICPushPopInterrupt(MF))
+ return PushPopKind::None;
+
// Zcmp is not compatible with the frame pointer convention.
if (MF.getSubtarget<RISCVSubtarget>().hasStdExtZcmp() &&
!MF.disableFramePointerElim())
diff --git a/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h b/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
index 3aaf7466d7425c..65c9ab8b714e36 100644
--- a/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
+++ b/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
@@ -87,6 +87,9 @@ class RISCVMachineFunctionInfo : public MachineFunctionInfo {
/// Size of any opaque stack adjustment due to QCI Interrupt instructions.
unsigned QCIInterruptStackSize = 0;
+ /// Size of the frame pushed by ACLIC Smip/Ssip interrupt entry.
+ unsigned ACLICInterruptStackSize = 0;
+
/// Store Frame Indexes for Interrupt-Related CSR Spills.
SmallVector<int, 2> InterruptCSRFrameIndexes;
@@ -127,7 +130,8 @@ class RISCVMachineFunctionInfo : public MachineFunctionInfo {
}
unsigned getReservedSpillsSize() const {
- return LibCallStackSize + RVPushStackSize + QCIInterruptStackSize;
+ return LibCallStackSize + RVPushStackSize + QCIInterruptStackSize +
+ ACLICInterruptStackSize;
}
unsigned getLibCallStackSize() const { return LibCallStackSize; }
@@ -190,7 +194,13 @@ class RISCVMachineFunctionInfo : public MachineFunctionInfo {
QCINoNest,
SiFiveCLICPreemptible,
SiFiveCLICStackSwap,
- SiFiveCLICPreemptibleStackSwap
+ SiFiveCLICPreemptibleStackSwap,
+ ACLICPreemptible,
+ ACLICSupervisorPreemptible,
+ ACLICPushPop,
+ ACLICSupervisorPushPop,
+ ACLICPreemptiblePushPop,
+ ACLICSupervisorPreemptiblePushPop
};
InterruptStackKind getInterruptStackKind(const MachineFunction &MF) const;
@@ -204,6 +214,14 @@ class RISCVMachineFunctionInfo : public MachineFunctionInfo {
unsigned getQCIInterruptStackSize() const { return QCIInterruptStackSize; }
void setQCIInterruptStackSize(unsigned Size) { QCIInterruptStackSize = Size; }
+ unsigned getACLICInterruptStackSize() const {
+ return ACLICInterruptStackSize;
+ }
+
+ void setACLICInterruptStackSize(unsigned Size) {
+ ACLICInterruptStackSize = Size;
+ }
+
bool useSiFiveInterrupt(const MachineFunction &MF) const {
InterruptStackKind Kind = getInterruptStackKind(MF);
return Kind == InterruptStackKind::SiFiveCLICPreemptible ||
@@ -223,12 +241,41 @@ class RISCVMachineFunctionInfo : public MachineFunctionInfo {
Kind == InterruptStackKind::SiFiveCLICPreemptibleStackSwap;
}
+ bool isACLICPreemptibleInterrupt(const MachineFunction &MF) const {
+ InterruptStackKind Kind = getInterruptStackKind(MF);
+ return Kind == InterruptStackKind::ACLICPreemptible ||
+ Kind == InterruptStackKind::ACLICSupervisorPreemptible ||
+ Kind == InterruptStackKind::ACLICPreemptiblePushPop ||
+ Kind == InterruptStackKind::ACLICSupervisorPreemptiblePushPop;
+ }
+
+ bool isACLICPushPopInterrupt(const MachineFunction &MF) const {
+ InterruptStackKind Kind = getInterruptStackKind(MF);
+ return Kind == InterruptStackKind::ACLICPushPop ||
+ Kind == InterruptStackKind::ACLICSupervisorPushPop ||
+ Kind == InterruptStackKind::ACLICPreemptiblePushPop ||
+ Kind == InterruptStackKind::ACLICSupervisorPreemptiblePushPop;
+ }
+
+ bool isACLICSupervisorInterrupt(const MachineFunction &MF) const {
+ InterruptStackKind Kind = getInterruptStackKind(MF);
+ return Kind == InterruptStackKind::ACLICSupervisorPreemptible ||
+ Kind == InterruptStackKind::ACLICSupervisorPushPop ||
+ Kind == InterruptStackKind::ACLICSupervisorPreemptiblePushPop;
+ }
+
void pushInterruptCSRFrameIndex(int FI) {
InterruptCSRFrameIndexes.push_back(FI);
}
int getInterruptCSRFrameIndex(size_t Idx) const {
return InterruptCSRFrameIndexes[Idx];
}
+ bool isInterruptCSRFrameIndex(int FI) const {
+ for (int Index : InterruptCSRFrameIndexes)
+ if (Index == FI)
+ return true;
+ return false;
+ }
// Some Stack Management Variants automatically update FP in a frame-pointer
// convention compatible way - which means we don't need to manually update
diff --git a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
index 742140325342eb..04923dcac164cc 100644
--- a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
@@ -12,6 +12,7 @@
#include "RISCVRegisterInfo.h"
#include "RISCV.h"
+#include "RISCVMachineFunctionInfo.h"
#include "RISCVSubtarget.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/BinaryFormat/Dwarf.h"
@@ -64,24 +65,44 @@ RISCVRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
return Subtarget.hasStdExtE() ? CSR_RT_MostRegs_RVE_SaveList
: CSR_RT_MostRegs_SaveList;
if (MF->getFunction().hasFnAttribute("interrupt")) {
+ const bool IsPushPop =
+ MF->getInfo<RISCVMachineFunctionInfo>()->isACLICPushPopInterrupt(*MF);
if (Subtarget.hasVInstructions()) {
if (Subtarget.hasStdExtD())
- return Subtarget.hasStdExtE() ? CSR_XLEN_F64_V_Interrupt_RVE_SaveList
- : CSR_XLEN_F64_V_Interrupt_SaveList;
+ return Subtarget.hasStdExtE()
+ ? (IsPushPop ? CSR_XLEN_F64_V_Interrupt_PushPop_RVE_SaveList
+ : CSR_XLEN_F64_V_Interrupt_RVE_SaveList)
+ : (IsPushPop ? CSR_XLEN_F64_V_Interrupt_PushPop_SaveList
+ : CSR_XLEN_F64_V_Interrupt_SaveList);
if (Subtarget.hasStdExtF())
- return Subtarget.hasStdExtE() ? CSR_XLEN_F32_V_Interrupt_RVE_SaveList
- : CSR_XLEN_F32_V_Interrupt_SaveList;
- return Subtarget.hasStdExtE() ? CSR_XLEN_V_Interrupt_RVE_SaveList
- : CSR_XLEN_V_Interrupt_SaveList;
+ return Subtarget.hasStdExtE()
+ ? (IsPushPop ? CSR_XLEN_F32_V_Interrupt_PushPop_RVE_SaveList
+ : CSR_XLEN_F32_V_Interrupt_RVE_SaveList)
+ : (IsPushPop ? CSR_XLEN_F32_V_Interrupt_PushPop_SaveList
+ : CSR_XLEN_F32_V_Interrupt_SaveList);
+ return Subtarget.hasStdExtE()
+ ? (IsPushPop ? CSR_XLEN_V_Interrupt_PushPop_RVE_SaveList
+ : CSR_XLEN_V_Interrupt_RVE_SaveList)
+ : (IsPushPop ? CSR_XLEN_V_Interrupt_PushPop_SaveList
+ : CSR_XLEN_V_Interrupt_SaveList);
}
if (Subtarget.hasStdExtD())
- return Subtarget.hasStdExtE() ? CSR_XLEN_F64_Interrupt_RVE_SaveList
- : CSR_XLEN_F64_Interrupt_SaveList;
+ return Subtarget.hasStdExtE()
+ ? (IsPushPop ? CSR_XLEN_F64_Interrupt_PushPop_RVE_SaveList
+ : CSR_XLEN_F64_Interrupt_RVE_SaveList)
+ : (IsPushPop ? CSR_XLEN_F64_Interrupt_PushPop_SaveList
+ : CSR_XLEN_F64_Interrupt_SaveList);
if (Subtarget.hasStdExtF())
- return Subtarget.hasStdExtE() ? CSR_XLEN_F32_Interrupt_RVE_SaveList
- : CSR_XLEN_F32_Interrupt_SaveList;
- return Subtarget.hasStdExtE() ? CSR_Interrupt_RVE_SaveList
- : CSR_Interrupt_SaveList;
+ return Subtarget.hasStdExtE()
+ ? (IsPushPop ? CSR_XLEN_F32_Interrupt_PushPop_RVE_SaveList
+ : CSR_XLEN_F32_Interrupt_RVE_SaveList)
+ : (IsPushPop ? CSR_XLEN_F32_Interrupt_PushPop_SaveList
+ : CSR_XLEN_F32_Interrupt_SaveList);
+ return Subtarget.hasStdExtE()
+ ? (IsPushPop ? CSR_Interrupt_PushPop_RVE_SaveList
+ : CSR_Interrupt_RVE_SaveList)
+ : (IsPushPop ? CSR_Interrupt_PushPop_SaveList
+ : CSR_Interrupt_SaveList);
}
bool HasVectorCSR =
diff --git a/llvm/test/CodeGen/RISCV/aclic-interrupt-attr-error.ll b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr-error.ll
new file mode 100644
index 00000000000000..94f40e2b68208a
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr-error.ll
@@ -0,0 +1,35 @@
+; RUN: split-file %s %t
+; RUN: not llc -mtriple=riscv32 %t/m-preemptible.ll -o - 2>&1 \
+; RUN: | FileCheck %s --check-prefix=M-PREEMPTIBLE
+; RUN: not llc -mtriple=riscv32 -mattr=+experimental-smnip \
+; RUN: %t/m-push-pop.ll -o - 2>&1 | FileCheck %s --check-prefix=M-PUSH-POP
+; RUN: not llc -mtriple=riscv32 -mattr=+experimental-smnip \
+; RUN: %t/s-preemptible.ll -o - 2>&1 \
+; RUN: | FileCheck %s --check-prefix=S-PREEMPTIBLE
+; RUN: not llc -mtriple=riscv32 -mattr=+experimental-smip \
+; RUN: %t/s-push-pop.ll -o - 2>&1 | FileCheck %s --check-prefix=S-PUSH-POP
+
+; M-PREEMPTIBLE: 'preemptible' interrupt kinds require Smnip/Ssnip extension
+; M-PUSH-POP: 'push-pop' interrupt kinds require Smip/Ssip extension
+; S-PREEMPTIBLE: 'preemptible' interrupt kinds require Smnip/Ssnip extension
+; S-PUSH-POP: 'push-pop' interrupt kinds require Smip/Ssip extension
+
+;--- m-preemptible.ll
+define void @f() "interrupt"="machine-preemptible" {
+ ret void
+}
+
+;--- m-push-pop.ll
+define void @f() "interrupt"="machine-preemptible-push-pop" {
+ ret void
+}
+
+;--- s-preemptible.ll
+define void @f() "interrupt"="supervisor-preemptible" {
+ ret void
+}
+
+;--- s-push-pop.ll
+define void @f() "interrupt"="supervisor-push-pop" {
+ ret void
+}
diff --git a/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
new file mode 100644
index 00000000000000..aad68e62929794
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
@@ -0,0 +1,1265 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=riscv32 -verify-machineinstrs \
+; RUN: -mattr=+experimental-smnip,+experimental-ssnip,+experimental-smip,+experimental-ssip \
+; RUN: < %s | FileCheck %s --check-prefix=RV32
+; RUN: llc -mtriple=riscv32 -target-abi=ilp32e -verify-machineinstrs \
+; RUN: -mattr=+e,+experimental-smnip,+experimental-ssnip,+experimental-smip,+experimental-ssip \
+; RUN: < %s | FileCheck %s --check-prefix=RV32E
+; RUN: llc -mtriple=riscv64 -verify-machineinstrs \
+; RUN: -mattr=+experimental-smnip,+experimental-ssnip,+experimental-smip,+experimental-ssip \
+; RUN: < %s | FileCheck %s --check-prefix=RV64
+
+declare void @callee()
+
+; Keep the interrupt enable ahead of ordinary GPR spills in a handler that
+; calls out, for both the machine and supervisor register save conventions.
+define void @m_preemptible_call() #0 {
+; RV32-LABEL: m_preemptible_call:
+; RV32: # %bb.0:
+; RV32-NEXT: addi sp, sp, -80
+; RV32-NEXT: .cfi_def_cfa_offset 80
+; RV32-NEXT: sw t0, 64(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset t0, -16
+; RV32-NEXT: csrr t0, mepc
+; RV32-NEXT: sw t0, 76(sp) # 4-byte Folded Spill
+; RV32-NEXT: csrrsi t0, mistatus, 1
+; RV32-NEXT: sw t0, 72(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw ra, 68(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t1, 60(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t2, 56(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a0, 52(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a1, 48(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a2, 44(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a3, 40(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a4, 36(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a5, 32(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a6, 28(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a7, 24(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t3, 20(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t4, 16(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t5, 12(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t6, 8(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset ra, -12
+; RV32-NEXT: .cfi_offset t1, -20
+; RV32-NEXT: .cfi_offset t2, -24
+; RV32-NEXT: .cfi_offset a0, -28
+; RV32-NEXT: .cfi_offset a1, -32
+; RV32-NEXT: .cfi_offset a2, -36
+; RV32-NEXT: .cfi_offset a3, -40
+; RV32-NEXT: .cfi_offset a4, -44
+; RV32-NEXT: .cfi_offset a5, -48
+; RV32-NEXT: .cfi_offset a6, -52
+; RV32-NEXT: .cfi_offset a7, -56
+; RV32-NEXT: .cfi_offset t3, -60
+; RV32-NEXT: .cfi_offset t4, -64
+; RV32-NEXT: .cfi_offset t5, -68
+; RV32-NEXT: .cfi_offset t6, -72
+; RV32-NEXT: call callee
+; RV32-NEXT: lw ra, 68(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t1, 60(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t2, 56(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a0, 52(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a1, 48(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a2, 44(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a3, 40(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a4, 36(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a5, 32(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a6, 28(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a7, 24(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t3, 20(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t4, 16(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t5, 12(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t6, 8(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t0, 72(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw mistatus, t0
+; RV32-NEXT: lw t0, 76(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw mepc, t0
+; RV32-NEXT: lw t0, 64(sp) # 4-byte Folded Reload
+; RV32-NEXT: .cfi_restore t0
+; RV32-NEXT: .cfi_restore ra
+; RV32-NEXT: .cfi_restore t1
+; RV32-NEXT: .cfi_restore t2
+; RV32-NEXT: .cfi_restore a0
+; RV32-NEXT: .cfi_restore a1
+; RV32-NEXT: .cfi_restore a2
+; RV32-NEXT: .cfi_restore a3
+; RV32-NEXT: .cfi_restore a4
+; RV32-NEXT: .cfi_restore a5
+; RV32-NEXT: .cfi_restore a6
+; RV32-NEXT: .cfi_restore a7
+; RV32-NEXT: .cfi_restore t3
+; RV32-NEXT: .cfi_restore t4
+; RV32-NEXT: .cfi_restore t5
+; RV32-NEXT: .cfi_restore t6
+; RV32-NEXT: addi sp, sp, 80
+; RV32-NEXT: .cfi_def_cfa_offset 0
+; RV32-NEXT: mret
+;
+; RV32E-LABEL: m_preemptible_call:
+; RV32E: # %bb.0:
+; RV32E-NEXT: addi sp, sp, -48
+; RV32E-NEXT: .cfi_def_cfa_offset 48
+; RV32E-NEXT: sw t0, 32(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset t0, -16
+; RV32E-NEXT: csrr t0, mepc
+; RV32E-NEXT: sw t0, 44(sp) # 4-byte Folded Spill
+; RV32E-NEXT: csrrsi t0, mistatus, 1
+; RV32E-NEXT: sw t0, 40(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw ra, 36(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw t1, 28(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw t2, 24(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a0, 20(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a1, 16(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a2, 12(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a3, 8(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a4, 4(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a5, 0(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset ra, -12
+; RV32E-NEXT: .cfi_offset t1, -20
+; RV32E-NEXT: .cfi_offset t2, -24
+; RV32E-NEXT: .cfi_offset a0, -28
+; RV32E-NEXT: .cfi_offset a1, -32
+; RV32E-NEXT: .cfi_offset a2, -36
+; RV32E-NEXT: .cfi_offset a3, -40
+; RV32E-NEXT: .cfi_offset a4, -44
+; RV32E-NEXT: .cfi_offset a5, -48
+; RV32E-NEXT: call callee
+; RV32E-NEXT: lw ra, 36(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t1, 28(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t2, 24(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a0, 20(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a1, 16(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a2, 12(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a3, 8(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a4, 4(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a5, 0(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t0, 40(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw mistatus, t0
+; RV32E-NEXT: lw t0, 44(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw mepc, t0
+; RV32E-NEXT: lw t0, 32(sp) # 4-byte Folded Reload
+; RV32E-NEXT: .cfi_restore t0
+; RV32E-NEXT: .cfi_restore ra
+; RV32E-NEXT: .cfi_restore t1
+; RV32E-NEXT: .cfi_restore t2
+; RV32E-NEXT: .cfi_restore a0
+; RV32E-NEXT: .cfi_restore a1
+; RV32E-NEXT: .cfi_restore a2
+; RV32E-NEXT: .cfi_restore a3
+; RV32E-NEXT: .cfi_restore a4
+; RV32E-NEXT: .cfi_restore a5
+; RV32E-NEXT: addi sp, sp, 48
+; RV32E-NEXT: .cfi_def_cfa_offset 0
+; RV32E-NEXT: mret
+;
+; RV64-LABEL: m_preemptible_call:
+; RV64: # %bb.0:
+; RV64-NEXT: addi sp, sp, -144
+; RV64-NEXT: .cfi_def_cfa_offset 144
+; RV64-NEXT: sd t0, 112(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset t0, -32
+; RV64-NEXT: csrr t0, mepc
+; RV64-NEXT: sd t0, 136(sp) # 8-byte Folded Spill
+; RV64-NEXT: csrrsi t0, mistatus, 1
+; RV64-NEXT: sd t0, 128(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd ra, 120(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t1, 104(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t2, 96(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a0, 88(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a1, 80(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a2, 72(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a3, 64(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a4, 56(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a5, 48(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a6, 40(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a7, 32(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t3, 24(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t4, 16(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t5, 8(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t6, 0(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset ra, -24
+; RV64-NEXT: .cfi_offset t1, -40
+; RV64-NEXT: .cfi_offset t2, -48
+; RV64-NEXT: .cfi_offset a0, -56
+; RV64-NEXT: .cfi_offset a1, -64
+; RV64-NEXT: .cfi_offset a2, -72
+; RV64-NEXT: .cfi_offset a3, -80
+; RV64-NEXT: .cfi_offset a4, -88
+; RV64-NEXT: .cfi_offset a5, -96
+; RV64-NEXT: .cfi_offset a6, -104
+; RV64-NEXT: .cfi_offset a7, -112
+; RV64-NEXT: .cfi_offset t3, -120
+; RV64-NEXT: .cfi_offset t4, -128
+; RV64-NEXT: .cfi_offset t5, -136
+; RV64-NEXT: .cfi_offset t6, -144
+; RV64-NEXT: call callee
+; RV64-NEXT: ld ra, 120(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t1, 104(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t2, 96(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a0, 88(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a1, 80(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a2, 72(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a3, 64(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a4, 56(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a5, 48(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a6, 40(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a7, 32(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t3, 24(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t4, 16(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t5, 8(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t6, 0(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t0, 128(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw mistatus, t0
+; RV64-NEXT: ld t0, 136(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw mepc, t0
+; RV64-NEXT: ld t0, 112(sp) # 8-byte Folded Reload
+; RV64-NEXT: .cfi_restore t0
+; RV64-NEXT: .cfi_restore ra
+; RV64-NEXT: .cfi_restore t1
+; RV64-NEXT: .cfi_restore t2
+; RV64-NEXT: .cfi_restore a0
+; RV64-NEXT: .cfi_restore a1
+; RV64-NEXT: .cfi_restore a2
+; RV64-NEXT: .cfi_restore a3
+; RV64-NEXT: .cfi_restore a4
+; RV64-NEXT: .cfi_restore a5
+; RV64-NEXT: .cfi_restore a6
+; RV64-NEXT: .cfi_restore a7
+; RV64-NEXT: .cfi_restore t3
+; RV64-NEXT: .cfi_restore t4
+; RV64-NEXT: .cfi_restore t5
+; RV64-NEXT: .cfi_restore t6
+; RV64-NEXT: addi sp, sp, 144
+; RV64-NEXT: .cfi_def_cfa_offset 0
+; RV64-NEXT: mret
+ call void @callee()
+ ret void
+}
+
+define void @s_preemptible_call() #1 {
+; RV32-LABEL: s_preemptible_call:
+; RV32: # %bb.0:
+; RV32-NEXT: addi sp, sp, -80
+; RV32-NEXT: .cfi_def_cfa_offset 80
+; RV32-NEXT: sw t0, 64(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset t0, -16
+; RV32-NEXT: csrr t0, sepc
+; RV32-NEXT: sw t0, 76(sp) # 4-byte Folded Spill
+; RV32-NEXT: csrrsi t0, sistatus, 1
+; RV32-NEXT: sw t0, 72(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw ra, 68(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t1, 60(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t2, 56(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a0, 52(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a1, 48(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a2, 44(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a3, 40(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a4, 36(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a5, 32(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a6, 28(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a7, 24(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t3, 20(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t4, 16(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t5, 12(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t6, 8(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset ra, -12
+; RV32-NEXT: .cfi_offset t1, -20
+; RV32-NEXT: .cfi_offset t2, -24
+; RV32-NEXT: .cfi_offset a0, -28
+; RV32-NEXT: .cfi_offset a1, -32
+; RV32-NEXT: .cfi_offset a2, -36
+; RV32-NEXT: .cfi_offset a3, -40
+; RV32-NEXT: .cfi_offset a4, -44
+; RV32-NEXT: .cfi_offset a5, -48
+; RV32-NEXT: .cfi_offset a6, -52
+; RV32-NEXT: .cfi_offset a7, -56
+; RV32-NEXT: .cfi_offset t3, -60
+; RV32-NEXT: .cfi_offset t4, -64
+; RV32-NEXT: .cfi_offset t5, -68
+; RV32-NEXT: .cfi_offset t6, -72
+; RV32-NEXT: call callee
+; RV32-NEXT: lw ra, 68(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t1, 60(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t2, 56(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a0, 52(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a1, 48(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a2, 44(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a3, 40(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a4, 36(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a5, 32(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a6, 28(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a7, 24(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t3, 20(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t4, 16(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t5, 12(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t6, 8(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t0, 72(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw sistatus, t0
+; RV32-NEXT: lw t0, 76(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw sepc, t0
+; RV32-NEXT: lw t0, 64(sp) # 4-byte Folded Reload
+; RV32-NEXT: .cfi_restore t0
+; RV32-NEXT: .cfi_restore ra
+; RV32-NEXT: .cfi_restore t1
+; RV32-NEXT: .cfi_restore t2
+; RV32-NEXT: .cfi_restore a0
+; RV32-NEXT: .cfi_restore a1
+; RV32-NEXT: .cfi_restore a2
+; RV32-NEXT: .cfi_restore a3
+; RV32-NEXT: .cfi_restore a4
+; RV32-NEXT: .cfi_restore a5
+; RV32-NEXT: .cfi_restore a6
+; RV32-NEXT: .cfi_restore a7
+; RV32-NEXT: .cfi_restore t3
+; RV32-NEXT: .cfi_restore t4
+; RV32-NEXT: .cfi_restore t5
+; RV32-NEXT: .cfi_restore t6
+; RV32-NEXT: addi sp, sp, 80
+; RV32-NEXT: .cfi_def_cfa_offset 0
+; RV32-NEXT: sret
+;
+; RV32E-LABEL: s_preemptible_call:
+; RV32E: # %bb.0:
+; RV32E-NEXT: addi sp, sp, -48
+; RV32E-NEXT: .cfi_def_cfa_offset 48
+; RV32E-NEXT: sw t0, 32(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset t0, -16
+; RV32E-NEXT: csrr t0, sepc
+; RV32E-NEXT: sw t0, 44(sp) # 4-byte Folded Spill
+; RV32E-NEXT: csrrsi t0, sistatus, 1
+; RV32E-NEXT: sw t0, 40(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw ra, 36(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw t1, 28(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw t2, 24(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a0, 20(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a1, 16(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a2, 12(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a3, 8(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a4, 4(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a5, 0(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset ra, -12
+; RV32E-NEXT: .cfi_offset t1, -20
+; RV32E-NEXT: .cfi_offset t2, -24
+; RV32E-NEXT: .cfi_offset a0, -28
+; RV32E-NEXT: .cfi_offset a1, -32
+; RV32E-NEXT: .cfi_offset a2, -36
+; RV32E-NEXT: .cfi_offset a3, -40
+; RV32E-NEXT: .cfi_offset a4, -44
+; RV32E-NEXT: .cfi_offset a5, -48
+; RV32E-NEXT: call callee
+; RV32E-NEXT: lw ra, 36(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t1, 28(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t2, 24(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a0, 20(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a1, 16(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a2, 12(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a3, 8(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a4, 4(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a5, 0(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t0, 40(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw sistatus, t0
+; RV32E-NEXT: lw t0, 44(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw sepc, t0
+; RV32E-NEXT: lw t0, 32(sp) # 4-byte Folded Reload
+; RV32E-NEXT: .cfi_restore t0
+; RV32E-NEXT: .cfi_restore ra
+; RV32E-NEXT: .cfi_restore t1
+; RV32E-NEXT: .cfi_restore t2
+; RV32E-NEXT: .cfi_restore a0
+; RV32E-NEXT: .cfi_restore a1
+; RV32E-NEXT: .cfi_restore a2
+; RV32E-NEXT: .cfi_restore a3
+; RV32E-NEXT: .cfi_restore a4
+; RV32E-NEXT: .cfi_restore a5
+; RV32E-NEXT: addi sp, sp, 48
+; RV32E-NEXT: .cfi_def_cfa_offset 0
+; RV32E-NEXT: sret
+;
+; RV64-LABEL: s_preemptible_call:
+; RV64: # %bb.0:
+; RV64-NEXT: addi sp, sp, -144
+; RV64-NEXT: .cfi_def_cfa_offset 144
+; RV64-NEXT: sd t0, 112(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset t0, -32
+; RV64-NEXT: csrr t0, sepc
+; RV64-NEXT: sd t0, 136(sp) # 8-byte Folded Spill
+; RV64-NEXT: csrrsi t0, sistatus, 1
+; RV64-NEXT: sd t0, 128(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd ra, 120(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t1, 104(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t2, 96(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a0, 88(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a1, 80(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a2, 72(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a3, 64(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a4, 56(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a5, 48(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a6, 40(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a7, 32(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t3, 24(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t4, 16(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t5, 8(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t6, 0(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset ra, -24
+; RV64-NEXT: .cfi_offset t1, -40
+; RV64-NEXT: .cfi_offset t2, -48
+; RV64-NEXT: .cfi_offset a0, -56
+; RV64-NEXT: .cfi_offset a1, -64
+; RV64-NEXT: .cfi_offset a2, -72
+; RV64-NEXT: .cfi_offset a3, -80
+; RV64-NEXT: .cfi_offset a4, -88
+; RV64-NEXT: .cfi_offset a5, -96
+; RV64-NEXT: .cfi_offset a6, -104
+; RV64-NEXT: .cfi_offset a7, -112
+; RV64-NEXT: .cfi_offset t3, -120
+; RV64-NEXT: .cfi_offset t4, -128
+; RV64-NEXT: .cfi_offset t5, -136
+; RV64-NEXT: .cfi_offset t6, -144
+; RV64-NEXT: call callee
+; RV64-NEXT: ld ra, 120(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t1, 104(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t2, 96(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a0, 88(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a1, 80(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a2, 72(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a3, 64(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a4, 56(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a5, 48(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a6, 40(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a7, 32(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t3, 24(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t4, 16(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t5, 8(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t6, 0(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t0, 128(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw sistatus, t0
+; RV64-NEXT: ld t0, 136(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw sepc, t0
+; RV64-NEXT: ld t0, 112(sp) # 8-byte Folded Reload
+; RV64-NEXT: .cfi_restore t0
+; RV64-NEXT: .cfi_restore ra
+; RV64-NEXT: .cfi_restore t1
+; RV64-NEXT: .cfi_restore t2
+; RV64-NEXT: .cfi_restore a0
+; RV64-NEXT: .cfi_restore a1
+; RV64-NEXT: .cfi_restore a2
+; RV64-NEXT: .cfi_restore a3
+; RV64-NEXT: .cfi_restore a4
+; RV64-NEXT: .cfi_restore a5
+; RV64-NEXT: .cfi_restore a6
+; RV64-NEXT: .cfi_restore a7
+; RV64-NEXT: .cfi_restore t3
+; RV64-NEXT: .cfi_restore t4
+; RV64-NEXT: .cfi_restore t5
+; RV64-NEXT: .cfi_restore t6
+; RV64-NEXT: addi sp, sp, 144
+; RV64-NEXT: .cfi_def_cfa_offset 0
+; RV64-NEXT: sret
+ call void @callee()
+ ret void
+}
+
+define void @m_preemptible() #0 {
+; RV32-LABEL: m_preemptible:
+; RV32: # %bb.0:
+; RV32-NEXT: addi sp, sp, -16
+; RV32-NEXT: .cfi_def_cfa_offset 16
+; RV32-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset t0, -12
+; RV32-NEXT: csrr t0, mepc
+; RV32-NEXT: sw t0, 12(sp) # 4-byte Folded Spill
+; RV32-NEXT: csrrsi t0, mistatus, 1
+; RV32-NEXT: sw t0, 8(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw zero, 0(sp)
+; RV32-NEXT: lw t0, 8(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw mistatus, t0
+; RV32-NEXT: lw t0, 12(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw mepc, t0
+; RV32-NEXT: lw t0, 4(sp) # 4-byte Folded Reload
+; RV32-NEXT: .cfi_restore t0
+; RV32-NEXT: addi sp, sp, 16
+; RV32-NEXT: .cfi_def_cfa_offset 0
+; RV32-NEXT: mret
+;
+; RV32E-LABEL: m_preemptible:
+; RV32E: # %bb.0:
+; RV32E-NEXT: addi sp, sp, -16
+; RV32E-NEXT: .cfi_def_cfa_offset 16
+; RV32E-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset t0, -12
+; RV32E-NEXT: csrr t0, mepc
+; RV32E-NEXT: sw t0, 12(sp) # 4-byte Folded Spill
+; RV32E-NEXT: csrrsi t0, mistatus, 1
+; RV32E-NEXT: sw t0, 8(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw zero, 0(sp)
+; RV32E-NEXT: lw t0, 8(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw mistatus, t0
+; RV32E-NEXT: lw t0, 12(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw mepc, t0
+; RV32E-NEXT: lw t0, 4(sp) # 4-byte Folded Reload
+; RV32E-NEXT: .cfi_restore t0
+; RV32E-NEXT: addi sp, sp, 16
+; RV32E-NEXT: .cfi_def_cfa_offset 0
+; RV32E-NEXT: mret
+;
+; RV64-LABEL: m_preemptible:
+; RV64: # %bb.0:
+; RV64-NEXT: addi sp, sp, -32
+; RV64-NEXT: .cfi_def_cfa_offset 32
+; RV64-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset t0, -24
+; RV64-NEXT: csrr t0, mepc
+; RV64-NEXT: sd t0, 24(sp) # 8-byte Folded Spill
+; RV64-NEXT: csrrsi t0, mistatus, 1
+; RV64-NEXT: sd t0, 16(sp) # 8-byte Folded Spill
+; RV64-NEXT: sw zero, 4(sp)
+; RV64-NEXT: ld t0, 16(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw mistatus, t0
+; RV64-NEXT: ld t0, 24(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw mepc, t0
+; RV64-NEXT: ld t0, 8(sp) # 8-byte Folded Reload
+; RV64-NEXT: .cfi_restore t0
+; RV64-NEXT: addi sp, sp, 32
+; RV64-NEXT: .cfi_def_cfa_offset 0
+; RV64-NEXT: mret
+ %slot = alloca i32
+ store volatile i32 0, ptr %slot
+ ret void
+}
+
+define void @s_preemptible() #1 {
+; RV32-LABEL: s_preemptible:
+; RV32: # %bb.0:
+; RV32-NEXT: addi sp, sp, -16
+; RV32-NEXT: .cfi_def_cfa_offset 16
+; RV32-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset t0, -12
+; RV32-NEXT: csrr t0, sepc
+; RV32-NEXT: sw t0, 12(sp) # 4-byte Folded Spill
+; RV32-NEXT: csrrsi t0, sistatus, 1
+; RV32-NEXT: sw t0, 8(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw zero, 0(sp)
+; RV32-NEXT: lw t0, 8(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw sistatus, t0
+; RV32-NEXT: lw t0, 12(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw sepc, t0
+; RV32-NEXT: lw t0, 4(sp) # 4-byte Folded Reload
+; RV32-NEXT: .cfi_restore t0
+; RV32-NEXT: addi sp, sp, 16
+; RV32-NEXT: .cfi_def_cfa_offset 0
+; RV32-NEXT: sret
+;
+; RV32E-LABEL: s_preemptible:
+; RV32E: # %bb.0:
+; RV32E-NEXT: addi sp, sp, -16
+; RV32E-NEXT: .cfi_def_cfa_offset 16
+; RV32E-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset t0, -12
+; RV32E-NEXT: csrr t0, sepc
+; RV32E-NEXT: sw t0, 12(sp) # 4-byte Folded Spill
+; RV32E-NEXT: csrrsi t0, sistatus, 1
+; RV32E-NEXT: sw t0, 8(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw zero, 0(sp)
+; RV32E-NEXT: lw t0, 8(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw sistatus, t0
+; RV32E-NEXT: lw t0, 12(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw sepc, t0
+; RV32E-NEXT: lw t0, 4(sp) # 4-byte Folded Reload
+; RV32E-NEXT: .cfi_restore t0
+; RV32E-NEXT: addi sp, sp, 16
+; RV32E-NEXT: .cfi_def_cfa_offset 0
+; RV32E-NEXT: sret
+;
+; RV64-LABEL: s_preemptible:
+; RV64: # %bb.0:
+; RV64-NEXT: addi sp, sp, -32
+; RV64-NEXT: .cfi_def_cfa_offset 32
+; RV64-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset t0, -24
+; RV64-NEXT: csrr t0, sepc
+; RV64-NEXT: sd t0, 24(sp) # 8-byte Folded Spill
+; RV64-NEXT: csrrsi t0, sistatus, 1
+; RV64-NEXT: sd t0, 16(sp) # 8-byte Folded Spill
+; RV64-NEXT: sw zero, 4(sp)
+; RV64-NEXT: ld t0, 16(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw sistatus, t0
+; RV64-NEXT: ld t0, 24(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw sepc, t0
+; RV64-NEXT: ld t0, 8(sp) # 8-byte Folded Reload
+; RV64-NEXT: .cfi_restore t0
+; RV64-NEXT: addi sp, sp, 32
+; RV64-NEXT: .cfi_def_cfa_offset 0
+; RV64-NEXT: sret
+ %slot = alloca i32
+ store volatile i32 0, ptr %slot
+ ret void
+}
+
+define void @m_push_pop() #2 {
+; RV32-LABEL: m_push_pop:
+; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: addi sp, sp, -48
+; RV32-NEXT: .cfi_def_cfa_offset 80
+; RV32-NEXT: sw ra, 44(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t0, 40(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t1, 36(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t2, 32(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a6, 28(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a7, 24(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t3, 20(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t4, 16(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t5, 12(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t6, 8(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset ra, -36
+; RV32-NEXT: .cfi_offset t0, -40
+; RV32-NEXT: .cfi_offset t1, -44
+; RV32-NEXT: .cfi_offset t2, -48
+; RV32-NEXT: .cfi_offset a6, -52
+; RV32-NEXT: .cfi_offset a7, -56
+; RV32-NEXT: .cfi_offset t3, -60
+; RV32-NEXT: .cfi_offset t4, -64
+; RV32-NEXT: .cfi_offset t5, -68
+; RV32-NEXT: .cfi_offset t6, -72
+; RV32-NEXT: call callee
+; RV32-NEXT: lw ra, 44(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t0, 40(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t1, 36(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t2, 32(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a6, 28(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a7, 24(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t3, 20(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t4, 16(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t5, 12(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t6, 8(sp) # 4-byte Folded Reload
+; RV32-NEXT: .cfi_restore ra
+; RV32-NEXT: .cfi_restore t0
+; RV32-NEXT: .cfi_restore t1
+; RV32-NEXT: .cfi_restore t2
+; RV32-NEXT: .cfi_restore a6
+; RV32-NEXT: .cfi_restore a7
+; RV32-NEXT: .cfi_restore t3
+; RV32-NEXT: .cfi_restore t4
+; RV32-NEXT: .cfi_restore t5
+; RV32-NEXT: .cfi_restore t6
+; RV32-NEXT: addi sp, sp, 48
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: mipopret
+;
+; RV32E-LABEL: m_push_pop:
+; RV32E: # %bb.0:
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: addi sp, sp, -16
+; RV32E-NEXT: .cfi_def_cfa_offset 40
+; RV32E-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw t0, 8(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw t1, 4(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw t2, 0(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset ra, -28
+; RV32E-NEXT: .cfi_offset t0, -32
+; RV32E-NEXT: .cfi_offset t1, -36
+; RV32E-NEXT: .cfi_offset t2, -40
+; RV32E-NEXT: call callee
+; RV32E-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t0, 8(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t1, 4(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t2, 0(sp) # 4-byte Folded Reload
+; RV32E-NEXT: .cfi_restore ra
+; RV32E-NEXT: .cfi_restore t0
+; RV32E-NEXT: .cfi_restore t1
+; RV32E-NEXT: .cfi_restore t2
+; RV32E-NEXT: addi sp, sp, 16
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: mipopret
+;
+; RV64-LABEL: m_push_pop:
+; RV64: # %bb.0:
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: addi sp, sp, -80
+; RV64-NEXT: .cfi_def_cfa_offset 128
+; RV64-NEXT: sd ra, 72(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t0, 64(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t1, 56(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t2, 48(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a6, 40(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a7, 32(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t3, 24(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t4, 16(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t5, 8(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t6, 0(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset ra, -56
+; RV64-NEXT: .cfi_offset t0, -64
+; RV64-NEXT: .cfi_offset t1, -72
+; RV64-NEXT: .cfi_offset t2, -80
+; RV64-NEXT: .cfi_offset a6, -88
+; RV64-NEXT: .cfi_offset a7, -96
+; RV64-NEXT: .cfi_offset t3, -104
+; RV64-NEXT: .cfi_offset t4, -112
+; RV64-NEXT: .cfi_offset t5, -120
+; RV64-NEXT: .cfi_offset t6, -128
+; RV64-NEXT: call callee
+; RV64-NEXT: ld ra, 72(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t0, 64(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t1, 56(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t2, 48(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a6, 40(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a7, 32(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t3, 24(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t4, 16(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t5, 8(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t6, 0(sp) # 8-byte Folded Reload
+; RV64-NEXT: .cfi_restore ra
+; RV64-NEXT: .cfi_restore t0
+; RV64-NEXT: .cfi_restore t1
+; RV64-NEXT: .cfi_restore t2
+; RV64-NEXT: .cfi_restore a6
+; RV64-NEXT: .cfi_restore a7
+; RV64-NEXT: .cfi_restore t3
+; RV64-NEXT: .cfi_restore t4
+; RV64-NEXT: .cfi_restore t5
+; RV64-NEXT: .cfi_restore t6
+; RV64-NEXT: addi sp, sp, 80
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: mipopret
+ call void @callee()
+ ret void
+}
+
+define void @s_push_pop() #3 {
+; RV32-LABEL: s_push_pop:
+; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: addi sp, sp, -48
+; RV32-NEXT: .cfi_def_cfa_offset 80
+; RV32-NEXT: sw ra, 44(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t0, 40(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t1, 36(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t2, 32(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a6, 28(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a7, 24(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t3, 20(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t4, 16(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t5, 12(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t6, 8(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset ra, -36
+; RV32-NEXT: .cfi_offset t0, -40
+; RV32-NEXT: .cfi_offset t1, -44
+; RV32-NEXT: .cfi_offset t2, -48
+; RV32-NEXT: .cfi_offset a6, -52
+; RV32-NEXT: .cfi_offset a7, -56
+; RV32-NEXT: .cfi_offset t3, -60
+; RV32-NEXT: .cfi_offset t4, -64
+; RV32-NEXT: .cfi_offset t5, -68
+; RV32-NEXT: .cfi_offset t6, -72
+; RV32-NEXT: call callee
+; RV32-NEXT: lw ra, 44(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t0, 40(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t1, 36(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t2, 32(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a6, 28(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a7, 24(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t3, 20(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t4, 16(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t5, 12(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t6, 8(sp) # 4-byte Folded Reload
+; RV32-NEXT: .cfi_restore ra
+; RV32-NEXT: .cfi_restore t0
+; RV32-NEXT: .cfi_restore t1
+; RV32-NEXT: .cfi_restore t2
+; RV32-NEXT: .cfi_restore a6
+; RV32-NEXT: .cfi_restore a7
+; RV32-NEXT: .cfi_restore t3
+; RV32-NEXT: .cfi_restore t4
+; RV32-NEXT: .cfi_restore t5
+; RV32-NEXT: .cfi_restore t6
+; RV32-NEXT: addi sp, sp, 48
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: sipopret
+;
+; RV32E-LABEL: s_push_pop:
+; RV32E: # %bb.0:
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: addi sp, sp, -16
+; RV32E-NEXT: .cfi_def_cfa_offset 40
+; RV32E-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw t0, 8(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw t1, 4(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw t2, 0(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset ra, -28
+; RV32E-NEXT: .cfi_offset t0, -32
+; RV32E-NEXT: .cfi_offset t1, -36
+; RV32E-NEXT: .cfi_offset t2, -40
+; RV32E-NEXT: call callee
+; RV32E-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t0, 8(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t1, 4(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t2, 0(sp) # 4-byte Folded Reload
+; RV32E-NEXT: .cfi_restore ra
+; RV32E-NEXT: .cfi_restore t0
+; RV32E-NEXT: .cfi_restore t1
+; RV32E-NEXT: .cfi_restore t2
+; RV32E-NEXT: addi sp, sp, 16
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: sipopret
+;
+; RV64-LABEL: s_push_pop:
+; RV64: # %bb.0:
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: addi sp, sp, -80
+; RV64-NEXT: .cfi_def_cfa_offset 128
+; RV64-NEXT: sd ra, 72(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t0, 64(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t1, 56(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t2, 48(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a6, 40(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a7, 32(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t3, 24(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t4, 16(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t5, 8(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t6, 0(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset ra, -56
+; RV64-NEXT: .cfi_offset t0, -64
+; RV64-NEXT: .cfi_offset t1, -72
+; RV64-NEXT: .cfi_offset t2, -80
+; RV64-NEXT: .cfi_offset a6, -88
+; RV64-NEXT: .cfi_offset a7, -96
+; RV64-NEXT: .cfi_offset t3, -104
+; RV64-NEXT: .cfi_offset t4, -112
+; RV64-NEXT: .cfi_offset t5, -120
+; RV64-NEXT: .cfi_offset t6, -128
+; RV64-NEXT: call callee
+; RV64-NEXT: ld ra, 72(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t0, 64(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t1, 56(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t2, 48(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a6, 40(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a7, 32(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t3, 24(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t4, 16(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t5, 8(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t6, 0(sp) # 8-byte Folded Reload
+; RV64-NEXT: .cfi_restore ra
+; RV64-NEXT: .cfi_restore t0
+; RV64-NEXT: .cfi_restore t1
+; RV64-NEXT: .cfi_restore t2
+; RV64-NEXT: .cfi_restore a6
+; RV64-NEXT: .cfi_restore a7
+; RV64-NEXT: .cfi_restore t3
+; RV64-NEXT: .cfi_restore t4
+; RV64-NEXT: .cfi_restore t5
+; RV64-NEXT: .cfi_restore t6
+; RV64-NEXT: addi sp, sp, 80
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: sipopret
+ call void @callee()
+ ret void
+}
+
+define void @m_combined() #4 {
+; RV32-LABEL: m_combined:
+; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: addi sp, sp, -16
+; RV32-NEXT: .cfi_def_cfa_offset 48
+; RV32-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset t0, -44
+; RV32-NEXT: csrr t0, mepc
+; RV32-NEXT: sw t0, 12(sp) # 4-byte Folded Spill
+; RV32-NEXT: csrrsi t0, mistatus, 1
+; RV32-NEXT: sw t0, 8(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw zero, 0(sp)
+; RV32-NEXT: lw t0, 8(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw mistatus, t0
+; RV32-NEXT: lw t0, 12(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw mepc, t0
+; RV32-NEXT: lw t0, 4(sp) # 4-byte Folded Reload
+; RV32-NEXT: .cfi_restore t0
+; RV32-NEXT: addi sp, sp, 16
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: mipopret
+;
+; RV32E-LABEL: m_combined:
+; RV32E: # %bb.0:
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: addi sp, sp, -16
+; RV32E-NEXT: .cfi_def_cfa_offset 40
+; RV32E-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset t0, -36
+; RV32E-NEXT: csrr t0, mepc
+; RV32E-NEXT: sw t0, 12(sp) # 4-byte Folded Spill
+; RV32E-NEXT: csrrsi t0, mistatus, 1
+; RV32E-NEXT: sw t0, 8(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw zero, 0(sp)
+; RV32E-NEXT: lw t0, 8(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw mistatus, t0
+; RV32E-NEXT: lw t0, 12(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw mepc, t0
+; RV32E-NEXT: lw t0, 4(sp) # 4-byte Folded Reload
+; RV32E-NEXT: .cfi_restore t0
+; RV32E-NEXT: addi sp, sp, 16
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: mipopret
+;
+; RV64-LABEL: m_combined:
+; RV64: # %bb.0:
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: addi sp, sp, -32
+; RV64-NEXT: .cfi_def_cfa_offset 80
+; RV64-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset t0, -72
+; RV64-NEXT: csrr t0, mepc
+; RV64-NEXT: sd t0, 24(sp) # 8-byte Folded Spill
+; RV64-NEXT: csrrsi t0, mistatus, 1
+; RV64-NEXT: sd t0, 16(sp) # 8-byte Folded Spill
+; RV64-NEXT: sw zero, 4(sp)
+; RV64-NEXT: ld t0, 16(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw mistatus, t0
+; RV64-NEXT: ld t0, 24(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw mepc, t0
+; RV64-NEXT: ld t0, 8(sp) # 8-byte Folded Reload
+; RV64-NEXT: .cfi_restore t0
+; RV64-NEXT: addi sp, sp, 32
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: mipopret
+ %slot = alloca i32
+ store volatile i32 0, ptr %slot
+ ret void
+}
+
+define void @s_combined() #5 {
+; RV32-LABEL: s_combined:
+; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: addi sp, sp, -16
+; RV32-NEXT: .cfi_def_cfa_offset 48
+; RV32-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset t0, -44
+; RV32-NEXT: csrr t0, sepc
+; RV32-NEXT: sw t0, 12(sp) # 4-byte Folded Spill
+; RV32-NEXT: csrrsi t0, sistatus, 1
+; RV32-NEXT: sw t0, 8(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw zero, 0(sp)
+; RV32-NEXT: lw t0, 8(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw sistatus, t0
+; RV32-NEXT: lw t0, 12(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw sepc, t0
+; RV32-NEXT: lw t0, 4(sp) # 4-byte Folded Reload
+; RV32-NEXT: .cfi_restore t0
+; RV32-NEXT: addi sp, sp, 16
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: sipopret
+;
+; RV32E-LABEL: s_combined:
+; RV32E: # %bb.0:
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: addi sp, sp, -16
+; RV32E-NEXT: .cfi_def_cfa_offset 40
+; RV32E-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset t0, -36
+; RV32E-NEXT: csrr t0, sepc
+; RV32E-NEXT: sw t0, 12(sp) # 4-byte Folded Spill
+; RV32E-NEXT: csrrsi t0, sistatus, 1
+; RV32E-NEXT: sw t0, 8(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw zero, 0(sp)
+; RV32E-NEXT: lw t0, 8(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw sistatus, t0
+; RV32E-NEXT: lw t0, 12(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw sepc, t0
+; RV32E-NEXT: lw t0, 4(sp) # 4-byte Folded Reload
+; RV32E-NEXT: .cfi_restore t0
+; RV32E-NEXT: addi sp, sp, 16
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: sipopret
+;
+; RV64-LABEL: s_combined:
+; RV64: # %bb.0:
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: addi sp, sp, -32
+; RV64-NEXT: .cfi_def_cfa_offset 80
+; RV64-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset t0, -72
+; RV64-NEXT: csrr t0, sepc
+; RV64-NEXT: sd t0, 24(sp) # 8-byte Folded Spill
+; RV64-NEXT: csrrsi t0, sistatus, 1
+; RV64-NEXT: sd t0, 16(sp) # 8-byte Folded Spill
+; RV64-NEXT: sw zero, 4(sp)
+; RV64-NEXT: ld t0, 16(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw sistatus, t0
+; RV64-NEXT: ld t0, 24(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw sepc, t0
+; RV64-NEXT: ld t0, 8(sp) # 8-byte Folded Reload
+; RV64-NEXT: .cfi_restore t0
+; RV64-NEXT: addi sp, sp, 32
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: sipopret
+ %slot = alloca i32
+ store volatile i32 0, ptr %slot
+ ret void
+}
+
+define void @m_push_pop_large() #2 {
+; RV32-LABEL: m_push_pop_large:
+; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: addi sp, sp, -2000
+; RV32-NEXT: .cfi_def_cfa_offset 2032
+; RV32-NEXT: sw ra, 1996(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t0, 1992(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t1, 1988(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t2, 1984(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a6, 1980(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a7, 1976(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t3, 1972(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t4, 1968(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t5, 1964(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw t6, 1960(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset ra, -36
+; RV32-NEXT: .cfi_offset t0, -40
+; RV32-NEXT: .cfi_offset t1, -44
+; RV32-NEXT: .cfi_offset t2, -48
+; RV32-NEXT: .cfi_offset a6, -52
+; RV32-NEXT: .cfi_offset a7, -56
+; RV32-NEXT: .cfi_offset t3, -60
+; RV32-NEXT: .cfi_offset t4, -64
+; RV32-NEXT: .cfi_offset t5, -68
+; RV32-NEXT: .cfi_offset t6, -72
+; RV32-NEXT: addi sp, sp, -2048
+; RV32-NEXT: addi sp, sp, -1008
+; RV32-NEXT: .cfi_def_cfa_offset 5088
+; RV32-NEXT: call callee
+; RV32-NEXT: sb zero, 16(sp)
+; RV32-NEXT: addi sp, sp, 2032
+; RV32-NEXT: addi sp, sp, 1024
+; RV32-NEXT: .cfi_def_cfa_offset 2032
+; RV32-NEXT: lw ra, 1996(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t0, 1992(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t1, 1988(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t2, 1984(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a6, 1980(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a7, 1976(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t3, 1972(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t4, 1968(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t5, 1964(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t6, 1960(sp) # 4-byte Folded Reload
+; RV32-NEXT: .cfi_restore ra
+; RV32-NEXT: .cfi_restore t0
+; RV32-NEXT: .cfi_restore t1
+; RV32-NEXT: .cfi_restore t2
+; RV32-NEXT: .cfi_restore a6
+; RV32-NEXT: .cfi_restore a7
+; RV32-NEXT: .cfi_restore t3
+; RV32-NEXT: .cfi_restore t4
+; RV32-NEXT: .cfi_restore t5
+; RV32-NEXT: .cfi_restore t6
+; RV32-NEXT: addi sp, sp, 2000
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: mipopret
+;
+; RV32E-LABEL: m_push_pop_large:
+; RV32E: # %bb.0:
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: addi sp, sp, -2020
+; RV32E-NEXT: .cfi_def_cfa_offset 2044
+; RV32E-NEXT: sw ra, 2016(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw t0, 2012(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw t1, 2008(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw t2, 2004(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset ra, -28
+; RV32E-NEXT: .cfi_offset t0, -32
+; RV32E-NEXT: .cfi_offset t1, -36
+; RV32E-NEXT: .cfi_offset t2, -40
+; RV32E-NEXT: addi sp, sp, -2048
+; RV32E-NEXT: addi sp, sp, -952
+; RV32E-NEXT: .cfi_def_cfa_offset 5044
+; RV32E-NEXT: call callee
+; RV32E-NEXT: sb zero, 4(sp)
+; RV32E-NEXT: addi sp, sp, 2044
+; RV32E-NEXT: addi sp, sp, 956
+; RV32E-NEXT: .cfi_def_cfa_offset 2044
+; RV32E-NEXT: lw ra, 2016(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t0, 2012(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t1, 2008(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t2, 2004(sp) # 4-byte Folded Reload
+; RV32E-NEXT: .cfi_restore ra
+; RV32E-NEXT: .cfi_restore t0
+; RV32E-NEXT: .cfi_restore t1
+; RV32E-NEXT: .cfi_restore t2
+; RV32E-NEXT: addi sp, sp, 2020
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: mipopret
+;
+; RV64-LABEL: m_push_pop_large:
+; RV64: # %bb.0:
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: addi sp, sp, -1984
+; RV64-NEXT: .cfi_def_cfa_offset 2032
+; RV64-NEXT: sd ra, 1976(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t0, 1968(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t1, 1960(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t2, 1952(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a6, 1944(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a7, 1936(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t3, 1928(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t4, 1920(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t5, 1912(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd t6, 1904(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset ra, -56
+; RV64-NEXT: .cfi_offset t0, -64
+; RV64-NEXT: .cfi_offset t1, -72
+; RV64-NEXT: .cfi_offset t2, -80
+; RV64-NEXT: .cfi_offset a6, -88
+; RV64-NEXT: .cfi_offset a7, -96
+; RV64-NEXT: .cfi_offset t3, -104
+; RV64-NEXT: .cfi_offset t4, -112
+; RV64-NEXT: .cfi_offset t5, -120
+; RV64-NEXT: .cfi_offset t6, -128
+; RV64-NEXT: addi sp, sp, -2048
+; RV64-NEXT: addi sp, sp, -1056
+; RV64-NEXT: .cfi_def_cfa_offset 5136
+; RV64-NEXT: call callee
+; RV64-NEXT: sb zero, 8(sp)
+; RV64-NEXT: addi sp, sp, 2032
+; RV64-NEXT: addi sp, sp, 1072
+; RV64-NEXT: .cfi_def_cfa_offset 2032
+; RV64-NEXT: ld ra, 1976(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t0, 1968(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t1, 1960(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t2, 1952(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a6, 1944(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a7, 1936(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t3, 1928(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t4, 1920(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t5, 1912(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t6, 1904(sp) # 8-byte Folded Reload
+; RV64-NEXT: .cfi_restore ra
+; RV64-NEXT: .cfi_restore t0
+; RV64-NEXT: .cfi_restore t1
+; RV64-NEXT: .cfi_restore t2
+; RV64-NEXT: .cfi_restore a6
+; RV64-NEXT: .cfi_restore a7
+; RV64-NEXT: .cfi_restore t3
+; RV64-NEXT: .cfi_restore t4
+; RV64-NEXT: .cfi_restore t5
+; RV64-NEXT: .cfi_restore t6
+; RV64-NEXT: addi sp, sp, 1984
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: mipopret
+ %slot = alloca [5000 x i8]
+ call void @callee()
+ store volatile i8 0, ptr %slot
+ ret void
+}
+
+define void @m_push_pop_empty() #6 {
+; RV32-LABEL: m_push_pop_empty:
+; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: mipopret
+;
+; RV32E-LABEL: m_push_pop_empty:
+; RV32E: # %bb.0:
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: mipopret
+;
+; RV64-LABEL: m_push_pop_empty:
+; RV64: # %bb.0:
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: mipopret
+ ret void
+}
+
+define void @s_push_pop_empty() #7 {
+; RV32-LABEL: s_push_pop_empty:
+; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: sipopret
+;
+; RV32E-LABEL: s_push_pop_empty:
+; RV32E: # %bb.0:
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: sipopret
+;
+; RV64-LABEL: s_push_pop_empty:
+; RV64: # %bb.0:
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: sipopret
+ ret void
+}
+
+define void @m_push_pop_fp() #8 {
+; RV32-LABEL: m_push_pop_fp:
+; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: addi sp, sp, -16
+; RV32-NEXT: .cfi_def_cfa_offset 48
+; RV32-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset ra, -36
+; RV32-NEXT: .cfi_offset s0, -40
+; RV32-NEXT: addi s0, sp, 48
+; RV32-NEXT: .cfi_def_cfa s0, 0
+; RV32-NEXT: sw zero, 4(sp)
+; RV32-NEXT: .cfi_def_cfa sp, 48
+; RV32-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
+; RV32-NEXT: .cfi_restore ra
+; RV32-NEXT: .cfi_restore s0
+; RV32-NEXT: addi sp, sp, 16
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: mipopret
+;
+; RV32E-LABEL: m_push_pop_fp:
+; RV32E: # %bb.0:
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: addi sp, sp, -12
+; RV32E-NEXT: .cfi_def_cfa_offset 36
+; RV32E-NEXT: sw ra, 8(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw s0, 4(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset ra, -28
+; RV32E-NEXT: .cfi_offset s0, -32
+; RV32E-NEXT: addi s0, sp, 36
+; RV32E-NEXT: .cfi_def_cfa s0, 0
+; RV32E-NEXT: sw zero, 0(sp)
+; RV32E-NEXT: .cfi_def_cfa sp, 36
+; RV32E-NEXT: lw ra, 8(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw s0, 4(sp) # 4-byte Folded Reload
+; RV32E-NEXT: .cfi_restore ra
+; RV32E-NEXT: .cfi_restore s0
+; RV32E-NEXT: addi sp, sp, 12
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: mipopret
+;
+; RV64-LABEL: m_push_pop_fp:
+; RV64: # %bb.0:
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: addi sp, sp, -32
+; RV64-NEXT: .cfi_def_cfa_offset 80
+; RV64-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd s0, 16(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset ra, -56
+; RV64-NEXT: .cfi_offset s0, -64
+; RV64-NEXT: addi s0, sp, 80
+; RV64-NEXT: .cfi_def_cfa s0, 0
+; RV64-NEXT: sw zero, 12(sp)
+; RV64-NEXT: .cfi_def_cfa sp, 80
+; RV64-NEXT: ld ra, 24(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld s0, 16(sp) # 8-byte Folded Reload
+; RV64-NEXT: .cfi_restore ra
+; RV64-NEXT: .cfi_restore s0
+; RV64-NEXT: addi sp, sp, 32
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: mipopret
+ %slot = alloca i32
+ store volatile i32 0, ptr %slot
+ ret void
+}
+
+attributes #0 = { "frame-pointer"="none" "interrupt"="machine-preemptible" }
+attributes #1 = { "frame-pointer"="none" "interrupt"="supervisor-preemptible" }
+attributes #2 = { "frame-pointer"="none" "interrupt"="machine-push-pop" }
+attributes #3 = { "frame-pointer"="none" "interrupt"="supervisor-push-pop" }
+attributes #4 = { "frame-pointer"="none" "interrupt"="machine-preemptible-push-pop" }
+attributes #5 = { "frame-pointer"="none" "interrupt"="supervisor-preemptible-push-pop" }
+attributes #6 = { "frame-pointer"="none" "interrupt"="machine-push-pop" uwtable }
+attributes #7 = { "frame-pointer"="none" "interrupt"="supervisor-push-pop" uwtable }
+attributes #8 = { "frame-pointer"="all" "interrupt"="machine-push-pop" }
diff --git a/llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll b/llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll
new file mode 100644
index 00000000000000..bfad186343a906
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll
@@ -0,0 +1,264 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=riscv32 -verify-machineinstrs \
+; RUN: -mattr=+experimental-smnip,+experimental-ssnip,+experimental-smip,+experimental-ssip \
+; RUN: < %s | FileCheck %s --check-prefix=RV32
+; RUN: llc -mtriple=riscv32 -target-abi=ilp32e -verify-machineinstrs \
+; RUN: -mattr=+e,+experimental-smnip,+experimental-ssnip,+experimental-smip,+experimental-ssip \
+; RUN: < %s | FileCheck %s --check-prefix=RV32E
+; RUN: llc -mtriple=riscv64 -verify-machineinstrs \
+; RUN: -mattr=+experimental-smnip,+experimental-ssnip,+experimental-smip,+experimental-ssip \
+; RUN: < %s | FileCheck %s --check-prefix=RV64
+
+define void @m_preemptible_fp_large() #0 {
+; RV32-LABEL: m_preemptible_fp_large:
+; RV32: # %bb.0:
+; RV32-NEXT: addi sp, sp, -2032
+; RV32-NEXT: .cfi_def_cfa_offset 2032
+; RV32-NEXT: sw t0, 2016(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset t0, -16
+; RV32-NEXT: csrr t0, mepc
+; RV32-NEXT: sw t0, 2028(sp) # 4-byte Folded Spill
+; RV32-NEXT: csrrsi t0, mistatus, 1
+; RV32-NEXT: sw t0, 2024(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw ra, 2020(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw s0, 2012(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a0, 2008(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw a1, 2004(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset ra, -12
+; RV32-NEXT: .cfi_offset s0, -20
+; RV32-NEXT: .cfi_offset a0, -24
+; RV32-NEXT: .cfi_offset a1, -28
+; RV32-NEXT: addi s0, sp, 2032
+; RV32-NEXT: .cfi_def_cfa s0, 0
+; RV32-NEXT: addi sp, sp, -2048
+; RV32-NEXT: addi sp, sp, -48
+; RV32-NEXT: lui a0, 1
+; RV32-NEXT: mv a1, sp
+; RV32-NEXT: add a0, a1, a0
+; RV32-NEXT: sb zero, -1(a0)
+; RV32-NEXT: addi sp, sp, 2032
+; RV32-NEXT: addi sp, sp, 64
+; RV32-NEXT: .cfi_def_cfa sp, 2032
+; RV32-NEXT: lw ra, 2020(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw s0, 2012(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a0, 2008(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw a1, 2004(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t0, 2024(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw mistatus, t0
+; RV32-NEXT: lw t0, 2028(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw mepc, t0
+; RV32-NEXT: lw t0, 2016(sp) # 4-byte Folded Reload
+; RV32-NEXT: .cfi_restore t0
+; RV32-NEXT: .cfi_restore ra
+; RV32-NEXT: .cfi_restore s0
+; RV32-NEXT: .cfi_restore a0
+; RV32-NEXT: .cfi_restore a1
+; RV32-NEXT: addi sp, sp, 2032
+; RV32-NEXT: .cfi_def_cfa_offset 0
+; RV32-NEXT: mret
+;
+; RV32E-LABEL: m_preemptible_fp_large:
+; RV32E: # %bb.0:
+; RV32E-NEXT: addi sp, sp, -2044
+; RV32E-NEXT: .cfi_def_cfa_offset 2044
+; RV32E-NEXT: sw t0, 2028(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset t0, -16
+; RV32E-NEXT: csrr t0, mepc
+; RV32E-NEXT: sw t0, 2040(sp) # 4-byte Folded Spill
+; RV32E-NEXT: csrrsi t0, mistatus, 1
+; RV32E-NEXT: sw t0, 2036(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw ra, 2032(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw s0, 2024(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a0, 2020(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw a1, 2016(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset ra, -12
+; RV32E-NEXT: .cfi_offset s0, -20
+; RV32E-NEXT: .cfi_offset a0, -24
+; RV32E-NEXT: .cfi_offset a1, -28
+; RV32E-NEXT: addi s0, sp, 2044
+; RV32E-NEXT: .cfi_def_cfa s0, 0
+; RV32E-NEXT: addi sp, sp, -2048
+; RV32E-NEXT: addi sp, sp, -52
+; RV32E-NEXT: andi sp, sp, -16
+; RV32E-NEXT: lui a0, 1
+; RV32E-NEXT: addi a1, sp, 16
+; RV32E-NEXT: add a0, a1, a0
+; RV32E-NEXT: sb zero, -1(a0)
+; RV32E-NEXT: addi sp, s0, -2044
+; RV32E-NEXT: .cfi_def_cfa sp, 2044
+; RV32E-NEXT: lw ra, 2032(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw s0, 2024(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a0, 2020(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw a1, 2016(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t0, 2036(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw mistatus, t0
+; RV32E-NEXT: lw t0, 2040(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw mepc, t0
+; RV32E-NEXT: lw t0, 2028(sp) # 4-byte Folded Reload
+; RV32E-NEXT: .cfi_restore t0
+; RV32E-NEXT: .cfi_restore ra
+; RV32E-NEXT: .cfi_restore s0
+; RV32E-NEXT: .cfi_restore a0
+; RV32E-NEXT: .cfi_restore a1
+; RV32E-NEXT: addi sp, sp, 2044
+; RV32E-NEXT: .cfi_def_cfa_offset 0
+; RV32E-NEXT: mret
+;
+; RV64-LABEL: m_preemptible_fp_large:
+; RV64: # %bb.0:
+; RV64-NEXT: addi sp, sp, -2032
+; RV64-NEXT: .cfi_def_cfa_offset 2032
+; RV64-NEXT: sd t0, 2000(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset t0, -32
+; RV64-NEXT: csrr t0, mepc
+; RV64-NEXT: sd t0, 2024(sp) # 8-byte Folded Spill
+; RV64-NEXT: csrrsi t0, mistatus, 1
+; RV64-NEXT: sd t0, 2016(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd ra, 2008(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd s0, 1992(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a0, 1984(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd a1, 1976(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset ra, -24
+; RV64-NEXT: .cfi_offset s0, -40
+; RV64-NEXT: .cfi_offset a0, -48
+; RV64-NEXT: .cfi_offset a1, -56
+; RV64-NEXT: addi s0, sp, 2032
+; RV64-NEXT: .cfi_def_cfa s0, 0
+; RV64-NEXT: addi sp, sp, -2048
+; RV64-NEXT: addi sp, sp, -80
+; RV64-NEXT: lui a0, 1
+; RV64-NEXT: mv a1, sp
+; RV64-NEXT: add a0, a1, a0
+; RV64-NEXT: sb zero, -1(a0)
+; RV64-NEXT: addi sp, sp, 2032
+; RV64-NEXT: addi sp, sp, 96
+; RV64-NEXT: .cfi_def_cfa sp, 2032
+; RV64-NEXT: ld ra, 2008(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld s0, 1992(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a0, 1984(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld a1, 1976(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t0, 2016(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw mistatus, t0
+; RV64-NEXT: ld t0, 2024(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw mepc, t0
+; RV64-NEXT: ld t0, 2000(sp) # 8-byte Folded Reload
+; RV64-NEXT: .cfi_restore t0
+; RV64-NEXT: .cfi_restore ra
+; RV64-NEXT: .cfi_restore s0
+; RV64-NEXT: .cfi_restore a0
+; RV64-NEXT: .cfi_restore a1
+; RV64-NEXT: addi sp, sp, 2032
+; RV64-NEXT: .cfi_def_cfa_offset 0
+; RV64-NEXT: mret
+ %frame = alloca [4096 x i8], align 16
+ %end = getelementptr [4096 x i8], ptr %frame, i32 0, i32 4095
+ store volatile i8 0, ptr %end
+ ret void
+}
+
+define void @s_preemptible_push_pop_fp() #1 {
+; RV32-LABEL: s_preemptible_push_pop_fp:
+; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: addi sp, sp, -32
+; RV32-NEXT: .cfi_def_cfa_offset 64
+; RV32-NEXT: sw t0, 16(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset t0, -48
+; RV32-NEXT: csrr t0, sepc
+; RV32-NEXT: sw t0, 28(sp) # 4-byte Folded Spill
+; RV32-NEXT: csrrsi t0, sistatus, 1
+; RV32-NEXT: sw t0, 24(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw ra, 20(sp) # 4-byte Folded Spill
+; RV32-NEXT: sw s0, 12(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset ra, -44
+; RV32-NEXT: .cfi_offset s0, -52
+; RV32-NEXT: addi s0, sp, 64
+; RV32-NEXT: .cfi_def_cfa s0, 0
+; RV32-NEXT: sw zero, 8(sp)
+; RV32-NEXT: .cfi_def_cfa sp, 64
+; RV32-NEXT: lw ra, 20(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw s0, 12(sp) # 4-byte Folded Reload
+; RV32-NEXT: lw t0, 24(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw sistatus, t0
+; RV32-NEXT: lw t0, 28(sp) # 4-byte Folded Reload
+; RV32-NEXT: csrw sepc, t0
+; RV32-NEXT: lw t0, 16(sp) # 4-byte Folded Reload
+; RV32-NEXT: .cfi_restore t0
+; RV32-NEXT: .cfi_restore ra
+; RV32-NEXT: .cfi_restore s0
+; RV32-NEXT: addi sp, sp, 32
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: sipopret
+;
+; RV32E-LABEL: s_preemptible_push_pop_fp:
+; RV32E: # %bb.0:
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: addi sp, sp, -24
+; RV32E-NEXT: .cfi_def_cfa_offset 48
+; RV32E-NEXT: sw t0, 8(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset t0, -40
+; RV32E-NEXT: csrr t0, sepc
+; RV32E-NEXT: sw t0, 20(sp) # 4-byte Folded Spill
+; RV32E-NEXT: csrrsi t0, sistatus, 1
+; RV32E-NEXT: sw t0, 16(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
+; RV32E-NEXT: sw s0, 4(sp) # 4-byte Folded Spill
+; RV32E-NEXT: .cfi_offset ra, -36
+; RV32E-NEXT: .cfi_offset s0, -44
+; RV32E-NEXT: addi s0, sp, 48
+; RV32E-NEXT: .cfi_def_cfa s0, 0
+; RV32E-NEXT: sw zero, 0(sp)
+; RV32E-NEXT: .cfi_def_cfa sp, 48
+; RV32E-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw s0, 4(sp) # 4-byte Folded Reload
+; RV32E-NEXT: lw t0, 16(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw sistatus, t0
+; RV32E-NEXT: lw t0, 20(sp) # 4-byte Folded Reload
+; RV32E-NEXT: csrw sepc, t0
+; RV32E-NEXT: lw t0, 8(sp) # 4-byte Folded Reload
+; RV32E-NEXT: .cfi_restore t0
+; RV32E-NEXT: .cfi_restore ra
+; RV32E-NEXT: .cfi_restore s0
+; RV32E-NEXT: addi sp, sp, 24
+; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: sipopret
+;
+; RV64-LABEL: s_preemptible_push_pop_fp:
+; RV64: # %bb.0:
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: addi sp, sp, -48
+; RV64-NEXT: .cfi_def_cfa_offset 96
+; RV64-NEXT: sd t0, 16(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset t0, -80
+; RV64-NEXT: csrr t0, sepc
+; RV64-NEXT: sd t0, 40(sp) # 8-byte Folded Spill
+; RV64-NEXT: csrrsi t0, sistatus, 1
+; RV64-NEXT: sd t0, 32(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
+; RV64-NEXT: sd s0, 8(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset ra, -72
+; RV64-NEXT: .cfi_offset s0, -88
+; RV64-NEXT: addi s0, sp, 96
+; RV64-NEXT: .cfi_def_cfa s0, 0
+; RV64-NEXT: sw zero, 4(sp)
+; RV64-NEXT: .cfi_def_cfa sp, 96
+; RV64-NEXT: ld ra, 24(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld s0, 8(sp) # 8-byte Folded Reload
+; RV64-NEXT: ld t0, 32(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw sistatus, t0
+; RV64-NEXT: ld t0, 40(sp) # 8-byte Folded Reload
+; RV64-NEXT: csrw sepc, t0
+; RV64-NEXT: ld t0, 16(sp) # 8-byte Folded Reload
+; RV64-NEXT: .cfi_restore t0
+; RV64-NEXT: .cfi_restore ra
+; RV64-NEXT: .cfi_restore s0
+; RV64-NEXT: addi sp, sp, 48
+; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: sipopret
+ %slot = alloca i32
+ store volatile i32 0, ptr %slot
+ ret void
+}
+
+attributes #0 = { "frame-pointer"="all" "interrupt"="machine-preemptible" }
+attributes #1 = { "frame-pointer"="all" "interrupt"="supervisor-preemptible-push-pop" }
>From 9bb9e80c9ccd04691ba571a3b2985b07ed9306c8 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <mitchell.xu2 at gmail.com>
Date: Mon, 9 Nov 2026 09:56:23 +0800
Subject: [PATCH 2/3] address review feedback
---
clang/lib/Sema/SemaRISCV.cpp | 8 +-
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 18 +-
.../Target/RISCV/RISCVMachineFunctionInfo.h | 5 +-
.../CodeGen/RISCV/aclic-interrupt-attr.ll | 319 ++++++++++++++++++
4 files changed, 331 insertions(+), 19 deletions(-)
diff --git a/clang/lib/Sema/SemaRISCV.cpp b/clang/lib/Sema/SemaRISCV.cpp
index 0213d9f78fc61e..3a6bba1a38c402 100644
--- a/clang/lib/Sema/SemaRISCV.cpp
+++ b/clang/lib/Sema/SemaRISCV.cpp
@@ -1744,17 +1744,13 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
return;
}
- if (HasUnaryType && HasSiFiveCLICType) {
- Diag(AL.getLoc(), diag::err_riscv_attribute_interrupt_invalid_combination);
- return;
- }
-
if (HasMachine && HasSupervisor) {
Diag(AL.getLoc(), diag::err_riscv_attribute_interrupt_invalid_combination);
return;
}
- if (HasSiFiveCLICType && (HasSupervisor || HasPreemptible || HasPushPop)) {
+ if (HasSiFiveCLICType &&
+ (HasUnaryType || HasSupervisor || HasPreemptible || HasPushPop)) {
Diag(AL.getLoc(), diag::err_riscv_attribute_interrupt_invalid_combination);
return;
}
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index a2e293c3fb500d..68b1cde9798659 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -75,7 +75,7 @@ static const MCPhysReg FixedCSRFIMap[] = {
static constexpr uint64_t QCIInterruptPushAmount = 96;
// Smip/Ssip push six registers. ACLIC specifies a 24-byte frame for RV32E,
-// a 32-byte frame for RV32I, and a 48-byte frame for RV64.
+// a 32-byte frame for RV32I, and a 48-byte frame for RV64I/E.
static uint64_t getACLICInterruptPushAmount(const MachineFunction &MF) {
const auto &STI = MF.getSubtarget<RISCVSubtarget>();
if (STI.is64Bit())
@@ -417,8 +417,7 @@ static void emitACLICPreemptibleSaves(MachineFunction &MF,
CFIInstBuilder(MBB, MBBI, MachineInstr::FrameSetup)
.buildOffset(RISCV::X5, MF.getFrameInfo().getObjectOffset(ScratchFI));
- BuildMI(MBB, MBBI, DL, TII->get(RISCV::CSRRS))
- .addReg(RISCV::X5, RegState::Define)
+ BuildMI(MBB, MBBI, DL, TII->get(RISCV::CSRRS), RISCV::X5)
.addImm(EpcCSR)
.addReg(RISCV::X0)
.setMIFlag(MachineInstr::FrameSetup);
@@ -428,8 +427,7 @@ static void emitACLICPreemptibleSaves(MachineFunction &MF,
// xistatus.xie is bit zero. CSRRSI returns the old status in X5 and enables
// interrupts after that value has been captured.
- BuildMI(MBB, MBBI, DL, TII->get(RISCV::CSRRSI))
- .addReg(RISCV::X5, RegState::Define)
+ BuildMI(MBB, MBBI, DL, TII->get(RISCV::CSRRSI), RISCV::X5)
.addImm(StatusCSR)
.addImm(1)
.setMIFlag(MachineInstr::FrameSetup);
@@ -460,8 +458,7 @@ static void emitACLICPreemptibleRestores(MachineFunction &MF,
RVFI->getInterruptCSRFrameIndex(1),
&RISCV::GPRRegClass, Register(),
RISCV::NoSubRegister, MachineInstr::FrameDestroy);
- BuildMI(MBB, MBBI, DL, TII->get(RISCV::CSRRW))
- .addReg(RISCV::X0, RegState::Define)
+ BuildMI(MBB, MBBI, DL, TII->get(RISCV::CSRRW), RISCV::X0)
.addImm(StatusCSR)
.addReg(RISCV::X5, RegState::Kill)
.setMIFlag(MachineInstr::FrameDestroy);
@@ -470,8 +467,7 @@ static void emitACLICPreemptibleRestores(MachineFunction &MF,
RVFI->getInterruptCSRFrameIndex(0),
&RISCV::GPRRegClass, Register(),
RISCV::NoSubRegister, MachineInstr::FrameDestroy);
- BuildMI(MBB, MBBI, DL, TII->get(RISCV::CSRRW))
- .addReg(RISCV::X0, RegState::Define)
+ BuildMI(MBB, MBBI, DL, TII->get(RISCV::CSRRW), RISCV::X0)
.addImm(EpcCSR)
.addReg(RISCV::X5, RegState::Kill)
.setMIFlag(MachineInstr::FrameDestroy);
@@ -2395,6 +2391,10 @@ RISCVFrameLowering::getFirstSPAdjustAmount(const MachineFunction &MF) const {
// Disable SplitSPAdjust if save-restore libcall, push/pop or QCI interrupts
// are used. The callee-saved registers will be pushed by the save-restore
// libcalls, so we don't have to split the SP adjustment in this case.
+ //
+ // ACLIC push-pop interrupts deliberately allow the split: Smip/Ssip
+ // only save a0-a5, so the remaining callee-saved registers are spilled in
+ // software.
if (RVFI->getLibCallStackSize() || RVFI->getRVPushStackSize() ||
RVFI->getQCIInterruptStackSize())
return 0;
diff --git a/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h b/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
index 65c9ab8b714e36..e45b76208abf0a 100644
--- a/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
+++ b/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
@@ -271,10 +271,7 @@ class RISCVMachineFunctionInfo : public MachineFunctionInfo {
return InterruptCSRFrameIndexes[Idx];
}
bool isInterruptCSRFrameIndex(int FI) const {
- for (int Index : InterruptCSRFrameIndexes)
- if (Index == FI)
- return true;
- return false;
+ return llvm::is_contained(InterruptCSRFrameIndexes, FI);
}
// Some Stack Management Variants automatically update FP in a frame-pointer
diff --git a/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
index aad68e62929794..35ec715352263e 100644
--- a/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
@@ -8,6 +8,9 @@
; RUN: llc -mtriple=riscv64 -verify-machineinstrs \
; RUN: -mattr=+experimental-smnip,+experimental-ssnip,+experimental-smip,+experimental-ssip \
; RUN: < %s | FileCheck %s --check-prefix=RV64
+; RUN: llc -mtriple=riscv64 -target-abi=lp64e -verify-machineinstrs \
+; RUN: -mattr=+e,+experimental-smnip,+experimental-ssnip,+experimental-smip,+experimental-ssip \
+; RUN: < %s | FileCheck %s --check-prefix=RV64E
declare void @callee()
@@ -232,6 +235,63 @@ define void @m_preemptible_call() #0 {
; RV64-NEXT: addi sp, sp, 144
; RV64-NEXT: .cfi_def_cfa_offset 0
; RV64-NEXT: mret
+;
+; RV64E-LABEL: m_preemptible_call:
+; RV64E: # %bb.0:
+; RV64E-NEXT: addi sp, sp, -96
+; RV64E-NEXT: .cfi_def_cfa_offset 96
+; RV64E-NEXT: sd t0, 64(sp) # 8-byte Folded Spill
+; RV64E-NEXT: .cfi_offset t0, -32
+; RV64E-NEXT: csrr t0, mepc
+; RV64E-NEXT: sd t0, 88(sp) # 8-byte Folded Spill
+; RV64E-NEXT: csrrsi t0, mistatus, 1
+; RV64E-NEXT: sd t0, 80(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd ra, 72(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd t1, 56(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd t2, 48(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd a0, 40(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd a1, 32(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd a2, 24(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd a3, 16(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd a4, 8(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd a5, 0(sp) # 8-byte Folded Spill
+; RV64E-NEXT: .cfi_offset ra, -24
+; RV64E-NEXT: .cfi_offset t1, -40
+; RV64E-NEXT: .cfi_offset t2, -48
+; RV64E-NEXT: .cfi_offset a0, -56
+; RV64E-NEXT: .cfi_offset a1, -64
+; RV64E-NEXT: .cfi_offset a2, -72
+; RV64E-NEXT: .cfi_offset a3, -80
+; RV64E-NEXT: .cfi_offset a4, -88
+; RV64E-NEXT: .cfi_offset a5, -96
+; RV64E-NEXT: call callee
+; RV64E-NEXT: ld ra, 72(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t1, 56(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t2, 48(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld a0, 40(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld a1, 32(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld a2, 24(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld a3, 16(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld a4, 8(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld a5, 0(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t0, 80(sp) # 8-byte Folded Reload
+; RV64E-NEXT: csrw mistatus, t0
+; RV64E-NEXT: ld t0, 88(sp) # 8-byte Folded Reload
+; RV64E-NEXT: csrw mepc, t0
+; RV64E-NEXT: ld t0, 64(sp) # 8-byte Folded Reload
+; RV64E-NEXT: .cfi_restore t0
+; RV64E-NEXT: .cfi_restore ra
+; RV64E-NEXT: .cfi_restore t1
+; RV64E-NEXT: .cfi_restore t2
+; RV64E-NEXT: .cfi_restore a0
+; RV64E-NEXT: .cfi_restore a1
+; RV64E-NEXT: .cfi_restore a2
+; RV64E-NEXT: .cfi_restore a3
+; RV64E-NEXT: .cfi_restore a4
+; RV64E-NEXT: .cfi_restore a5
+; RV64E-NEXT: addi sp, sp, 96
+; RV64E-NEXT: .cfi_def_cfa_offset 0
+; RV64E-NEXT: mret
call void @callee()
ret void
}
@@ -455,6 +515,63 @@ define void @s_preemptible_call() #1 {
; RV64-NEXT: addi sp, sp, 144
; RV64-NEXT: .cfi_def_cfa_offset 0
; RV64-NEXT: sret
+;
+; RV64E-LABEL: s_preemptible_call:
+; RV64E: # %bb.0:
+; RV64E-NEXT: addi sp, sp, -96
+; RV64E-NEXT: .cfi_def_cfa_offset 96
+; RV64E-NEXT: sd t0, 64(sp) # 8-byte Folded Spill
+; RV64E-NEXT: .cfi_offset t0, -32
+; RV64E-NEXT: csrr t0, sepc
+; RV64E-NEXT: sd t0, 88(sp) # 8-byte Folded Spill
+; RV64E-NEXT: csrrsi t0, sistatus, 1
+; RV64E-NEXT: sd t0, 80(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd ra, 72(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd t1, 56(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd t2, 48(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd a0, 40(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd a1, 32(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd a2, 24(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd a3, 16(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd a4, 8(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd a5, 0(sp) # 8-byte Folded Spill
+; RV64E-NEXT: .cfi_offset ra, -24
+; RV64E-NEXT: .cfi_offset t1, -40
+; RV64E-NEXT: .cfi_offset t2, -48
+; RV64E-NEXT: .cfi_offset a0, -56
+; RV64E-NEXT: .cfi_offset a1, -64
+; RV64E-NEXT: .cfi_offset a2, -72
+; RV64E-NEXT: .cfi_offset a3, -80
+; RV64E-NEXT: .cfi_offset a4, -88
+; RV64E-NEXT: .cfi_offset a5, -96
+; RV64E-NEXT: call callee
+; RV64E-NEXT: ld ra, 72(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t1, 56(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t2, 48(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld a0, 40(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld a1, 32(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld a2, 24(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld a3, 16(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld a4, 8(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld a5, 0(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t0, 80(sp) # 8-byte Folded Reload
+; RV64E-NEXT: csrw sistatus, t0
+; RV64E-NEXT: ld t0, 88(sp) # 8-byte Folded Reload
+; RV64E-NEXT: csrw sepc, t0
+; RV64E-NEXT: ld t0, 64(sp) # 8-byte Folded Reload
+; RV64E-NEXT: .cfi_restore t0
+; RV64E-NEXT: .cfi_restore ra
+; RV64E-NEXT: .cfi_restore t1
+; RV64E-NEXT: .cfi_restore t2
+; RV64E-NEXT: .cfi_restore a0
+; RV64E-NEXT: .cfi_restore a1
+; RV64E-NEXT: .cfi_restore a2
+; RV64E-NEXT: .cfi_restore a3
+; RV64E-NEXT: .cfi_restore a4
+; RV64E-NEXT: .cfi_restore a5
+; RV64E-NEXT: addi sp, sp, 96
+; RV64E-NEXT: .cfi_def_cfa_offset 0
+; RV64E-NEXT: sret
call void @callee()
ret void
}
@@ -522,6 +639,27 @@ define void @m_preemptible() #0 {
; RV64-NEXT: addi sp, sp, 32
; RV64-NEXT: .cfi_def_cfa_offset 0
; RV64-NEXT: mret
+;
+; RV64E-LABEL: m_preemptible:
+; RV64E: # %bb.0:
+; RV64E-NEXT: addi sp, sp, -32
+; RV64E-NEXT: .cfi_def_cfa_offset 32
+; RV64E-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
+; RV64E-NEXT: .cfi_offset t0, -24
+; RV64E-NEXT: csrr t0, mepc
+; RV64E-NEXT: sd t0, 24(sp) # 8-byte Folded Spill
+; RV64E-NEXT: csrrsi t0, mistatus, 1
+; RV64E-NEXT: sd t0, 16(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sw zero, 4(sp)
+; RV64E-NEXT: ld t0, 16(sp) # 8-byte Folded Reload
+; RV64E-NEXT: csrw mistatus, t0
+; RV64E-NEXT: ld t0, 24(sp) # 8-byte Folded Reload
+; RV64E-NEXT: csrw mepc, t0
+; RV64E-NEXT: ld t0, 8(sp) # 8-byte Folded Reload
+; RV64E-NEXT: .cfi_restore t0
+; RV64E-NEXT: addi sp, sp, 32
+; RV64E-NEXT: .cfi_def_cfa_offset 0
+; RV64E-NEXT: mret
%slot = alloca i32
store volatile i32 0, ptr %slot
ret void
@@ -590,6 +728,27 @@ define void @s_preemptible() #1 {
; RV64-NEXT: addi sp, sp, 32
; RV64-NEXT: .cfi_def_cfa_offset 0
; RV64-NEXT: sret
+;
+; RV64E-LABEL: s_preemptible:
+; RV64E: # %bb.0:
+; RV64E-NEXT: addi sp, sp, -32
+; RV64E-NEXT: .cfi_def_cfa_offset 32
+; RV64E-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
+; RV64E-NEXT: .cfi_offset t0, -24
+; RV64E-NEXT: csrr t0, sepc
+; RV64E-NEXT: sd t0, 24(sp) # 8-byte Folded Spill
+; RV64E-NEXT: csrrsi t0, sistatus, 1
+; RV64E-NEXT: sd t0, 16(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sw zero, 4(sp)
+; RV64E-NEXT: ld t0, 16(sp) # 8-byte Folded Reload
+; RV64E-NEXT: csrw sistatus, t0
+; RV64E-NEXT: ld t0, 24(sp) # 8-byte Folded Reload
+; RV64E-NEXT: csrw sepc, t0
+; RV64E-NEXT: ld t0, 8(sp) # 8-byte Folded Reload
+; RV64E-NEXT: .cfi_restore t0
+; RV64E-NEXT: addi sp, sp, 32
+; RV64E-NEXT: .cfi_def_cfa_offset 0
+; RV64E-NEXT: sret
%slot = alloca i32
store volatile i32 0, ptr %slot
ret void
@@ -721,6 +880,32 @@ define void @m_push_pop() #2 {
; RV64-NEXT: addi sp, sp, 80
; RV64-NEXT: .cfi_def_cfa_offset 48
; RV64-NEXT: mipopret
+;
+; RV64E-LABEL: m_push_pop:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: addi sp, sp, -32
+; RV64E-NEXT: .cfi_def_cfa_offset 80
+; RV64E-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd t0, 16(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd t1, 8(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd t2, 0(sp) # 8-byte Folded Spill
+; RV64E-NEXT: .cfi_offset ra, -56
+; RV64E-NEXT: .cfi_offset t0, -64
+; RV64E-NEXT: .cfi_offset t1, -72
+; RV64E-NEXT: .cfi_offset t2, -80
+; RV64E-NEXT: call callee
+; RV64E-NEXT: ld ra, 24(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t0, 16(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t1, 8(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t2, 0(sp) # 8-byte Folded Reload
+; RV64E-NEXT: .cfi_restore ra
+; RV64E-NEXT: .cfi_restore t0
+; RV64E-NEXT: .cfi_restore t1
+; RV64E-NEXT: .cfi_restore t2
+; RV64E-NEXT: addi sp, sp, 32
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: mipopret
call void @callee()
ret void
}
@@ -851,6 +1036,32 @@ define void @s_push_pop() #3 {
; RV64-NEXT: addi sp, sp, 80
; RV64-NEXT: .cfi_def_cfa_offset 48
; RV64-NEXT: sipopret
+;
+; RV64E-LABEL: s_push_pop:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: addi sp, sp, -32
+; RV64E-NEXT: .cfi_def_cfa_offset 80
+; RV64E-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd t0, 16(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd t1, 8(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd t2, 0(sp) # 8-byte Folded Spill
+; RV64E-NEXT: .cfi_offset ra, -56
+; RV64E-NEXT: .cfi_offset t0, -64
+; RV64E-NEXT: .cfi_offset t1, -72
+; RV64E-NEXT: .cfi_offset t2, -80
+; RV64E-NEXT: call callee
+; RV64E-NEXT: ld ra, 24(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t0, 16(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t1, 8(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t2, 0(sp) # 8-byte Folded Reload
+; RV64E-NEXT: .cfi_restore ra
+; RV64E-NEXT: .cfi_restore t0
+; RV64E-NEXT: .cfi_restore t1
+; RV64E-NEXT: .cfi_restore t2
+; RV64E-NEXT: addi sp, sp, 32
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: sipopret
call void @callee()
ret void
}
@@ -921,6 +1132,28 @@ define void @m_combined() #4 {
; RV64-NEXT: addi sp, sp, 32
; RV64-NEXT: .cfi_def_cfa_offset 48
; RV64-NEXT: mipopret
+;
+; RV64E-LABEL: m_combined:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: addi sp, sp, -32
+; RV64E-NEXT: .cfi_def_cfa_offset 80
+; RV64E-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
+; RV64E-NEXT: .cfi_offset t0, -72
+; RV64E-NEXT: csrr t0, mepc
+; RV64E-NEXT: sd t0, 24(sp) # 8-byte Folded Spill
+; RV64E-NEXT: csrrsi t0, mistatus, 1
+; RV64E-NEXT: sd t0, 16(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sw zero, 4(sp)
+; RV64E-NEXT: ld t0, 16(sp) # 8-byte Folded Reload
+; RV64E-NEXT: csrw mistatus, t0
+; RV64E-NEXT: ld t0, 24(sp) # 8-byte Folded Reload
+; RV64E-NEXT: csrw mepc, t0
+; RV64E-NEXT: ld t0, 8(sp) # 8-byte Folded Reload
+; RV64E-NEXT: .cfi_restore t0
+; RV64E-NEXT: addi sp, sp, 32
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: mipopret
%slot = alloca i32
store volatile i32 0, ptr %slot
ret void
@@ -992,6 +1225,28 @@ define void @s_combined() #5 {
; RV64-NEXT: addi sp, sp, 32
; RV64-NEXT: .cfi_def_cfa_offset 48
; RV64-NEXT: sipopret
+;
+; RV64E-LABEL: s_combined:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: addi sp, sp, -32
+; RV64E-NEXT: .cfi_def_cfa_offset 80
+; RV64E-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
+; RV64E-NEXT: .cfi_offset t0, -72
+; RV64E-NEXT: csrr t0, sepc
+; RV64E-NEXT: sd t0, 24(sp) # 8-byte Folded Spill
+; RV64E-NEXT: csrrsi t0, sistatus, 1
+; RV64E-NEXT: sd t0, 16(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sw zero, 4(sp)
+; RV64E-NEXT: ld t0, 16(sp) # 8-byte Folded Reload
+; RV64E-NEXT: csrw sistatus, t0
+; RV64E-NEXT: ld t0, 24(sp) # 8-byte Folded Reload
+; RV64E-NEXT: csrw sepc, t0
+; RV64E-NEXT: ld t0, 8(sp) # 8-byte Folded Reload
+; RV64E-NEXT: .cfi_restore t0
+; RV64E-NEXT: addi sp, sp, 32
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: sipopret
%slot = alloca i32
store volatile i32 0, ptr %slot
ret void
@@ -1144,6 +1399,39 @@ define void @m_push_pop_large() #2 {
; RV64-NEXT: addi sp, sp, 1984
; RV64-NEXT: .cfi_def_cfa_offset 48
; RV64-NEXT: mipopret
+;
+; RV64E-LABEL: m_push_pop_large:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: addi sp, sp, -1992
+; RV64E-NEXT: .cfi_def_cfa_offset 2040
+; RV64E-NEXT: sd ra, 1984(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd t0, 1976(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd t1, 1968(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd t2, 1960(sp) # 8-byte Folded Spill
+; RV64E-NEXT: .cfi_offset ra, -56
+; RV64E-NEXT: .cfi_offset t0, -64
+; RV64E-NEXT: .cfi_offset t1, -72
+; RV64E-NEXT: .cfi_offset t2, -80
+; RV64E-NEXT: addi sp, sp, -2048
+; RV64E-NEXT: addi sp, sp, -1000
+; RV64E-NEXT: .cfi_def_cfa_offset 5088
+; RV64E-NEXT: call callee
+; RV64E-NEXT: sb zero, 8(sp)
+; RV64E-NEXT: addi sp, sp, 2040
+; RV64E-NEXT: addi sp, sp, 1008
+; RV64E-NEXT: .cfi_def_cfa_offset 2040
+; RV64E-NEXT: ld ra, 1984(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t0, 1976(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t1, 1968(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld t2, 1960(sp) # 8-byte Folded Reload
+; RV64E-NEXT: .cfi_restore ra
+; RV64E-NEXT: .cfi_restore t0
+; RV64E-NEXT: .cfi_restore t1
+; RV64E-NEXT: .cfi_restore t2
+; RV64E-NEXT: addi sp, sp, 1992
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: mipopret
%slot = alloca [5000 x i8]
call void @callee()
store volatile i8 0, ptr %slot
@@ -1165,6 +1453,11 @@ define void @m_push_pop_empty() #6 {
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
; RV64-NEXT: mipopret
+;
+; RV64E-LABEL: m_push_pop_empty:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: mipopret
ret void
}
@@ -1183,6 +1476,11 @@ define void @s_push_pop_empty() #7 {
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
; RV64-NEXT: sipopret
+;
+; RV64E-LABEL: s_push_pop_empty:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: sipopret
ret void
}
@@ -1249,6 +1547,27 @@ define void @m_push_pop_fp() #8 {
; RV64-NEXT: addi sp, sp, 32
; RV64-NEXT: .cfi_def_cfa_offset 48
; RV64-NEXT: mipopret
+;
+; RV64E-LABEL: m_push_pop_fp:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: addi sp, sp, -24
+; RV64E-NEXT: .cfi_def_cfa_offset 72
+; RV64E-NEXT: sd ra, 16(sp) # 8-byte Folded Spill
+; RV64E-NEXT: sd s0, 8(sp) # 8-byte Folded Spill
+; RV64E-NEXT: .cfi_offset ra, -56
+; RV64E-NEXT: .cfi_offset s0, -64
+; RV64E-NEXT: addi s0, sp, 72
+; RV64E-NEXT: .cfi_def_cfa s0, 0
+; RV64E-NEXT: sw zero, 4(sp)
+; RV64E-NEXT: .cfi_def_cfa sp, 72
+; RV64E-NEXT: ld ra, 16(sp) # 8-byte Folded Reload
+; RV64E-NEXT: ld s0, 8(sp) # 8-byte Folded Reload
+; RV64E-NEXT: .cfi_restore ra
+; RV64E-NEXT: .cfi_restore s0
+; RV64E-NEXT: addi sp, sp, 24
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: mipopret
%slot = alloca i32
store volatile i32 0, ptr %slot
ret void
>From b2a7af9ad371f5b6d45b42934c21619b75fc16cf Mon Sep 17 00:00:00 2001
From: Zeyi Xu <mitchell.xu2 at gmail.com>
Date: Mon, 9 Nov 2026 12:24:38 +0800
Subject: [PATCH 3/3] port to latest RISCVABI enum
---
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 3831ceaa18143f..72abdc85e3ead9 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -73,7 +73,7 @@ static uint64_t getACLICInterruptPushAmount(const MachineFunction &MF) {
const auto &STI = MF.getSubtarget<RISCVSubtarget>();
if (STI.is64Bit())
return 48;
- return STI.getTargetABI() == RISCVABI::ABI_ILP32E ? 24 : 32;
+ return STI.getTargetABI() == RISCVABI::ABI::ILP32E ? 24 : 32;
}
static const std::pair<MCPhysReg, int8_t> FixedCSRFIQCIInterruptMap[] = {
More information about the cfe-commits
mailing list