[clang] [llvm] [RISCV] Add Codegen support for ACLIC (PR #238325)
Zeyi Xu via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 25 21:06:51 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 01/12] [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 02/12] 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 03/12] 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[] = {
>From 3758982642d04f09d6bee890e11fbb368ae78a37 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <mitchell.xu2 at gmail.com>
Date: Wed, 11 Nov 2026 13:48:08 +0800
Subject: [PATCH 04/12] address feedback, pt.1
---
clang/include/clang/Basic/Attr.td | 8 +++----
clang/include/clang/Basic/AttrDocs.td | 24 +++++++++----------
clang/lib/CodeGen/Targets/RISCV.cpp | 16 ++++++-------
clang/lib/Sema/SemaRISCV.cpp | 16 ++++++-------
clang/test/Sema/riscv-interrupt-attr-aclic.c | 2 +-
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 2 +-
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 10 ++++----
.../Target/RISCV/RISCVMachineFunctionInfo.cpp | 14 +++++------
.../Target/RISCV/RISCVMachineFunctionInfo.h | 12 +++++-----
9 files changed, 52 insertions(+), 52 deletions(-)
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 8031fd7e1b9480..e6470cc3ef2c43 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2481,23 +2481,23 @@ def RISCVInterrupt : InheritableAttr, TargetSpecificAttr<TargetRISCV> {
"supervisor",
"machine",
"rnmi",
+ "preemptible",
+ "push-pop",
"qci-nest",
"qci-nonest",
"SiFive-CLIC-preemptible",
"SiFive-CLIC-stack-swap",
- "preemptible",
- "push-pop",
],
[
"supervisor",
"machine",
"rnmi",
+ "preemptible",
+ "pushpop",
"qcinest",
"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 6b95e7724c3549..463d25c3e92e5f 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3296,13 +3296,22 @@ the backend to generate appropriate function entry/exit code so that it can be
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`, `preemptible`, and `push-pop`. If there is no
+`rnmi`, `preemptible`, `push-pop`, `qci-nest`, `qci-nonest`,
+`SiFive-CLIC-preemptible`, and `SiFive-CLIC-stack-swap`. 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.
+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`.
+
The `qci-nest` and `qci-nonest` values require Qualcomm's Xqciint extension
and are used for Machine-mode Interrupts and Machine-mode Non-maskable
interrupts. These use the following instructions from Xqciint to save and
@@ -3320,24 +3329,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.
References:
- [GCC RISC-V Attributes](https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Function-Attributes.html)
- [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)
+- [RISC-V Fast Interrupt v0.20](https://github.com/riscv/riscv-fast-interrupt/releases/tag/v0.20)
- [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 4b07a2d0b87812..a4e96570a92b0b 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -1140,10 +1140,10 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
return;
std::string Kind = "machine";
- bool HasSiFiveCLICPreemptible = false;
- bool HasSiFiveCLICStackSwap = false;
bool HasPreemptible = false;
bool HasPushPop = false;
+ bool HasSiFiveCLICPreemptible = false;
+ bool HasSiFiveCLICStackSwap = false;
for (RISCVInterruptAttr::InterruptType type : Attr->interrupt()) {
switch (type) {
case RISCVInterruptAttr::machine:
@@ -1156,6 +1156,12 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
case RISCVInterruptAttr::rnmi:
Kind = "rnmi";
break;
+ case RISCVInterruptAttr::preemptible:
+ HasPreemptible = true;
+ break;
+ case RISCVInterruptAttr::pushpop:
+ HasPushPop = true;
+ break;
case RISCVInterruptAttr::qcinest:
Kind = "qci-nest";
break;
@@ -1176,12 +1182,6 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
: "SiFive-CLIC-stack-swap";
break;
}
- case RISCVInterruptAttr::preemptible:
- HasPreemptible = true;
- break;
- case RISCVInterruptAttr::pushpop:
- HasPushPop = true;
- break;
}
}
diff --git a/clang/lib/Sema/SemaRISCV.cpp b/clang/lib/Sema/SemaRISCV.cpp
index ffed87e91bbf0a..dadf1c3ae2c191 100644
--- a/clang/lib/Sema/SemaRISCV.cpp
+++ b/clang/lib/Sema/SemaRISCV.cpp
@@ -1682,9 +1682,9 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
bool HasMachine = false;
bool HasSupervisor = false;
- bool HasSiFiveCLICType = false;
bool HasPreemptible = false;
bool HasPushPop = false;
+ bool HasSiFiveCLICType = false;
bool HasUnaryType = false;
bool ReportedDuplicateType = false;
@@ -1706,24 +1706,24 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
switch (Type) {
case RISCVInterruptAttr::machine:
- // "machine" can be used alone, with SiFive CLIC types, or with ACLIC
- // modifiers.
+ // "machine" can be used alone, with ACLIC modifiers, or with SiFive CLIC
+ // types.
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::preemptible:
HasPreemptible = true;
break;
case RISCVInterruptAttr::pushpop:
HasPushPop = true;
break;
+ case RISCVInterruptAttr::SiFiveCLICPreemptible:
+ case RISCVInterruptAttr::SiFiveCLICStackSwap:
+ // SiFive-CLIC types can be combined with each other and "machine"
+ HasSiFiveCLICType = true;
+ break;
case RISCVInterruptAttr::rnmi:
case RISCVInterruptAttr::qcinest:
case RISCVInterruptAttr::qcinonest:
diff --git a/clang/test/Sema/riscv-interrupt-attr-aclic.c b/clang/test/Sema/riscv-interrupt-attr-aclic.c
index 1a1b3edadc6e31..90faec2a46df69 100644
--- a/clang/test/Sema/riscv-interrupt-attr-aclic.c
+++ b/clang/test/Sema/riscv-interrupt-attr-aclic.c
@@ -13,7 +13,7 @@
// RUN: %clang_cc1 -triple riscv64-unknown-elf -verify=disabled,both \
// RUN: -fsyntax-only %s
-#ifdef CHECK_IR
+#if defined(CHECK_IR)
__attribute__((interrupt("preemptible"))) void m_preemptible(void) {}
__attribute__((interrupt("supervisor", "preemptible")))
void s_preemptible(void) {}
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 72abdc85e3ead9..9a8b1e4669fe95 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.hasStdExtE() ? 24 : 32;
}
static const std::pair<MCPhysReg, int8_t> FixedCSRFIQCIInterruptMap[] = {
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 6dbad4206d518e..8f96b2401d5f77 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -28780,17 +28780,17 @@ SDValue RISCVTargetLowering::LowerFormalArguments(
"machine",
"supervisor",
"rnmi",
- "qci-nest",
- "qci-nonest",
- "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",
+ "qci-nest",
+ "qci-nonest",
+ "SiFive-CLIC-preemptible",
+ "SiFive-CLIC-stack-swap",
+ "SiFive-CLIC-preemptible-stack-swap",
};
if (!llvm::is_contained(SupportedInterruptKinds, Kind))
reportFatalUsageError(
diff --git a/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp b/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp
index c25d02a52f2de3..e80f5830b3d6ca 100644
--- a/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp
@@ -73,13 +73,6 @@ RISCVMachineFunctionInfo::getInterruptStackKind(
return StringSwitch<RISCVMachineFunctionInfo::InterruptStackKind>(
InterruptVal)
- .Case("qci-nest", InterruptStackKind::QCINest)
- .Case("qci-nonest", InterruptStackKind::QCINoNest)
- .Case("SiFive-CLIC-preemptible",
- InterruptStackKind::SiFiveCLICPreemptible)
- .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)
@@ -89,6 +82,13 @@ RISCVMachineFunctionInfo::getInterruptStackKind(
InterruptStackKind::ACLICPreemptiblePushPop)
.Case("supervisor-preemptible-push-pop",
InterruptStackKind::ACLICSupervisorPreemptiblePushPop)
+ .Case("qci-nest", InterruptStackKind::QCINest)
+ .Case("qci-nonest", InterruptStackKind::QCINoNest)
+ .Case("SiFive-CLIC-preemptible",
+ InterruptStackKind::SiFiveCLICPreemptible)
+ .Case("SiFive-CLIC-stack-swap", InterruptStackKind::SiFiveCLICStackSwap)
+ .Case("SiFive-CLIC-preemptible-stack-swap",
+ InterruptStackKind::SiFiveCLICPreemptibleStackSwap)
.Default(InterruptStackKind::None);
}
diff --git a/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h b/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
index e45b76208abf0a..423c6d4f9b9fac 100644
--- a/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
+++ b/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
@@ -190,17 +190,17 @@ class RISCVMachineFunctionInfo : public MachineFunctionInfo {
enum class InterruptStackKind {
None = 0,
- QCINest,
- QCINoNest,
- SiFiveCLICPreemptible,
- SiFiveCLICStackSwap,
- SiFiveCLICPreemptibleStackSwap,
ACLICPreemptible,
ACLICSupervisorPreemptible,
ACLICPushPop,
ACLICSupervisorPushPop,
ACLICPreemptiblePushPop,
- ACLICSupervisorPreemptiblePushPop
+ ACLICSupervisorPreemptiblePushPop,
+ QCINest,
+ QCINoNest,
+ SiFiveCLICPreemptible,
+ SiFiveCLICStackSwap,
+ SiFiveCLICPreemptibleStackSwap
};
InterruptStackKind getInterruptStackKind(const MachineFunction &MF) const;
>From 79dc20f0f732f0955ac3bfdec31fa622652ebb69 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <zeyi2 at nekoarch.cc>
Date: Wed, 18 Nov 2026 03:01:54 +0000
Subject: [PATCH 05/12] guard the shrink wrapping better
---
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 9a8b1e4669fe95..d363e785700a5f 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -2825,7 +2825,9 @@ bool RISCVFrameLowering::restoreCalleeSavedRegisters(
}
bool RISCVFrameLowering::enableShrinkWrapping(const MachineFunction &MF) const {
- if (MF.getInfo<RISCVMachineFunctionInfo>()->isACLICPreemptibleInterrupt(MF))
+ const auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
+ if (RVFI->isACLICPreemptibleInterrupt(MF) ||
+ RVFI->isACLICPushPopInterrupt(MF))
return false;
// Keep the conventional code flow when not optimizing.
@@ -2834,7 +2836,6 @@ bool RISCVFrameLowering::enableShrinkWrapping(const MachineFunction &MF) const {
// QCI and SiFive CLIC interrupt entry sequences must precede all handler
// code.
- const auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
if (RVFI->useQCIInterrupt(MF) || RVFI->useSiFiveInterrupt(MF))
return false;
>From c22d4eb9bb8082088be464d294e38e8910d51432 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <zeyi2 at nekoarch.cc>
Date: Wed, 18 Nov 2026 03:08:36 +0000
Subject: [PATCH 06/12] cfa bug! add baseline test
---
.../CodeGen/RISCV/aclic-interrupt-attr.ll | 181 ++++++++++++++++++
1 file changed, 181 insertions(+)
diff --git a/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
index 35ec715352263e..53985dc11f5d10 100644
--- a/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
@@ -1573,6 +1573,186 @@ define void @m_push_pop_fp() #8 {
ret void
}
+define void @m_push_pop_scs() #9 {
+; RV32-LABEL: m_push_pop_scs:
+; RV32: # %bb.0:
+; RV32-NEXT: addi gp, gp, 4
+; RV32-NEXT: sw ra, -4(gp)
+; RV32-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x7c #
+; 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: lw ra, -4(gp)
+; RV32-NEXT: addi gp, gp, -4
+; RV32-NEXT: .cfi_restore gp
+; RV32-NEXT: mipopret
+;
+; RV32E-LABEL: m_push_pop_scs:
+; RV32E: # %bb.0:
+; RV32E-NEXT: addi gp, gp, 4
+; RV32E-NEXT: sw ra, -4(gp)
+; RV32E-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x7c #
+; 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: lw ra, -4(gp)
+; RV32E-NEXT: addi gp, gp, -4
+; RV32E-NEXT: .cfi_restore gp
+; RV32E-NEXT: mipopret
+;
+; RV64-LABEL: m_push_pop_scs:
+; RV64: # %bb.0:
+; RV64-NEXT: addi gp, gp, 8
+; RV64-NEXT: sd ra, -8(gp)
+; RV64-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x78 #
+; 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: ld ra, -8(gp)
+; RV64-NEXT: addi gp, gp, -8
+; RV64-NEXT: .cfi_restore gp
+; RV64-NEXT: mipopret
+;
+; RV64E-LABEL: m_push_pop_scs:
+; RV64E: # %bb.0:
+; RV64E-NEXT: addi gp, gp, 8
+; RV64E-NEXT: sd ra, -8(gp)
+; RV64E-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x78 #
+; 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: ld ra, -8(gp)
+; RV64E-NEXT: addi gp, gp, -8
+; RV64E-NEXT: .cfi_restore gp
+; RV64E-NEXT: mipopret
+ call void @callee()
+ 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" }
@@ -1582,3 +1762,4 @@ attributes #5 = { "frame-pointer"="none" "interrupt"="supervisor-preemptible-pus
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" }
+attributes #9 = { "frame-pointer"="none" "interrupt"="machine-push-pop" shadowcallstack }
>From f087b4805d13c4b6a232d805e6d42ccff21bcd14 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <zeyi2 at nekoarch.cc>
Date: Wed, 18 Nov 2026 03:11:26 +0000
Subject: [PATCH 07/12] cfa tweak, shadow stack fix
---
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 12 ++++++------
llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll | 8 ++++----
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index d363e785700a5f..eab7266e234b97 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -1121,6 +1121,12 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
if (MF.getFunction().getCallingConv() == CallingConv::GHC)
return;
+ // The CFA is the SP before the Smip/Ssip hardware push, so describe it
+ // before any other prologue code.
+ if (needsDwarfCFI(MF) && RVFI->isACLICPushPopInterrupt(MF))
+ CFIInstBuilder(MBB, MBBI, MachineInstr::FrameSetup)
+ .buildDefCFAOffset(RVFI->getACLICInterruptStackSize());
+
// SiFive CLIC needs to swap `sp` into `sf.mscratchcsw`
emitSiFiveCLICStackSwap(MF, MBB, MBBI, DL, MachineInstr::FrameSetup);
@@ -1150,12 +1156,6 @@ 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);
diff --git a/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
index 53985dc11f5d10..089ff7ffb36443 100644
--- a/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
@@ -1576,10 +1576,10 @@ define void @m_push_pop_fp() #8 {
define void @m_push_pop_scs() #9 {
; RV32-LABEL: m_push_pop_scs:
; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
; RV32-NEXT: addi gp, gp, 4
; RV32-NEXT: sw ra, -4(gp)
; RV32-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x7c #
-; 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
@@ -1632,10 +1632,10 @@ define void @m_push_pop_scs() #9 {
;
; RV32E-LABEL: m_push_pop_scs:
; RV32E: # %bb.0:
+; RV32E-NEXT: .cfi_def_cfa_offset 24
; RV32E-NEXT: addi gp, gp, 4
; RV32E-NEXT: sw ra, -4(gp)
; RV32E-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x7c #
-; 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
@@ -1664,10 +1664,10 @@ define void @m_push_pop_scs() #9 {
;
; RV64-LABEL: m_push_pop_scs:
; RV64: # %bb.0:
+; RV64-NEXT: .cfi_def_cfa_offset 48
; RV64-NEXT: addi gp, gp, 8
; RV64-NEXT: sd ra, -8(gp)
; RV64-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x78 #
-; 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
@@ -1720,10 +1720,10 @@ define void @m_push_pop_scs() #9 {
;
; RV64E-LABEL: m_push_pop_scs:
; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
; RV64E-NEXT: addi gp, gp, 8
; RV64E-NEXT: sd ra, -8(gp)
; RV64E-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x78 #
-; 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
>From 612d5a95e032b2cb0f80d4c15ede50ba7160369e Mon Sep 17 00:00:00 2001
From: Zeyi Xu <zeyi2 at nekoarch.cc>
Date: Wed, 25 Nov 2026 03:18:34 +0000
Subject: [PATCH 08/12] address feedback pt.2
---
llvm/lib/Target/RISCV/RISCVCallingConv.td | 55 -----
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 13 +-
llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp | 45 +---
.../CodeGen/RISCV/aclic-interrupt-attr.ll | 216 ++++++++++++++++++
.../RISCV/aclic-interrupt-frame-pointer.ll | 18 ++
5 files changed, 256 insertions(+), 91 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVCallingConv.td b/llvm/lib/Target/RISCV/RISCVCallingConv.td
index ad9ebb554ff077..a5cf7ab27c4091 100644
--- a/llvm/lib/Target/RISCV/RISCVCallingConv.td
+++ b/llvm/lib/Target/RISCV/RISCVCallingConv.td
@@ -96,61 +96,6 @@ 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 eab7266e234b97..083a00355ccaf8 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -1123,9 +1123,12 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
// The CFA is the SP before the Smip/Ssip hardware push, so describe it
// before any other prologue code.
- if (needsDwarfCFI(MF) && RVFI->isACLICPushPopInterrupt(MF))
- CFIInstBuilder(MBB, MBBI, MachineInstr::FrameSetup)
- .buildDefCFAOffset(RVFI->getACLICInterruptStackSize());
+ if (needsDwarfCFI(MF) && RVFI->isACLICPushPopInterrupt(MF)) {
+ CFIInstBuilder CFIBuilder(MBB, MBBI, MachineInstr::FrameSetup);
+ CFIBuilder.buildDefCFAOffset(RVFI->getACLICInterruptStackSize());
+ for (MCPhysReg Reg = RISCV::X10; Reg <= RISCV::X15; ++Reg)
+ CFIBuilder.buildUndefined(Reg);
+ }
// SiFive CLIC needs to swap `sp` into `sf.mscratchcsw`
emitSiFiveCLICStackSwap(MF, MBB, MBBI, DL, MachineInstr::FrameSetup);
@@ -2008,6 +2011,10 @@ void RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
if (RVFI->isPushable(MF) && SavedRegs.test(RISCV::X26))
SavedRegs.set(RISCV::X27);
+ if (RVFI->isACLICPushPopInterrupt(MF))
+ for (MCPhysReg Reg = RISCV::X10; Reg <= RISCV::X15; ++Reg)
+ SavedRegs.reset(Reg);
+
// For Zilsd on RV32, append GPRPair registers to the CSR list. This prevents
// the need to create register sets for each abi which is a lot more complex.
// Don't use Zilsd for callee-saved coalescing if the required alignment
diff --git a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
index 5b5da3707fa13d..00c89367fc3ecb 100644
--- a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
@@ -12,7 +12,6 @@
#include "RISCVRegisterInfo.h"
#include "RISCV.h"
-#include "RISCVMachineFunctionInfo.h"
#include "RISCVSubtarget.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/BinaryFormat/Dwarf.h"
@@ -76,44 +75,24 @@ 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()
- ? (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);
+ return Subtarget.hasStdExtE() ? CSR_XLEN_F64_V_Interrupt_RVE_SaveList
+ : CSR_XLEN_F64_V_Interrupt_SaveList;
if (Subtarget.hasStdExtF())
- 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);
+ 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;
}
if (Subtarget.hasStdExtD())
- 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);
+ return Subtarget.hasStdExtE() ? CSR_XLEN_F64_Interrupt_RVE_SaveList
+ : CSR_XLEN_F64_Interrupt_SaveList;
if (Subtarget.hasStdExtF())
- 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);
+ return Subtarget.hasStdExtE() ? CSR_XLEN_F32_Interrupt_RVE_SaveList
+ : CSR_XLEN_F32_Interrupt_SaveList;
+ return Subtarget.hasStdExtE() ? CSR_Interrupt_RVE_SaveList
+ : CSR_Interrupt_SaveList;
}
bool HasVectorCSR =
diff --git a/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
index 089ff7ffb36443..95aedc7b60fb7c 100644
--- a/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
@@ -758,6 +758,12 @@ define void @m_push_pop() #2 {
; RV32-LABEL: m_push_pop:
; RV32: # %bb.0:
; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: .cfi_undefined a0
+; RV32-NEXT: .cfi_undefined a1
+; RV32-NEXT: .cfi_undefined a2
+; RV32-NEXT: .cfi_undefined a3
+; RV32-NEXT: .cfi_undefined a4
+; RV32-NEXT: .cfi_undefined a5
; RV32-NEXT: addi sp, sp, -48
; RV32-NEXT: .cfi_def_cfa_offset 80
; RV32-NEXT: sw ra, 44(sp) # 4-byte Folded Spill
@@ -808,6 +814,12 @@ define void @m_push_pop() #2 {
; RV32E-LABEL: m_push_pop:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: .cfi_undefined a0
+; RV32E-NEXT: .cfi_undefined a1
+; RV32E-NEXT: .cfi_undefined a2
+; RV32E-NEXT: .cfi_undefined a3
+; RV32E-NEXT: .cfi_undefined a4
+; RV32E-NEXT: .cfi_undefined a5
; RV32E-NEXT: addi sp, sp, -16
; RV32E-NEXT: .cfi_def_cfa_offset 40
; RV32E-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
@@ -834,6 +846,12 @@ define void @m_push_pop() #2 {
; RV64-LABEL: m_push_pop:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: .cfi_undefined a0
+; RV64-NEXT: .cfi_undefined a1
+; RV64-NEXT: .cfi_undefined a2
+; RV64-NEXT: .cfi_undefined a3
+; RV64-NEXT: .cfi_undefined a4
+; RV64-NEXT: .cfi_undefined a5
; RV64-NEXT: addi sp, sp, -80
; RV64-NEXT: .cfi_def_cfa_offset 128
; RV64-NEXT: sd ra, 72(sp) # 8-byte Folded Spill
@@ -884,6 +902,12 @@ define void @m_push_pop() #2 {
; RV64E-LABEL: m_push_pop:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: .cfi_undefined a0
+; RV64E-NEXT: .cfi_undefined a1
+; RV64E-NEXT: .cfi_undefined a2
+; RV64E-NEXT: .cfi_undefined a3
+; RV64E-NEXT: .cfi_undefined a4
+; RV64E-NEXT: .cfi_undefined a5
; RV64E-NEXT: addi sp, sp, -32
; RV64E-NEXT: .cfi_def_cfa_offset 80
; RV64E-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
@@ -914,6 +938,12 @@ define void @s_push_pop() #3 {
; RV32-LABEL: s_push_pop:
; RV32: # %bb.0:
; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: .cfi_undefined a0
+; RV32-NEXT: .cfi_undefined a1
+; RV32-NEXT: .cfi_undefined a2
+; RV32-NEXT: .cfi_undefined a3
+; RV32-NEXT: .cfi_undefined a4
+; RV32-NEXT: .cfi_undefined a5
; RV32-NEXT: addi sp, sp, -48
; RV32-NEXT: .cfi_def_cfa_offset 80
; RV32-NEXT: sw ra, 44(sp) # 4-byte Folded Spill
@@ -964,6 +994,12 @@ define void @s_push_pop() #3 {
; RV32E-LABEL: s_push_pop:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: .cfi_undefined a0
+; RV32E-NEXT: .cfi_undefined a1
+; RV32E-NEXT: .cfi_undefined a2
+; RV32E-NEXT: .cfi_undefined a3
+; RV32E-NEXT: .cfi_undefined a4
+; RV32E-NEXT: .cfi_undefined a5
; RV32E-NEXT: addi sp, sp, -16
; RV32E-NEXT: .cfi_def_cfa_offset 40
; RV32E-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
@@ -990,6 +1026,12 @@ define void @s_push_pop() #3 {
; RV64-LABEL: s_push_pop:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: .cfi_undefined a0
+; RV64-NEXT: .cfi_undefined a1
+; RV64-NEXT: .cfi_undefined a2
+; RV64-NEXT: .cfi_undefined a3
+; RV64-NEXT: .cfi_undefined a4
+; RV64-NEXT: .cfi_undefined a5
; RV64-NEXT: addi sp, sp, -80
; RV64-NEXT: .cfi_def_cfa_offset 128
; RV64-NEXT: sd ra, 72(sp) # 8-byte Folded Spill
@@ -1040,6 +1082,12 @@ define void @s_push_pop() #3 {
; RV64E-LABEL: s_push_pop:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: .cfi_undefined a0
+; RV64E-NEXT: .cfi_undefined a1
+; RV64E-NEXT: .cfi_undefined a2
+; RV64E-NEXT: .cfi_undefined a3
+; RV64E-NEXT: .cfi_undefined a4
+; RV64E-NEXT: .cfi_undefined a5
; RV64E-NEXT: addi sp, sp, -32
; RV64E-NEXT: .cfi_def_cfa_offset 80
; RV64E-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
@@ -1070,6 +1118,12 @@ define void @m_combined() #4 {
; RV32-LABEL: m_combined:
; RV32: # %bb.0:
; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: .cfi_undefined a0
+; RV32-NEXT: .cfi_undefined a1
+; RV32-NEXT: .cfi_undefined a2
+; RV32-NEXT: .cfi_undefined a3
+; RV32-NEXT: .cfi_undefined a4
+; RV32-NEXT: .cfi_undefined a5
; RV32-NEXT: addi sp, sp, -16
; RV32-NEXT: .cfi_def_cfa_offset 48
; RV32-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
@@ -1092,6 +1146,12 @@ define void @m_combined() #4 {
; RV32E-LABEL: m_combined:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: .cfi_undefined a0
+; RV32E-NEXT: .cfi_undefined a1
+; RV32E-NEXT: .cfi_undefined a2
+; RV32E-NEXT: .cfi_undefined a3
+; RV32E-NEXT: .cfi_undefined a4
+; RV32E-NEXT: .cfi_undefined a5
; RV32E-NEXT: addi sp, sp, -16
; RV32E-NEXT: .cfi_def_cfa_offset 40
; RV32E-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
@@ -1114,6 +1174,12 @@ define void @m_combined() #4 {
; RV64-LABEL: m_combined:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: .cfi_undefined a0
+; RV64-NEXT: .cfi_undefined a1
+; RV64-NEXT: .cfi_undefined a2
+; RV64-NEXT: .cfi_undefined a3
+; RV64-NEXT: .cfi_undefined a4
+; RV64-NEXT: .cfi_undefined a5
; RV64-NEXT: addi sp, sp, -32
; RV64-NEXT: .cfi_def_cfa_offset 80
; RV64-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
@@ -1136,6 +1202,12 @@ define void @m_combined() #4 {
; RV64E-LABEL: m_combined:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: .cfi_undefined a0
+; RV64E-NEXT: .cfi_undefined a1
+; RV64E-NEXT: .cfi_undefined a2
+; RV64E-NEXT: .cfi_undefined a3
+; RV64E-NEXT: .cfi_undefined a4
+; RV64E-NEXT: .cfi_undefined a5
; RV64E-NEXT: addi sp, sp, -32
; RV64E-NEXT: .cfi_def_cfa_offset 80
; RV64E-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
@@ -1163,6 +1235,12 @@ define void @s_combined() #5 {
; RV32-LABEL: s_combined:
; RV32: # %bb.0:
; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: .cfi_undefined a0
+; RV32-NEXT: .cfi_undefined a1
+; RV32-NEXT: .cfi_undefined a2
+; RV32-NEXT: .cfi_undefined a3
+; RV32-NEXT: .cfi_undefined a4
+; RV32-NEXT: .cfi_undefined a5
; RV32-NEXT: addi sp, sp, -16
; RV32-NEXT: .cfi_def_cfa_offset 48
; RV32-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
@@ -1185,6 +1263,12 @@ define void @s_combined() #5 {
; RV32E-LABEL: s_combined:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: .cfi_undefined a0
+; RV32E-NEXT: .cfi_undefined a1
+; RV32E-NEXT: .cfi_undefined a2
+; RV32E-NEXT: .cfi_undefined a3
+; RV32E-NEXT: .cfi_undefined a4
+; RV32E-NEXT: .cfi_undefined a5
; RV32E-NEXT: addi sp, sp, -16
; RV32E-NEXT: .cfi_def_cfa_offset 40
; RV32E-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
@@ -1207,6 +1291,12 @@ define void @s_combined() #5 {
; RV64-LABEL: s_combined:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: .cfi_undefined a0
+; RV64-NEXT: .cfi_undefined a1
+; RV64-NEXT: .cfi_undefined a2
+; RV64-NEXT: .cfi_undefined a3
+; RV64-NEXT: .cfi_undefined a4
+; RV64-NEXT: .cfi_undefined a5
; RV64-NEXT: addi sp, sp, -32
; RV64-NEXT: .cfi_def_cfa_offset 80
; RV64-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
@@ -1229,6 +1319,12 @@ define void @s_combined() #5 {
; RV64E-LABEL: s_combined:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: .cfi_undefined a0
+; RV64E-NEXT: .cfi_undefined a1
+; RV64E-NEXT: .cfi_undefined a2
+; RV64E-NEXT: .cfi_undefined a3
+; RV64E-NEXT: .cfi_undefined a4
+; RV64E-NEXT: .cfi_undefined a5
; RV64E-NEXT: addi sp, sp, -32
; RV64E-NEXT: .cfi_def_cfa_offset 80
; RV64E-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
@@ -1256,6 +1352,12 @@ 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: .cfi_undefined a0
+; RV32-NEXT: .cfi_undefined a1
+; RV32-NEXT: .cfi_undefined a2
+; RV32-NEXT: .cfi_undefined a3
+; RV32-NEXT: .cfi_undefined a4
+; RV32-NEXT: .cfi_undefined a5
; RV32-NEXT: addi sp, sp, -2000
; RV32-NEXT: .cfi_def_cfa_offset 2032
; RV32-NEXT: sw ra, 1996(sp) # 4-byte Folded Spill
@@ -1313,6 +1415,12 @@ define void @m_push_pop_large() #2 {
; RV32E-LABEL: m_push_pop_large:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: .cfi_undefined a0
+; RV32E-NEXT: .cfi_undefined a1
+; RV32E-NEXT: .cfi_undefined a2
+; RV32E-NEXT: .cfi_undefined a3
+; RV32E-NEXT: .cfi_undefined a4
+; RV32E-NEXT: .cfi_undefined a5
; RV32E-NEXT: addi sp, sp, -2020
; RV32E-NEXT: .cfi_def_cfa_offset 2044
; RV32E-NEXT: sw ra, 2016(sp) # 4-byte Folded Spill
@@ -1346,6 +1454,12 @@ define void @m_push_pop_large() #2 {
; RV64-LABEL: m_push_pop_large:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: .cfi_undefined a0
+; RV64-NEXT: .cfi_undefined a1
+; RV64-NEXT: .cfi_undefined a2
+; RV64-NEXT: .cfi_undefined a3
+; RV64-NEXT: .cfi_undefined a4
+; RV64-NEXT: .cfi_undefined a5
; RV64-NEXT: addi sp, sp, -1984
; RV64-NEXT: .cfi_def_cfa_offset 2032
; RV64-NEXT: sd ra, 1976(sp) # 8-byte Folded Spill
@@ -1403,6 +1517,12 @@ define void @m_push_pop_large() #2 {
; RV64E-LABEL: m_push_pop_large:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: .cfi_undefined a0
+; RV64E-NEXT: .cfi_undefined a1
+; RV64E-NEXT: .cfi_undefined a2
+; RV64E-NEXT: .cfi_undefined a3
+; RV64E-NEXT: .cfi_undefined a4
+; RV64E-NEXT: .cfi_undefined a5
; RV64E-NEXT: addi sp, sp, -1992
; RV64E-NEXT: .cfi_def_cfa_offset 2040
; RV64E-NEXT: sd ra, 1984(sp) # 8-byte Folded Spill
@@ -1442,21 +1562,45 @@ 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: .cfi_undefined a0
+; RV32-NEXT: .cfi_undefined a1
+; RV32-NEXT: .cfi_undefined a2
+; RV32-NEXT: .cfi_undefined a3
+; RV32-NEXT: .cfi_undefined a4
+; RV32-NEXT: .cfi_undefined a5
; RV32-NEXT: mipopret
;
; RV32E-LABEL: m_push_pop_empty:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: .cfi_undefined a0
+; RV32E-NEXT: .cfi_undefined a1
+; RV32E-NEXT: .cfi_undefined a2
+; RV32E-NEXT: .cfi_undefined a3
+; RV32E-NEXT: .cfi_undefined a4
+; RV32E-NEXT: .cfi_undefined a5
; RV32E-NEXT: mipopret
;
; RV64-LABEL: m_push_pop_empty:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: .cfi_undefined a0
+; RV64-NEXT: .cfi_undefined a1
+; RV64-NEXT: .cfi_undefined a2
+; RV64-NEXT: .cfi_undefined a3
+; RV64-NEXT: .cfi_undefined a4
+; RV64-NEXT: .cfi_undefined a5
; RV64-NEXT: mipopret
;
; RV64E-LABEL: m_push_pop_empty:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: .cfi_undefined a0
+; RV64E-NEXT: .cfi_undefined a1
+; RV64E-NEXT: .cfi_undefined a2
+; RV64E-NEXT: .cfi_undefined a3
+; RV64E-NEXT: .cfi_undefined a4
+; RV64E-NEXT: .cfi_undefined a5
; RV64E-NEXT: mipopret
ret void
}
@@ -1465,21 +1609,45 @@ 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: .cfi_undefined a0
+; RV32-NEXT: .cfi_undefined a1
+; RV32-NEXT: .cfi_undefined a2
+; RV32-NEXT: .cfi_undefined a3
+; RV32-NEXT: .cfi_undefined a4
+; RV32-NEXT: .cfi_undefined a5
; RV32-NEXT: sipopret
;
; RV32E-LABEL: s_push_pop_empty:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: .cfi_undefined a0
+; RV32E-NEXT: .cfi_undefined a1
+; RV32E-NEXT: .cfi_undefined a2
+; RV32E-NEXT: .cfi_undefined a3
+; RV32E-NEXT: .cfi_undefined a4
+; RV32E-NEXT: .cfi_undefined a5
; RV32E-NEXT: sipopret
;
; RV64-LABEL: s_push_pop_empty:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: .cfi_undefined a0
+; RV64-NEXT: .cfi_undefined a1
+; RV64-NEXT: .cfi_undefined a2
+; RV64-NEXT: .cfi_undefined a3
+; RV64-NEXT: .cfi_undefined a4
+; RV64-NEXT: .cfi_undefined a5
; RV64-NEXT: sipopret
;
; RV64E-LABEL: s_push_pop_empty:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: .cfi_undefined a0
+; RV64E-NEXT: .cfi_undefined a1
+; RV64E-NEXT: .cfi_undefined a2
+; RV64E-NEXT: .cfi_undefined a3
+; RV64E-NEXT: .cfi_undefined a4
+; RV64E-NEXT: .cfi_undefined a5
; RV64E-NEXT: sipopret
ret void
}
@@ -1488,6 +1656,12 @@ 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: .cfi_undefined a0
+; RV32-NEXT: .cfi_undefined a1
+; RV32-NEXT: .cfi_undefined a2
+; RV32-NEXT: .cfi_undefined a3
+; RV32-NEXT: .cfi_undefined a4
+; RV32-NEXT: .cfi_undefined a5
; RV32-NEXT: addi sp, sp, -16
; RV32-NEXT: .cfi_def_cfa_offset 48
; RV32-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
@@ -1509,6 +1683,12 @@ define void @m_push_pop_fp() #8 {
; RV32E-LABEL: m_push_pop_fp:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: .cfi_undefined a0
+; RV32E-NEXT: .cfi_undefined a1
+; RV32E-NEXT: .cfi_undefined a2
+; RV32E-NEXT: .cfi_undefined a3
+; RV32E-NEXT: .cfi_undefined a4
+; RV32E-NEXT: .cfi_undefined a5
; RV32E-NEXT: addi sp, sp, -12
; RV32E-NEXT: .cfi_def_cfa_offset 36
; RV32E-NEXT: sw ra, 8(sp) # 4-byte Folded Spill
@@ -1530,6 +1710,12 @@ define void @m_push_pop_fp() #8 {
; RV64-LABEL: m_push_pop_fp:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: .cfi_undefined a0
+; RV64-NEXT: .cfi_undefined a1
+; RV64-NEXT: .cfi_undefined a2
+; RV64-NEXT: .cfi_undefined a3
+; RV64-NEXT: .cfi_undefined a4
+; RV64-NEXT: .cfi_undefined a5
; RV64-NEXT: addi sp, sp, -32
; RV64-NEXT: .cfi_def_cfa_offset 80
; RV64-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
@@ -1551,6 +1737,12 @@ define void @m_push_pop_fp() #8 {
; RV64E-LABEL: m_push_pop_fp:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: .cfi_undefined a0
+; RV64E-NEXT: .cfi_undefined a1
+; RV64E-NEXT: .cfi_undefined a2
+; RV64E-NEXT: .cfi_undefined a3
+; RV64E-NEXT: .cfi_undefined a4
+; RV64E-NEXT: .cfi_undefined a5
; RV64E-NEXT: addi sp, sp, -24
; RV64E-NEXT: .cfi_def_cfa_offset 72
; RV64E-NEXT: sd ra, 16(sp) # 8-byte Folded Spill
@@ -1577,6 +1769,12 @@ define void @m_push_pop_scs() #9 {
; RV32-LABEL: m_push_pop_scs:
; RV32: # %bb.0:
; RV32-NEXT: .cfi_def_cfa_offset 32
+; RV32-NEXT: .cfi_undefined a0
+; RV32-NEXT: .cfi_undefined a1
+; RV32-NEXT: .cfi_undefined a2
+; RV32-NEXT: .cfi_undefined a3
+; RV32-NEXT: .cfi_undefined a4
+; RV32-NEXT: .cfi_undefined a5
; RV32-NEXT: addi gp, gp, 4
; RV32-NEXT: sw ra, -4(gp)
; RV32-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x7c #
@@ -1633,6 +1831,12 @@ define void @m_push_pop_scs() #9 {
; RV32E-LABEL: m_push_pop_scs:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: .cfi_undefined a0
+; RV32E-NEXT: .cfi_undefined a1
+; RV32E-NEXT: .cfi_undefined a2
+; RV32E-NEXT: .cfi_undefined a3
+; RV32E-NEXT: .cfi_undefined a4
+; RV32E-NEXT: .cfi_undefined a5
; RV32E-NEXT: addi gp, gp, 4
; RV32E-NEXT: sw ra, -4(gp)
; RV32E-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x7c #
@@ -1665,6 +1869,12 @@ define void @m_push_pop_scs() #9 {
; RV64-LABEL: m_push_pop_scs:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: .cfi_undefined a0
+; RV64-NEXT: .cfi_undefined a1
+; RV64-NEXT: .cfi_undefined a2
+; RV64-NEXT: .cfi_undefined a3
+; RV64-NEXT: .cfi_undefined a4
+; RV64-NEXT: .cfi_undefined a5
; RV64-NEXT: addi gp, gp, 8
; RV64-NEXT: sd ra, -8(gp)
; RV64-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x78 #
@@ -1721,6 +1931,12 @@ define void @m_push_pop_scs() #9 {
; RV64E-LABEL: m_push_pop_scs:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
+; RV64E-NEXT: .cfi_undefined a0
+; RV64E-NEXT: .cfi_undefined a1
+; RV64E-NEXT: .cfi_undefined a2
+; RV64E-NEXT: .cfi_undefined a3
+; RV64E-NEXT: .cfi_undefined a4
+; RV64E-NEXT: .cfi_undefined a5
; RV64E-NEXT: addi gp, gp, 8
; RV64E-NEXT: sd ra, -8(gp)
; RV64E-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x78 #
diff --git a/llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll b/llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll
index bfad186343a906..cf8aea78948d3a 100644
--- a/llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll
@@ -160,6 +160,12 @@ 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: .cfi_undefined a0
+; RV32-NEXT: .cfi_undefined a1
+; RV32-NEXT: .cfi_undefined a2
+; RV32-NEXT: .cfi_undefined a3
+; RV32-NEXT: .cfi_undefined a4
+; RV32-NEXT: .cfi_undefined a5
; RV32-NEXT: addi sp, sp, -32
; RV32-NEXT: .cfi_def_cfa_offset 64
; RV32-NEXT: sw t0, 16(sp) # 4-byte Folded Spill
@@ -193,6 +199,12 @@ define void @s_preemptible_push_pop_fp() #1 {
; RV32E-LABEL: s_preemptible_push_pop_fp:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
+; RV32E-NEXT: .cfi_undefined a0
+; RV32E-NEXT: .cfi_undefined a1
+; RV32E-NEXT: .cfi_undefined a2
+; RV32E-NEXT: .cfi_undefined a3
+; RV32E-NEXT: .cfi_undefined a4
+; RV32E-NEXT: .cfi_undefined a5
; RV32E-NEXT: addi sp, sp, -24
; RV32E-NEXT: .cfi_def_cfa_offset 48
; RV32E-NEXT: sw t0, 8(sp) # 4-byte Folded Spill
@@ -226,6 +238,12 @@ define void @s_preemptible_push_pop_fp() #1 {
; RV64-LABEL: s_preemptible_push_pop_fp:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
+; RV64-NEXT: .cfi_undefined a0
+; RV64-NEXT: .cfi_undefined a1
+; RV64-NEXT: .cfi_undefined a2
+; RV64-NEXT: .cfi_undefined a3
+; RV64-NEXT: .cfi_undefined a4
+; RV64-NEXT: .cfi_undefined a5
; RV64-NEXT: addi sp, sp, -48
; RV64-NEXT: .cfi_def_cfa_offset 96
; RV64-NEXT: sd t0, 16(sp) # 8-byte Folded Spill
>From c026ce6e4fb1aad4736d8aea6a8ec90dc19b25f4 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <zeyi2 at nekoarch.cc>
Date: Thu, 26 Nov 2026 02:27:11 +0000
Subject: [PATCH 09/12] shrink wrapping cleanup
---
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 083a00355ccaf8..fb2c122805f50e 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -2837,15 +2837,15 @@ bool RISCVFrameLowering::enableShrinkWrapping(const MachineFunction &MF) const {
RVFI->isACLICPushPopInterrupt(MF))
return false;
- // Keep the conventional code flow when not optimizing.
- if (MF.getFunction().hasOptNone())
- return false;
-
// QCI and SiFive CLIC interrupt entry sequences must precede all handler
// code.
if (RVFI->useQCIInterrupt(MF) || RVFI->useSiFiveInterrupt(MF))
return false;
+ // Keep the conventional code flow when not optimizing.
+ if (MF.getFunction().hasOptNone())
+ return false;
+
return true;
}
>From 0c23c3de51f3729d1dc5226eafa490355040ae7d Mon Sep 17 00:00:00 2001
From: Zeyi Xu <zeyi2 at nekoarch.cc>
Date: Thu, 26 Nov 2026 02:27:48 +0000
Subject: [PATCH 10/12] sema cleanup
---
clang/lib/Sema/SemaRISCV.cpp | 42 ++++++++++++++++++------------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/clang/lib/Sema/SemaRISCV.cpp b/clang/lib/Sema/SemaRISCV.cpp
index dadf1c3ae2c191..f3bd0734c7a6b9 100644
--- a/clang/lib/Sema/SemaRISCV.cpp
+++ b/clang/lib/Sema/SemaRISCV.cpp
@@ -1770,27 +1770,6 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
for (RISCVInterruptAttr::InterruptType Type : Types) {
switch (Type) {
- // The QCI interrupt types require Xqciint
- case RISCVInterruptAttr::qcinest:
- case RISCVInterruptAttr::qcinonest: {
- if (!HasFeature("xqciint")) {
- Diag(AL.getLoc(),
- diag::err_riscv_attribute_interrupt_requires_extension)
- << RISCVInterruptAttr::ConvertInterruptTypeToStr(Type) << "Xqciint";
- return;
- }
- } break;
- // The SiFive CLIC interrupt types require Xsfmclic
- case RISCVInterruptAttr::SiFiveCLICPreemptible:
- case RISCVInterruptAttr::SiFiveCLICStackSwap: {
- if (!HasFeature("experimental-xsfmclic")) {
- Diag(AL.getLoc(),
- diag::err_riscv_attribute_interrupt_requires_extension)
- << RISCVInterruptAttr::ConvertInterruptTypeToStr(Type)
- << "XSfmclic";
- return;
- }
- } break;
case RISCVInterruptAttr::rnmi: {
if (!HasFeature("smrnmi")) {
Diag(AL.getLoc(),
@@ -1819,6 +1798,27 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
return;
}
} break;
+ // The QCI interrupt types require Xqciint
+ case RISCVInterruptAttr::qcinest:
+ case RISCVInterruptAttr::qcinonest: {
+ if (!HasFeature("xqciint")) {
+ Diag(AL.getLoc(),
+ diag::err_riscv_attribute_interrupt_requires_extension)
+ << RISCVInterruptAttr::ConvertInterruptTypeToStr(Type) << "Xqciint";
+ return;
+ }
+ } break;
+ // The SiFive CLIC interrupt types require Xsfmclic
+ case RISCVInterruptAttr::SiFiveCLICPreemptible:
+ case RISCVInterruptAttr::SiFiveCLICStackSwap: {
+ if (!HasFeature("experimental-xsfmclic")) {
+ Diag(AL.getLoc(),
+ diag::err_riscv_attribute_interrupt_requires_extension)
+ << RISCVInterruptAttr::ConvertInterruptTypeToStr(Type)
+ << "XSfmclic";
+ return;
+ }
+ } break;
default:
break;
}
>From 1e3a34e884cdc5a94bd431c78ead6ed805170681 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <zeyi2 at nekoarch.cc>
Date: Thu, 26 Nov 2026 05:02:05 +0000
Subject: [PATCH 11/12] address feedback pt.3, and add baseline for zilsd
---
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 53 ++-
.../CodeGen/RISCV/aclic-interrupt-attr.ll | 432 +++++++++---------
.../RISCV/aclic-interrupt-frame-pointer.ll | 36 +-
.../CodeGen/RISCV/aclic-interrupt-zilsd.ll | 105 +++++
4 files changed, 385 insertions(+), 241 deletions(-)
create mode 100644 llvm/test/CodeGen/RISCV/aclic-interrupt-zilsd.ll
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index fb2c122805f50e..2f29012353e0d2 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -76,6 +76,14 @@ static uint64_t getACLICInterruptPushAmount(const MachineFunction &MF) {
return STI.hasStdExtE() ? 24 : 32;
}
+// FIXME: These offsets are placeholders. ACLIC does not yet define where
+// Smip/Ssip store a0-a5 within the hardware-pushed frame. Update them
+// to agree with the architecture once the frame layout is specified.
+static const std::pair<MCPhysReg, int8_t> FixedCSRFIACLICInterruptMap[] = {
+ {/*a0*/ RISCV::X10, -1}, {/*a1*/ RISCV::X11, -2}, {/*a2*/ RISCV::X12, -3},
+ {/*a3*/ RISCV::X13, -4}, {/*a4*/ RISCV::X14, -5}, {/*a5*/ RISCV::X15, -6},
+};
+
static const std::pair<MCPhysReg, int8_t> FixedCSRFIQCIInterruptMap[] = {
/* -1 is a gap for mepc/mnepc */
{/*fp*/ FPReg, -2},
@@ -771,6 +779,24 @@ getQCISavedInfo(const MachineFunction &MF,
return QCIInterruptCSI;
}
+static SmallVector<CalleeSavedInfo, 8>
+getACLICSavedInfo(const MachineFunction &MF,
+ const std::vector<CalleeSavedInfo> &CSI) {
+ auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
+
+ SmallVector<CalleeSavedInfo, 8> ACLICInterruptCSI;
+ if (!RVFI->isACLICPushPopInterrupt(MF))
+ return ACLICInterruptCSI;
+
+ for (const auto &CS : CSI) {
+ if (llvm::is_contained(llvm::make_first_range(FixedCSRFIACLICInterruptMap),
+ CS.getReg()))
+ ACLICInterruptCSI.push_back(CS);
+ }
+
+ return ACLICInterruptCSI;
+}
+
static void getLiveRegsForEntryMBB(LivePhysRegs &LiveRegs,
const MachineBasicBlock &MBB) {
const MachineFunction *MF = MBB.getParent();
@@ -1126,8 +1152,10 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
if (needsDwarfCFI(MF) && RVFI->isACLICPushPopInterrupt(MF)) {
CFIInstBuilder CFIBuilder(MBB, MBBI, MachineInstr::FrameSetup);
CFIBuilder.buildDefCFAOffset(RVFI->getACLICInterruptStackSize());
- for (MCPhysReg Reg = RISCV::X10; Reg <= RISCV::X15; ++Reg)
- CFIBuilder.buildUndefined(Reg);
+ for (const CalleeSavedInfo &CS :
+ getACLICSavedInfo(MF, MFI.getCalleeSavedInfo()))
+ CFIBuilder.buildOffset(CS.getReg(),
+ MFI.getObjectOffset(CS.getFrameIdx()));
}
// SiFive CLIC needs to swap `sp` into `sf.mscratchcsw`
@@ -2011,10 +2039,6 @@ void RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
if (RVFI->isPushable(MF) && SavedRegs.test(RISCV::X26))
SavedRegs.set(RISCV::X27);
- if (RVFI->isACLICPushPopInterrupt(MF))
- for (MCPhysReg Reg = RISCV::X10; Reg <= RISCV::X15; ++Reg)
- SavedRegs.reset(Reg);
-
// For Zilsd on RV32, append GPRPair registers to the CSR list. This prevents
// the need to create register sets for each abi which is a lot more complex.
// Don't use Zilsd for callee-saved coalescing if the required alignment
@@ -2401,7 +2425,8 @@ RISCVFrameLowering::getFirstSPAdjustAmount(const MachineFunction &MF) const {
// Return the FirstSPAdjustAmount if the StackSize can not fit in a signed
// 12-bit and there exists a callee-saved register needing to be pushed.
- if (!isInt<12>(StackSize) && (CSI.size() > 0)) {
+ if (!isInt<12>(StackSize) &&
+ (CSI.size() > getACLICSavedInfo(MF, CSI).size())) {
// FirstSPAdjustAmount is chosen at most as (2048 - StackAlign) because
// 2048 will cause sp = sp + 2048 in the epilogue to be split into multiple
// instructions. Offsets smaller than 2048 can fit in a single load/store
@@ -2517,6 +2542,20 @@ bool RISCVFrameLowering::assignCalleeSavedSpillSlots(
}
}
+ if (RVFI->isACLICPushPopInterrupt(MF)) {
+ const auto *FFI = llvm::find_if(FixedCSRFIACLICInterruptMap, [&](auto P) {
+ return P.first == CS.getReg();
+ });
+ if (FFI != std::end(FixedCSRFIACLICInterruptMap)) {
+ int64_t Offset = FFI->second * (int64_t)Size;
+
+ int FrameIdx = MFI.CreateFixedSpillStackObject(Size, Offset);
+ assert(FrameIdx < 0);
+ CS.setFrameIdx(FrameIdx);
+ continue;
+ }
+ }
+
if (RVFI->useSaveRestoreLibCalls(MF) || RVFI->isPushable(MF)) {
const auto *FII = llvm::find_if(
FixedCSRFIMap, [&](MCPhysReg P) { return P == CS.getReg(); });
diff --git a/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
index 95aedc7b60fb7c..4e0f78659df0a2 100644
--- a/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
@@ -758,12 +758,12 @@ define void @m_push_pop() #2 {
; RV32-LABEL: m_push_pop:
; RV32: # %bb.0:
; RV32-NEXT: .cfi_def_cfa_offset 32
-; RV32-NEXT: .cfi_undefined a0
-; RV32-NEXT: .cfi_undefined a1
-; RV32-NEXT: .cfi_undefined a2
-; RV32-NEXT: .cfi_undefined a3
-; RV32-NEXT: .cfi_undefined a4
-; RV32-NEXT: .cfi_undefined a5
+; RV32-NEXT: .cfi_offset a0, -4
+; RV32-NEXT: .cfi_offset a1, -8
+; RV32-NEXT: .cfi_offset a2, -12
+; RV32-NEXT: .cfi_offset a3, -16
+; RV32-NEXT: .cfi_offset a4, -20
+; RV32-NEXT: .cfi_offset a5, -24
; RV32-NEXT: addi sp, sp, -48
; RV32-NEXT: .cfi_def_cfa_offset 80
; RV32-NEXT: sw ra, 44(sp) # 4-byte Folded Spill
@@ -814,12 +814,12 @@ define void @m_push_pop() #2 {
; RV32E-LABEL: m_push_pop:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
-; RV32E-NEXT: .cfi_undefined a0
-; RV32E-NEXT: .cfi_undefined a1
-; RV32E-NEXT: .cfi_undefined a2
-; RV32E-NEXT: .cfi_undefined a3
-; RV32E-NEXT: .cfi_undefined a4
-; RV32E-NEXT: .cfi_undefined a5
+; RV32E-NEXT: .cfi_offset a0, -4
+; RV32E-NEXT: .cfi_offset a1, -8
+; RV32E-NEXT: .cfi_offset a2, -12
+; RV32E-NEXT: .cfi_offset a3, -16
+; RV32E-NEXT: .cfi_offset a4, -20
+; RV32E-NEXT: .cfi_offset a5, -24
; RV32E-NEXT: addi sp, sp, -16
; RV32E-NEXT: .cfi_def_cfa_offset 40
; RV32E-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
@@ -846,12 +846,12 @@ define void @m_push_pop() #2 {
; RV64-LABEL: m_push_pop:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
-; RV64-NEXT: .cfi_undefined a0
-; RV64-NEXT: .cfi_undefined a1
-; RV64-NEXT: .cfi_undefined a2
-; RV64-NEXT: .cfi_undefined a3
-; RV64-NEXT: .cfi_undefined a4
-; RV64-NEXT: .cfi_undefined a5
+; RV64-NEXT: .cfi_offset a0, -8
+; RV64-NEXT: .cfi_offset a1, -16
+; RV64-NEXT: .cfi_offset a2, -24
+; RV64-NEXT: .cfi_offset a3, -32
+; RV64-NEXT: .cfi_offset a4, -40
+; RV64-NEXT: .cfi_offset a5, -48
; RV64-NEXT: addi sp, sp, -80
; RV64-NEXT: .cfi_def_cfa_offset 128
; RV64-NEXT: sd ra, 72(sp) # 8-byte Folded Spill
@@ -902,12 +902,12 @@ define void @m_push_pop() #2 {
; RV64E-LABEL: m_push_pop:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
-; RV64E-NEXT: .cfi_undefined a0
-; RV64E-NEXT: .cfi_undefined a1
-; RV64E-NEXT: .cfi_undefined a2
-; RV64E-NEXT: .cfi_undefined a3
-; RV64E-NEXT: .cfi_undefined a4
-; RV64E-NEXT: .cfi_undefined a5
+; RV64E-NEXT: .cfi_offset a0, -8
+; RV64E-NEXT: .cfi_offset a1, -16
+; RV64E-NEXT: .cfi_offset a2, -24
+; RV64E-NEXT: .cfi_offset a3, -32
+; RV64E-NEXT: .cfi_offset a4, -40
+; RV64E-NEXT: .cfi_offset a5, -48
; RV64E-NEXT: addi sp, sp, -32
; RV64E-NEXT: .cfi_def_cfa_offset 80
; RV64E-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
@@ -938,12 +938,12 @@ define void @s_push_pop() #3 {
; RV32-LABEL: s_push_pop:
; RV32: # %bb.0:
; RV32-NEXT: .cfi_def_cfa_offset 32
-; RV32-NEXT: .cfi_undefined a0
-; RV32-NEXT: .cfi_undefined a1
-; RV32-NEXT: .cfi_undefined a2
-; RV32-NEXT: .cfi_undefined a3
-; RV32-NEXT: .cfi_undefined a4
-; RV32-NEXT: .cfi_undefined a5
+; RV32-NEXT: .cfi_offset a0, -4
+; RV32-NEXT: .cfi_offset a1, -8
+; RV32-NEXT: .cfi_offset a2, -12
+; RV32-NEXT: .cfi_offset a3, -16
+; RV32-NEXT: .cfi_offset a4, -20
+; RV32-NEXT: .cfi_offset a5, -24
; RV32-NEXT: addi sp, sp, -48
; RV32-NEXT: .cfi_def_cfa_offset 80
; RV32-NEXT: sw ra, 44(sp) # 4-byte Folded Spill
@@ -994,12 +994,12 @@ define void @s_push_pop() #3 {
; RV32E-LABEL: s_push_pop:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
-; RV32E-NEXT: .cfi_undefined a0
-; RV32E-NEXT: .cfi_undefined a1
-; RV32E-NEXT: .cfi_undefined a2
-; RV32E-NEXT: .cfi_undefined a3
-; RV32E-NEXT: .cfi_undefined a4
-; RV32E-NEXT: .cfi_undefined a5
+; RV32E-NEXT: .cfi_offset a0, -4
+; RV32E-NEXT: .cfi_offset a1, -8
+; RV32E-NEXT: .cfi_offset a2, -12
+; RV32E-NEXT: .cfi_offset a3, -16
+; RV32E-NEXT: .cfi_offset a4, -20
+; RV32E-NEXT: .cfi_offset a5, -24
; RV32E-NEXT: addi sp, sp, -16
; RV32E-NEXT: .cfi_def_cfa_offset 40
; RV32E-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
@@ -1026,12 +1026,12 @@ define void @s_push_pop() #3 {
; RV64-LABEL: s_push_pop:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
-; RV64-NEXT: .cfi_undefined a0
-; RV64-NEXT: .cfi_undefined a1
-; RV64-NEXT: .cfi_undefined a2
-; RV64-NEXT: .cfi_undefined a3
-; RV64-NEXT: .cfi_undefined a4
-; RV64-NEXT: .cfi_undefined a5
+; RV64-NEXT: .cfi_offset a0, -8
+; RV64-NEXT: .cfi_offset a1, -16
+; RV64-NEXT: .cfi_offset a2, -24
+; RV64-NEXT: .cfi_offset a3, -32
+; RV64-NEXT: .cfi_offset a4, -40
+; RV64-NEXT: .cfi_offset a5, -48
; RV64-NEXT: addi sp, sp, -80
; RV64-NEXT: .cfi_def_cfa_offset 128
; RV64-NEXT: sd ra, 72(sp) # 8-byte Folded Spill
@@ -1082,12 +1082,12 @@ define void @s_push_pop() #3 {
; RV64E-LABEL: s_push_pop:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
-; RV64E-NEXT: .cfi_undefined a0
-; RV64E-NEXT: .cfi_undefined a1
-; RV64E-NEXT: .cfi_undefined a2
-; RV64E-NEXT: .cfi_undefined a3
-; RV64E-NEXT: .cfi_undefined a4
-; RV64E-NEXT: .cfi_undefined a5
+; RV64E-NEXT: .cfi_offset a0, -8
+; RV64E-NEXT: .cfi_offset a1, -16
+; RV64E-NEXT: .cfi_offset a2, -24
+; RV64E-NEXT: .cfi_offset a3, -32
+; RV64E-NEXT: .cfi_offset a4, -40
+; RV64E-NEXT: .cfi_offset a5, -48
; RV64E-NEXT: addi sp, sp, -32
; RV64E-NEXT: .cfi_def_cfa_offset 80
; RV64E-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
@@ -1118,12 +1118,12 @@ define void @m_combined() #4 {
; RV32-LABEL: m_combined:
; RV32: # %bb.0:
; RV32-NEXT: .cfi_def_cfa_offset 32
-; RV32-NEXT: .cfi_undefined a0
-; RV32-NEXT: .cfi_undefined a1
-; RV32-NEXT: .cfi_undefined a2
-; RV32-NEXT: .cfi_undefined a3
-; RV32-NEXT: .cfi_undefined a4
-; RV32-NEXT: .cfi_undefined a5
+; RV32-NEXT: .cfi_offset a0, -4
+; RV32-NEXT: .cfi_offset a1, -8
+; RV32-NEXT: .cfi_offset a2, -12
+; RV32-NEXT: .cfi_offset a3, -16
+; RV32-NEXT: .cfi_offset a4, -20
+; RV32-NEXT: .cfi_offset a5, -24
; RV32-NEXT: addi sp, sp, -16
; RV32-NEXT: .cfi_def_cfa_offset 48
; RV32-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
@@ -1146,12 +1146,12 @@ define void @m_combined() #4 {
; RV32E-LABEL: m_combined:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
-; RV32E-NEXT: .cfi_undefined a0
-; RV32E-NEXT: .cfi_undefined a1
-; RV32E-NEXT: .cfi_undefined a2
-; RV32E-NEXT: .cfi_undefined a3
-; RV32E-NEXT: .cfi_undefined a4
-; RV32E-NEXT: .cfi_undefined a5
+; RV32E-NEXT: .cfi_offset a0, -4
+; RV32E-NEXT: .cfi_offset a1, -8
+; RV32E-NEXT: .cfi_offset a2, -12
+; RV32E-NEXT: .cfi_offset a3, -16
+; RV32E-NEXT: .cfi_offset a4, -20
+; RV32E-NEXT: .cfi_offset a5, -24
; RV32E-NEXT: addi sp, sp, -16
; RV32E-NEXT: .cfi_def_cfa_offset 40
; RV32E-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
@@ -1174,12 +1174,12 @@ define void @m_combined() #4 {
; RV64-LABEL: m_combined:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
-; RV64-NEXT: .cfi_undefined a0
-; RV64-NEXT: .cfi_undefined a1
-; RV64-NEXT: .cfi_undefined a2
-; RV64-NEXT: .cfi_undefined a3
-; RV64-NEXT: .cfi_undefined a4
-; RV64-NEXT: .cfi_undefined a5
+; RV64-NEXT: .cfi_offset a0, -8
+; RV64-NEXT: .cfi_offset a1, -16
+; RV64-NEXT: .cfi_offset a2, -24
+; RV64-NEXT: .cfi_offset a3, -32
+; RV64-NEXT: .cfi_offset a4, -40
+; RV64-NEXT: .cfi_offset a5, -48
; RV64-NEXT: addi sp, sp, -32
; RV64-NEXT: .cfi_def_cfa_offset 80
; RV64-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
@@ -1202,12 +1202,12 @@ define void @m_combined() #4 {
; RV64E-LABEL: m_combined:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
-; RV64E-NEXT: .cfi_undefined a0
-; RV64E-NEXT: .cfi_undefined a1
-; RV64E-NEXT: .cfi_undefined a2
-; RV64E-NEXT: .cfi_undefined a3
-; RV64E-NEXT: .cfi_undefined a4
-; RV64E-NEXT: .cfi_undefined a5
+; RV64E-NEXT: .cfi_offset a0, -8
+; RV64E-NEXT: .cfi_offset a1, -16
+; RV64E-NEXT: .cfi_offset a2, -24
+; RV64E-NEXT: .cfi_offset a3, -32
+; RV64E-NEXT: .cfi_offset a4, -40
+; RV64E-NEXT: .cfi_offset a5, -48
; RV64E-NEXT: addi sp, sp, -32
; RV64E-NEXT: .cfi_def_cfa_offset 80
; RV64E-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
@@ -1235,12 +1235,12 @@ define void @s_combined() #5 {
; RV32-LABEL: s_combined:
; RV32: # %bb.0:
; RV32-NEXT: .cfi_def_cfa_offset 32
-; RV32-NEXT: .cfi_undefined a0
-; RV32-NEXT: .cfi_undefined a1
-; RV32-NEXT: .cfi_undefined a2
-; RV32-NEXT: .cfi_undefined a3
-; RV32-NEXT: .cfi_undefined a4
-; RV32-NEXT: .cfi_undefined a5
+; RV32-NEXT: .cfi_offset a0, -4
+; RV32-NEXT: .cfi_offset a1, -8
+; RV32-NEXT: .cfi_offset a2, -12
+; RV32-NEXT: .cfi_offset a3, -16
+; RV32-NEXT: .cfi_offset a4, -20
+; RV32-NEXT: .cfi_offset a5, -24
; RV32-NEXT: addi sp, sp, -16
; RV32-NEXT: .cfi_def_cfa_offset 48
; RV32-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
@@ -1263,12 +1263,12 @@ define void @s_combined() #5 {
; RV32E-LABEL: s_combined:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
-; RV32E-NEXT: .cfi_undefined a0
-; RV32E-NEXT: .cfi_undefined a1
-; RV32E-NEXT: .cfi_undefined a2
-; RV32E-NEXT: .cfi_undefined a3
-; RV32E-NEXT: .cfi_undefined a4
-; RV32E-NEXT: .cfi_undefined a5
+; RV32E-NEXT: .cfi_offset a0, -4
+; RV32E-NEXT: .cfi_offset a1, -8
+; RV32E-NEXT: .cfi_offset a2, -12
+; RV32E-NEXT: .cfi_offset a3, -16
+; RV32E-NEXT: .cfi_offset a4, -20
+; RV32E-NEXT: .cfi_offset a5, -24
; RV32E-NEXT: addi sp, sp, -16
; RV32E-NEXT: .cfi_def_cfa_offset 40
; RV32E-NEXT: sw t0, 4(sp) # 4-byte Folded Spill
@@ -1291,12 +1291,12 @@ define void @s_combined() #5 {
; RV64-LABEL: s_combined:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
-; RV64-NEXT: .cfi_undefined a0
-; RV64-NEXT: .cfi_undefined a1
-; RV64-NEXT: .cfi_undefined a2
-; RV64-NEXT: .cfi_undefined a3
-; RV64-NEXT: .cfi_undefined a4
-; RV64-NEXT: .cfi_undefined a5
+; RV64-NEXT: .cfi_offset a0, -8
+; RV64-NEXT: .cfi_offset a1, -16
+; RV64-NEXT: .cfi_offset a2, -24
+; RV64-NEXT: .cfi_offset a3, -32
+; RV64-NEXT: .cfi_offset a4, -40
+; RV64-NEXT: .cfi_offset a5, -48
; RV64-NEXT: addi sp, sp, -32
; RV64-NEXT: .cfi_def_cfa_offset 80
; RV64-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
@@ -1319,12 +1319,12 @@ define void @s_combined() #5 {
; RV64E-LABEL: s_combined:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
-; RV64E-NEXT: .cfi_undefined a0
-; RV64E-NEXT: .cfi_undefined a1
-; RV64E-NEXT: .cfi_undefined a2
-; RV64E-NEXT: .cfi_undefined a3
-; RV64E-NEXT: .cfi_undefined a4
-; RV64E-NEXT: .cfi_undefined a5
+; RV64E-NEXT: .cfi_offset a0, -8
+; RV64E-NEXT: .cfi_offset a1, -16
+; RV64E-NEXT: .cfi_offset a2, -24
+; RV64E-NEXT: .cfi_offset a3, -32
+; RV64E-NEXT: .cfi_offset a4, -40
+; RV64E-NEXT: .cfi_offset a5, -48
; RV64E-NEXT: addi sp, sp, -32
; RV64E-NEXT: .cfi_def_cfa_offset 80
; RV64E-NEXT: sd t0, 8(sp) # 8-byte Folded Spill
@@ -1352,12 +1352,12 @@ 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: .cfi_undefined a0
-; RV32-NEXT: .cfi_undefined a1
-; RV32-NEXT: .cfi_undefined a2
-; RV32-NEXT: .cfi_undefined a3
-; RV32-NEXT: .cfi_undefined a4
-; RV32-NEXT: .cfi_undefined a5
+; RV32-NEXT: .cfi_offset a0, -4
+; RV32-NEXT: .cfi_offset a1, -8
+; RV32-NEXT: .cfi_offset a2, -12
+; RV32-NEXT: .cfi_offset a3, -16
+; RV32-NEXT: .cfi_offset a4, -20
+; RV32-NEXT: .cfi_offset a5, -24
; RV32-NEXT: addi sp, sp, -2000
; RV32-NEXT: .cfi_def_cfa_offset 2032
; RV32-NEXT: sw ra, 1996(sp) # 4-byte Folded Spill
@@ -1415,12 +1415,12 @@ define void @m_push_pop_large() #2 {
; RV32E-LABEL: m_push_pop_large:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
-; RV32E-NEXT: .cfi_undefined a0
-; RV32E-NEXT: .cfi_undefined a1
-; RV32E-NEXT: .cfi_undefined a2
-; RV32E-NEXT: .cfi_undefined a3
-; RV32E-NEXT: .cfi_undefined a4
-; RV32E-NEXT: .cfi_undefined a5
+; RV32E-NEXT: .cfi_offset a0, -4
+; RV32E-NEXT: .cfi_offset a1, -8
+; RV32E-NEXT: .cfi_offset a2, -12
+; RV32E-NEXT: .cfi_offset a3, -16
+; RV32E-NEXT: .cfi_offset a4, -20
+; RV32E-NEXT: .cfi_offset a5, -24
; RV32E-NEXT: addi sp, sp, -2020
; RV32E-NEXT: .cfi_def_cfa_offset 2044
; RV32E-NEXT: sw ra, 2016(sp) # 4-byte Folded Spill
@@ -1454,12 +1454,12 @@ define void @m_push_pop_large() #2 {
; RV64-LABEL: m_push_pop_large:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
-; RV64-NEXT: .cfi_undefined a0
-; RV64-NEXT: .cfi_undefined a1
-; RV64-NEXT: .cfi_undefined a2
-; RV64-NEXT: .cfi_undefined a3
-; RV64-NEXT: .cfi_undefined a4
-; RV64-NEXT: .cfi_undefined a5
+; RV64-NEXT: .cfi_offset a0, -8
+; RV64-NEXT: .cfi_offset a1, -16
+; RV64-NEXT: .cfi_offset a2, -24
+; RV64-NEXT: .cfi_offset a3, -32
+; RV64-NEXT: .cfi_offset a4, -40
+; RV64-NEXT: .cfi_offset a5, -48
; RV64-NEXT: addi sp, sp, -1984
; RV64-NEXT: .cfi_def_cfa_offset 2032
; RV64-NEXT: sd ra, 1976(sp) # 8-byte Folded Spill
@@ -1517,12 +1517,12 @@ define void @m_push_pop_large() #2 {
; RV64E-LABEL: m_push_pop_large:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
-; RV64E-NEXT: .cfi_undefined a0
-; RV64E-NEXT: .cfi_undefined a1
-; RV64E-NEXT: .cfi_undefined a2
-; RV64E-NEXT: .cfi_undefined a3
-; RV64E-NEXT: .cfi_undefined a4
-; RV64E-NEXT: .cfi_undefined a5
+; RV64E-NEXT: .cfi_offset a0, -8
+; RV64E-NEXT: .cfi_offset a1, -16
+; RV64E-NEXT: .cfi_offset a2, -24
+; RV64E-NEXT: .cfi_offset a3, -32
+; RV64E-NEXT: .cfi_offset a4, -40
+; RV64E-NEXT: .cfi_offset a5, -48
; RV64E-NEXT: addi sp, sp, -1992
; RV64E-NEXT: .cfi_def_cfa_offset 2040
; RV64E-NEXT: sd ra, 1984(sp) # 8-byte Folded Spill
@@ -1562,45 +1562,45 @@ 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: .cfi_undefined a0
-; RV32-NEXT: .cfi_undefined a1
-; RV32-NEXT: .cfi_undefined a2
-; RV32-NEXT: .cfi_undefined a3
-; RV32-NEXT: .cfi_undefined a4
-; RV32-NEXT: .cfi_undefined a5
+; RV32-NEXT: .cfi_offset a0, -4
+; RV32-NEXT: .cfi_offset a1, -8
+; RV32-NEXT: .cfi_offset a2, -12
+; RV32-NEXT: .cfi_offset a3, -16
+; RV32-NEXT: .cfi_offset a4, -20
+; RV32-NEXT: .cfi_offset a5, -24
; RV32-NEXT: mipopret
;
; RV32E-LABEL: m_push_pop_empty:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
-; RV32E-NEXT: .cfi_undefined a0
-; RV32E-NEXT: .cfi_undefined a1
-; RV32E-NEXT: .cfi_undefined a2
-; RV32E-NEXT: .cfi_undefined a3
-; RV32E-NEXT: .cfi_undefined a4
-; RV32E-NEXT: .cfi_undefined a5
+; RV32E-NEXT: .cfi_offset a0, -4
+; RV32E-NEXT: .cfi_offset a1, -8
+; RV32E-NEXT: .cfi_offset a2, -12
+; RV32E-NEXT: .cfi_offset a3, -16
+; RV32E-NEXT: .cfi_offset a4, -20
+; RV32E-NEXT: .cfi_offset a5, -24
; RV32E-NEXT: mipopret
;
; RV64-LABEL: m_push_pop_empty:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
-; RV64-NEXT: .cfi_undefined a0
-; RV64-NEXT: .cfi_undefined a1
-; RV64-NEXT: .cfi_undefined a2
-; RV64-NEXT: .cfi_undefined a3
-; RV64-NEXT: .cfi_undefined a4
-; RV64-NEXT: .cfi_undefined a5
+; RV64-NEXT: .cfi_offset a0, -8
+; RV64-NEXT: .cfi_offset a1, -16
+; RV64-NEXT: .cfi_offset a2, -24
+; RV64-NEXT: .cfi_offset a3, -32
+; RV64-NEXT: .cfi_offset a4, -40
+; RV64-NEXT: .cfi_offset a5, -48
; RV64-NEXT: mipopret
;
; RV64E-LABEL: m_push_pop_empty:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
-; RV64E-NEXT: .cfi_undefined a0
-; RV64E-NEXT: .cfi_undefined a1
-; RV64E-NEXT: .cfi_undefined a2
-; RV64E-NEXT: .cfi_undefined a3
-; RV64E-NEXT: .cfi_undefined a4
-; RV64E-NEXT: .cfi_undefined a5
+; RV64E-NEXT: .cfi_offset a0, -8
+; RV64E-NEXT: .cfi_offset a1, -16
+; RV64E-NEXT: .cfi_offset a2, -24
+; RV64E-NEXT: .cfi_offset a3, -32
+; RV64E-NEXT: .cfi_offset a4, -40
+; RV64E-NEXT: .cfi_offset a5, -48
; RV64E-NEXT: mipopret
ret void
}
@@ -1609,45 +1609,45 @@ 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: .cfi_undefined a0
-; RV32-NEXT: .cfi_undefined a1
-; RV32-NEXT: .cfi_undefined a2
-; RV32-NEXT: .cfi_undefined a3
-; RV32-NEXT: .cfi_undefined a4
-; RV32-NEXT: .cfi_undefined a5
+; RV32-NEXT: .cfi_offset a0, -4
+; RV32-NEXT: .cfi_offset a1, -8
+; RV32-NEXT: .cfi_offset a2, -12
+; RV32-NEXT: .cfi_offset a3, -16
+; RV32-NEXT: .cfi_offset a4, -20
+; RV32-NEXT: .cfi_offset a5, -24
; RV32-NEXT: sipopret
;
; RV32E-LABEL: s_push_pop_empty:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
-; RV32E-NEXT: .cfi_undefined a0
-; RV32E-NEXT: .cfi_undefined a1
-; RV32E-NEXT: .cfi_undefined a2
-; RV32E-NEXT: .cfi_undefined a3
-; RV32E-NEXT: .cfi_undefined a4
-; RV32E-NEXT: .cfi_undefined a5
+; RV32E-NEXT: .cfi_offset a0, -4
+; RV32E-NEXT: .cfi_offset a1, -8
+; RV32E-NEXT: .cfi_offset a2, -12
+; RV32E-NEXT: .cfi_offset a3, -16
+; RV32E-NEXT: .cfi_offset a4, -20
+; RV32E-NEXT: .cfi_offset a5, -24
; RV32E-NEXT: sipopret
;
; RV64-LABEL: s_push_pop_empty:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
-; RV64-NEXT: .cfi_undefined a0
-; RV64-NEXT: .cfi_undefined a1
-; RV64-NEXT: .cfi_undefined a2
-; RV64-NEXT: .cfi_undefined a3
-; RV64-NEXT: .cfi_undefined a4
-; RV64-NEXT: .cfi_undefined a5
+; RV64-NEXT: .cfi_offset a0, -8
+; RV64-NEXT: .cfi_offset a1, -16
+; RV64-NEXT: .cfi_offset a2, -24
+; RV64-NEXT: .cfi_offset a3, -32
+; RV64-NEXT: .cfi_offset a4, -40
+; RV64-NEXT: .cfi_offset a5, -48
; RV64-NEXT: sipopret
;
; RV64E-LABEL: s_push_pop_empty:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
-; RV64E-NEXT: .cfi_undefined a0
-; RV64E-NEXT: .cfi_undefined a1
-; RV64E-NEXT: .cfi_undefined a2
-; RV64E-NEXT: .cfi_undefined a3
-; RV64E-NEXT: .cfi_undefined a4
-; RV64E-NEXT: .cfi_undefined a5
+; RV64E-NEXT: .cfi_offset a0, -8
+; RV64E-NEXT: .cfi_offset a1, -16
+; RV64E-NEXT: .cfi_offset a2, -24
+; RV64E-NEXT: .cfi_offset a3, -32
+; RV64E-NEXT: .cfi_offset a4, -40
+; RV64E-NEXT: .cfi_offset a5, -48
; RV64E-NEXT: sipopret
ret void
}
@@ -1656,12 +1656,12 @@ 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: .cfi_undefined a0
-; RV32-NEXT: .cfi_undefined a1
-; RV32-NEXT: .cfi_undefined a2
-; RV32-NEXT: .cfi_undefined a3
-; RV32-NEXT: .cfi_undefined a4
-; RV32-NEXT: .cfi_undefined a5
+; RV32-NEXT: .cfi_offset a0, -4
+; RV32-NEXT: .cfi_offset a1, -8
+; RV32-NEXT: .cfi_offset a2, -12
+; RV32-NEXT: .cfi_offset a3, -16
+; RV32-NEXT: .cfi_offset a4, -20
+; RV32-NEXT: .cfi_offset a5, -24
; RV32-NEXT: addi sp, sp, -16
; RV32-NEXT: .cfi_def_cfa_offset 48
; RV32-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
@@ -1683,12 +1683,12 @@ define void @m_push_pop_fp() #8 {
; RV32E-LABEL: m_push_pop_fp:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
-; RV32E-NEXT: .cfi_undefined a0
-; RV32E-NEXT: .cfi_undefined a1
-; RV32E-NEXT: .cfi_undefined a2
-; RV32E-NEXT: .cfi_undefined a3
-; RV32E-NEXT: .cfi_undefined a4
-; RV32E-NEXT: .cfi_undefined a5
+; RV32E-NEXT: .cfi_offset a0, -4
+; RV32E-NEXT: .cfi_offset a1, -8
+; RV32E-NEXT: .cfi_offset a2, -12
+; RV32E-NEXT: .cfi_offset a3, -16
+; RV32E-NEXT: .cfi_offset a4, -20
+; RV32E-NEXT: .cfi_offset a5, -24
; RV32E-NEXT: addi sp, sp, -12
; RV32E-NEXT: .cfi_def_cfa_offset 36
; RV32E-NEXT: sw ra, 8(sp) # 4-byte Folded Spill
@@ -1710,12 +1710,12 @@ define void @m_push_pop_fp() #8 {
; RV64-LABEL: m_push_pop_fp:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
-; RV64-NEXT: .cfi_undefined a0
-; RV64-NEXT: .cfi_undefined a1
-; RV64-NEXT: .cfi_undefined a2
-; RV64-NEXT: .cfi_undefined a3
-; RV64-NEXT: .cfi_undefined a4
-; RV64-NEXT: .cfi_undefined a5
+; RV64-NEXT: .cfi_offset a0, -8
+; RV64-NEXT: .cfi_offset a1, -16
+; RV64-NEXT: .cfi_offset a2, -24
+; RV64-NEXT: .cfi_offset a3, -32
+; RV64-NEXT: .cfi_offset a4, -40
+; RV64-NEXT: .cfi_offset a5, -48
; RV64-NEXT: addi sp, sp, -32
; RV64-NEXT: .cfi_def_cfa_offset 80
; RV64-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
@@ -1737,12 +1737,12 @@ define void @m_push_pop_fp() #8 {
; RV64E-LABEL: m_push_pop_fp:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
-; RV64E-NEXT: .cfi_undefined a0
-; RV64E-NEXT: .cfi_undefined a1
-; RV64E-NEXT: .cfi_undefined a2
-; RV64E-NEXT: .cfi_undefined a3
-; RV64E-NEXT: .cfi_undefined a4
-; RV64E-NEXT: .cfi_undefined a5
+; RV64E-NEXT: .cfi_offset a0, -8
+; RV64E-NEXT: .cfi_offset a1, -16
+; RV64E-NEXT: .cfi_offset a2, -24
+; RV64E-NEXT: .cfi_offset a3, -32
+; RV64E-NEXT: .cfi_offset a4, -40
+; RV64E-NEXT: .cfi_offset a5, -48
; RV64E-NEXT: addi sp, sp, -24
; RV64E-NEXT: .cfi_def_cfa_offset 72
; RV64E-NEXT: sd ra, 16(sp) # 8-byte Folded Spill
@@ -1769,12 +1769,12 @@ define void @m_push_pop_scs() #9 {
; RV32-LABEL: m_push_pop_scs:
; RV32: # %bb.0:
; RV32-NEXT: .cfi_def_cfa_offset 32
-; RV32-NEXT: .cfi_undefined a0
-; RV32-NEXT: .cfi_undefined a1
-; RV32-NEXT: .cfi_undefined a2
-; RV32-NEXT: .cfi_undefined a3
-; RV32-NEXT: .cfi_undefined a4
-; RV32-NEXT: .cfi_undefined a5
+; RV32-NEXT: .cfi_offset a0, -4
+; RV32-NEXT: .cfi_offset a1, -8
+; RV32-NEXT: .cfi_offset a2, -12
+; RV32-NEXT: .cfi_offset a3, -16
+; RV32-NEXT: .cfi_offset a4, -20
+; RV32-NEXT: .cfi_offset a5, -24
; RV32-NEXT: addi gp, gp, 4
; RV32-NEXT: sw ra, -4(gp)
; RV32-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x7c #
@@ -1831,12 +1831,12 @@ define void @m_push_pop_scs() #9 {
; RV32E-LABEL: m_push_pop_scs:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
-; RV32E-NEXT: .cfi_undefined a0
-; RV32E-NEXT: .cfi_undefined a1
-; RV32E-NEXT: .cfi_undefined a2
-; RV32E-NEXT: .cfi_undefined a3
-; RV32E-NEXT: .cfi_undefined a4
-; RV32E-NEXT: .cfi_undefined a5
+; RV32E-NEXT: .cfi_offset a0, -4
+; RV32E-NEXT: .cfi_offset a1, -8
+; RV32E-NEXT: .cfi_offset a2, -12
+; RV32E-NEXT: .cfi_offset a3, -16
+; RV32E-NEXT: .cfi_offset a4, -20
+; RV32E-NEXT: .cfi_offset a5, -24
; RV32E-NEXT: addi gp, gp, 4
; RV32E-NEXT: sw ra, -4(gp)
; RV32E-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x7c #
@@ -1869,12 +1869,12 @@ define void @m_push_pop_scs() #9 {
; RV64-LABEL: m_push_pop_scs:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
-; RV64-NEXT: .cfi_undefined a0
-; RV64-NEXT: .cfi_undefined a1
-; RV64-NEXT: .cfi_undefined a2
-; RV64-NEXT: .cfi_undefined a3
-; RV64-NEXT: .cfi_undefined a4
-; RV64-NEXT: .cfi_undefined a5
+; RV64-NEXT: .cfi_offset a0, -8
+; RV64-NEXT: .cfi_offset a1, -16
+; RV64-NEXT: .cfi_offset a2, -24
+; RV64-NEXT: .cfi_offset a3, -32
+; RV64-NEXT: .cfi_offset a4, -40
+; RV64-NEXT: .cfi_offset a5, -48
; RV64-NEXT: addi gp, gp, 8
; RV64-NEXT: sd ra, -8(gp)
; RV64-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x78 #
@@ -1931,12 +1931,12 @@ define void @m_push_pop_scs() #9 {
; RV64E-LABEL: m_push_pop_scs:
; RV64E: # %bb.0:
; RV64E-NEXT: .cfi_def_cfa_offset 48
-; RV64E-NEXT: .cfi_undefined a0
-; RV64E-NEXT: .cfi_undefined a1
-; RV64E-NEXT: .cfi_undefined a2
-; RV64E-NEXT: .cfi_undefined a3
-; RV64E-NEXT: .cfi_undefined a4
-; RV64E-NEXT: .cfi_undefined a5
+; RV64E-NEXT: .cfi_offset a0, -8
+; RV64E-NEXT: .cfi_offset a1, -16
+; RV64E-NEXT: .cfi_offset a2, -24
+; RV64E-NEXT: .cfi_offset a3, -32
+; RV64E-NEXT: .cfi_offset a4, -40
+; RV64E-NEXT: .cfi_offset a5, -48
; RV64E-NEXT: addi gp, gp, 8
; RV64E-NEXT: sd ra, -8(gp)
; RV64E-NEXT: .cfi_escape 0x16, 0x03, 0x02, 0x73, 0x78 #
diff --git a/llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll b/llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll
index cf8aea78948d3a..9a27886a8728a9 100644
--- a/llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll
@@ -160,12 +160,12 @@ 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: .cfi_undefined a0
-; RV32-NEXT: .cfi_undefined a1
-; RV32-NEXT: .cfi_undefined a2
-; RV32-NEXT: .cfi_undefined a3
-; RV32-NEXT: .cfi_undefined a4
-; RV32-NEXT: .cfi_undefined a5
+; RV32-NEXT: .cfi_offset a0, -4
+; RV32-NEXT: .cfi_offset a1, -8
+; RV32-NEXT: .cfi_offset a2, -12
+; RV32-NEXT: .cfi_offset a3, -16
+; RV32-NEXT: .cfi_offset a4, -20
+; RV32-NEXT: .cfi_offset a5, -24
; RV32-NEXT: addi sp, sp, -32
; RV32-NEXT: .cfi_def_cfa_offset 64
; RV32-NEXT: sw t0, 16(sp) # 4-byte Folded Spill
@@ -199,12 +199,12 @@ define void @s_preemptible_push_pop_fp() #1 {
; RV32E-LABEL: s_preemptible_push_pop_fp:
; RV32E: # %bb.0:
; RV32E-NEXT: .cfi_def_cfa_offset 24
-; RV32E-NEXT: .cfi_undefined a0
-; RV32E-NEXT: .cfi_undefined a1
-; RV32E-NEXT: .cfi_undefined a2
-; RV32E-NEXT: .cfi_undefined a3
-; RV32E-NEXT: .cfi_undefined a4
-; RV32E-NEXT: .cfi_undefined a5
+; RV32E-NEXT: .cfi_offset a0, -4
+; RV32E-NEXT: .cfi_offset a1, -8
+; RV32E-NEXT: .cfi_offset a2, -12
+; RV32E-NEXT: .cfi_offset a3, -16
+; RV32E-NEXT: .cfi_offset a4, -20
+; RV32E-NEXT: .cfi_offset a5, -24
; RV32E-NEXT: addi sp, sp, -24
; RV32E-NEXT: .cfi_def_cfa_offset 48
; RV32E-NEXT: sw t0, 8(sp) # 4-byte Folded Spill
@@ -238,12 +238,12 @@ define void @s_preemptible_push_pop_fp() #1 {
; RV64-LABEL: s_preemptible_push_pop_fp:
; RV64: # %bb.0:
; RV64-NEXT: .cfi_def_cfa_offset 48
-; RV64-NEXT: .cfi_undefined a0
-; RV64-NEXT: .cfi_undefined a1
-; RV64-NEXT: .cfi_undefined a2
-; RV64-NEXT: .cfi_undefined a3
-; RV64-NEXT: .cfi_undefined a4
-; RV64-NEXT: .cfi_undefined a5
+; RV64-NEXT: .cfi_offset a0, -8
+; RV64-NEXT: .cfi_offset a1, -16
+; RV64-NEXT: .cfi_offset a2, -24
+; RV64-NEXT: .cfi_offset a3, -32
+; RV64-NEXT: .cfi_offset a4, -40
+; RV64-NEXT: .cfi_offset a5, -48
; RV64-NEXT: addi sp, sp, -48
; RV64-NEXT: .cfi_def_cfa_offset 96
; RV64-NEXT: sd t0, 16(sp) # 8-byte Folded Spill
diff --git a/llvm/test/CodeGen/RISCV/aclic-interrupt-zilsd.ll b/llvm/test/CodeGen/RISCV/aclic-interrupt-zilsd.ll
new file mode 100644
index 00000000000000..123a91f75ff1c3
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-zilsd.ll
@@ -0,0 +1,105 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=riscv32 -verify-machineinstrs \
+; RUN: -mattr=+zilsd,+experimental-smip,+experimental-ssip \
+; RUN: < %s | FileCheck %s
+
+; Smip/Ssip save a0-a5 in hardware, so Zilsd must not pair them for software
+; spills in push-pop handlers.
+
+declare void @callee()
+
+define void @zilsd_push_pop_empty() #0 {
+; CHECK-LABEL: zilsd_push_pop_empty:
+; CHECK: # %bb.0:
+; CHECK-NEXT: .cfi_def_cfa_offset 32
+; CHECK-NEXT: addi sp, sp, -32
+; CHECK-NEXT: .cfi_def_cfa_offset 64
+; CHECK-NEXT: sd a0, 24(sp) # 8-byte Folded Spill
+; CHECK-NEXT: sd a2, 16(sp) # 8-byte Folded Spill
+; CHECK-NEXT: sd a4, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT: .cfi_offset a0, -40
+; CHECK-NEXT: .cfi_offset a1, -36
+; CHECK-NEXT: .cfi_offset a2, -48
+; CHECK-NEXT: .cfi_offset a3, -44
+; CHECK-NEXT: .cfi_offset a4, -56
+; CHECK-NEXT: .cfi_offset a5, -52
+; CHECK-NEXT: ld a0, 24(sp) # 8-byte Folded Reload
+; CHECK-NEXT: ld a2, 16(sp) # 8-byte Folded Reload
+; CHECK-NEXT: ld a4, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT: .cfi_restore a0
+; CHECK-NEXT: .cfi_restore a1
+; CHECK-NEXT: .cfi_restore a2
+; CHECK-NEXT: .cfi_restore a3
+; CHECK-NEXT: .cfi_restore a4
+; CHECK-NEXT: .cfi_restore a5
+; CHECK-NEXT: addi sp, sp, 32
+; CHECK-NEXT: .cfi_def_cfa_offset 32
+; CHECK-NEXT: mipopret
+ ret void
+}
+
+define void @zilsd_push_pop_call() #0 {
+; CHECK-LABEL: zilsd_push_pop_call:
+; CHECK: # %bb.0:
+; CHECK-NEXT: .cfi_def_cfa_offset 32
+; CHECK-NEXT: addi sp, sp, -64
+; CHECK-NEXT: .cfi_def_cfa_offset 96
+; CHECK-NEXT: sw ra, 60(sp) # 4-byte Folded Spill
+; CHECK-NEXT: sw t0, 56(sp) # 4-byte Folded Spill
+; CHECK-NEXT: sd a0, 48(sp) # 8-byte Folded Spill
+; CHECK-NEXT: sd a2, 40(sp) # 8-byte Folded Spill
+; CHECK-NEXT: sd a4, 32(sp) # 8-byte Folded Spill
+; CHECK-NEXT: sd a6, 24(sp) # 8-byte Folded Spill
+; CHECK-NEXT: sd t1, 16(sp) # 8-byte Folded Spill
+; CHECK-NEXT: sd t3, 8(sp) # 8-byte Folded Spill
+; CHECK-NEXT: sd t5, 0(sp) # 8-byte Folded Spill
+; CHECK-NEXT: .cfi_offset ra, -36
+; CHECK-NEXT: .cfi_offset t0, -40
+; CHECK-NEXT: .cfi_offset a0, -48
+; CHECK-NEXT: .cfi_offset a1, -44
+; CHECK-NEXT: .cfi_offset a2, -56
+; CHECK-NEXT: .cfi_offset a3, -52
+; CHECK-NEXT: .cfi_offset a4, -64
+; CHECK-NEXT: .cfi_offset a5, -60
+; CHECK-NEXT: .cfi_offset a6, -72
+; CHECK-NEXT: .cfi_offset a7, -68
+; CHECK-NEXT: .cfi_offset t1, -80
+; CHECK-NEXT: .cfi_offset t2, -76
+; CHECK-NEXT: .cfi_offset t3, -88
+; CHECK-NEXT: .cfi_offset t4, -84
+; CHECK-NEXT: .cfi_offset t5, -96
+; CHECK-NEXT: .cfi_offset t6, -92
+; CHECK-NEXT: call callee
+; CHECK-NEXT: lw ra, 60(sp) # 4-byte Folded Reload
+; CHECK-NEXT: lw t0, 56(sp) # 4-byte Folded Reload
+; CHECK-NEXT: ld a0, 48(sp) # 8-byte Folded Reload
+; CHECK-NEXT: ld a2, 40(sp) # 8-byte Folded Reload
+; CHECK-NEXT: ld a4, 32(sp) # 8-byte Folded Reload
+; CHECK-NEXT: ld a6, 24(sp) # 8-byte Folded Reload
+; CHECK-NEXT: ld t1, 16(sp) # 8-byte Folded Reload
+; CHECK-NEXT: ld t3, 8(sp) # 8-byte Folded Reload
+; CHECK-NEXT: ld t5, 0(sp) # 8-byte Folded Reload
+; CHECK-NEXT: .cfi_restore ra
+; CHECK-NEXT: .cfi_restore t0
+; CHECK-NEXT: .cfi_restore a0
+; CHECK-NEXT: .cfi_restore a1
+; CHECK-NEXT: .cfi_restore a2
+; CHECK-NEXT: .cfi_restore a3
+; CHECK-NEXT: .cfi_restore a4
+; CHECK-NEXT: .cfi_restore a5
+; CHECK-NEXT: .cfi_restore a6
+; CHECK-NEXT: .cfi_restore a7
+; CHECK-NEXT: .cfi_restore t1
+; CHECK-NEXT: .cfi_restore t2
+; CHECK-NEXT: .cfi_restore t3
+; CHECK-NEXT: .cfi_restore t4
+; CHECK-NEXT: .cfi_restore t5
+; CHECK-NEXT: .cfi_restore t6
+; CHECK-NEXT: addi sp, sp, 64
+; CHECK-NEXT: .cfi_def_cfa_offset 32
+; CHECK-NEXT: mipopret
+ call void @callee()
+ ret void
+}
+
+attributes #0 = { "frame-pointer"="none" "interrupt"="machine-push-pop" }
>From 9e186422c072fa682953051505dd782e8a712286 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <zeyi2 at nekoarch.cc>
Date: Thu, 26 Nov 2026 05:03:23 +0000
Subject: [PATCH 12/12] fix zilsd redundant codegen
---
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 5 +
.../CodeGen/RISCV/aclic-interrupt-zilsd.ll | 98 +++++++------------
2 files changed, 40 insertions(+), 63 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 2f29012353e0d2..c87752c981c2f8 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -2088,6 +2088,11 @@ void RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
// breaks the frame chain.
if (hasFP(MF) && CSReg == RISCV::X8_X9)
CombineToSuperReg = false;
+ // a0-a5 are saved by the ACLIC hardware push.
+ if (RVFI->isACLICPushPopInterrupt(MF) &&
+ llvm::is_contained(
+ llvm::make_first_range(FixedCSRFIACLICInterruptMap), EvenReg))
+ CombineToSuperReg = false;
} else {
auto SubRegs = TRI.subregs(CSReg);
CombineToSuperReg =
diff --git a/llvm/test/CodeGen/RISCV/aclic-interrupt-zilsd.ll b/llvm/test/CodeGen/RISCV/aclic-interrupt-zilsd.ll
index 123a91f75ff1c3..85378728def1b5 100644
--- a/llvm/test/CodeGen/RISCV/aclic-interrupt-zilsd.ll
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-zilsd.ll
@@ -12,28 +12,12 @@ define void @zilsd_push_pop_empty() #0 {
; CHECK-LABEL: zilsd_push_pop_empty:
; CHECK: # %bb.0:
; CHECK-NEXT: .cfi_def_cfa_offset 32
-; CHECK-NEXT: addi sp, sp, -32
-; CHECK-NEXT: .cfi_def_cfa_offset 64
-; CHECK-NEXT: sd a0, 24(sp) # 8-byte Folded Spill
-; CHECK-NEXT: sd a2, 16(sp) # 8-byte Folded Spill
-; CHECK-NEXT: sd a4, 8(sp) # 8-byte Folded Spill
-; CHECK-NEXT: .cfi_offset a0, -40
-; CHECK-NEXT: .cfi_offset a1, -36
-; CHECK-NEXT: .cfi_offset a2, -48
-; CHECK-NEXT: .cfi_offset a3, -44
-; CHECK-NEXT: .cfi_offset a4, -56
-; CHECK-NEXT: .cfi_offset a5, -52
-; CHECK-NEXT: ld a0, 24(sp) # 8-byte Folded Reload
-; CHECK-NEXT: ld a2, 16(sp) # 8-byte Folded Reload
-; CHECK-NEXT: ld a4, 8(sp) # 8-byte Folded Reload
-; CHECK-NEXT: .cfi_restore a0
-; CHECK-NEXT: .cfi_restore a1
-; CHECK-NEXT: .cfi_restore a2
-; CHECK-NEXT: .cfi_restore a3
-; CHECK-NEXT: .cfi_restore a4
-; CHECK-NEXT: .cfi_restore a5
-; CHECK-NEXT: addi sp, sp, 32
-; CHECK-NEXT: .cfi_def_cfa_offset 32
+; CHECK-NEXT: .cfi_offset a0, -4
+; CHECK-NEXT: .cfi_offset a1, -8
+; CHECK-NEXT: .cfi_offset a2, -12
+; CHECK-NEXT: .cfi_offset a3, -16
+; CHECK-NEXT: .cfi_offset a4, -20
+; CHECK-NEXT: .cfi_offset a5, -24
; CHECK-NEXT: mipopret
ret void
}
@@ -42,51 +26,39 @@ define void @zilsd_push_pop_call() #0 {
; CHECK-LABEL: zilsd_push_pop_call:
; CHECK: # %bb.0:
; CHECK-NEXT: .cfi_def_cfa_offset 32
-; CHECK-NEXT: addi sp, sp, -64
-; CHECK-NEXT: .cfi_def_cfa_offset 96
-; CHECK-NEXT: sw ra, 60(sp) # 4-byte Folded Spill
-; CHECK-NEXT: sw t0, 56(sp) # 4-byte Folded Spill
-; CHECK-NEXT: sd a0, 48(sp) # 8-byte Folded Spill
-; CHECK-NEXT: sd a2, 40(sp) # 8-byte Folded Spill
-; CHECK-NEXT: sd a4, 32(sp) # 8-byte Folded Spill
-; CHECK-NEXT: sd a6, 24(sp) # 8-byte Folded Spill
-; CHECK-NEXT: sd t1, 16(sp) # 8-byte Folded Spill
-; CHECK-NEXT: sd t3, 8(sp) # 8-byte Folded Spill
-; CHECK-NEXT: sd t5, 0(sp) # 8-byte Folded Spill
+; CHECK-NEXT: .cfi_offset a0, -4
+; CHECK-NEXT: .cfi_offset a1, -8
+; CHECK-NEXT: .cfi_offset a2, -12
+; CHECK-NEXT: .cfi_offset a3, -16
+; CHECK-NEXT: .cfi_offset a4, -20
+; CHECK-NEXT: .cfi_offset a5, -24
+; CHECK-NEXT: addi sp, sp, -48
+; CHECK-NEXT: .cfi_def_cfa_offset 80
+; CHECK-NEXT: sw ra, 44(sp) # 4-byte Folded Spill
+; CHECK-NEXT: sw t0, 40(sp) # 4-byte Folded Spill
+; CHECK-NEXT: sd a6, 32(sp) # 8-byte Folded Spill
+; CHECK-NEXT: sd t1, 24(sp) # 8-byte Folded Spill
+; CHECK-NEXT: sd t3, 16(sp) # 8-byte Folded Spill
+; CHECK-NEXT: sd t5, 8(sp) # 8-byte Folded Spill
; CHECK-NEXT: .cfi_offset ra, -36
; CHECK-NEXT: .cfi_offset t0, -40
-; CHECK-NEXT: .cfi_offset a0, -48
-; CHECK-NEXT: .cfi_offset a1, -44
-; CHECK-NEXT: .cfi_offset a2, -56
-; CHECK-NEXT: .cfi_offset a3, -52
-; CHECK-NEXT: .cfi_offset a4, -64
-; CHECK-NEXT: .cfi_offset a5, -60
-; CHECK-NEXT: .cfi_offset a6, -72
-; CHECK-NEXT: .cfi_offset a7, -68
-; CHECK-NEXT: .cfi_offset t1, -80
-; CHECK-NEXT: .cfi_offset t2, -76
-; CHECK-NEXT: .cfi_offset t3, -88
-; CHECK-NEXT: .cfi_offset t4, -84
-; CHECK-NEXT: .cfi_offset t5, -96
-; CHECK-NEXT: .cfi_offset t6, -92
+; CHECK-NEXT: .cfi_offset a6, -48
+; CHECK-NEXT: .cfi_offset a7, -44
+; CHECK-NEXT: .cfi_offset t1, -56
+; CHECK-NEXT: .cfi_offset t2, -52
+; CHECK-NEXT: .cfi_offset t3, -64
+; CHECK-NEXT: .cfi_offset t4, -60
+; CHECK-NEXT: .cfi_offset t5, -72
+; CHECK-NEXT: .cfi_offset t6, -68
; CHECK-NEXT: call callee
-; CHECK-NEXT: lw ra, 60(sp) # 4-byte Folded Reload
-; CHECK-NEXT: lw t0, 56(sp) # 4-byte Folded Reload
-; CHECK-NEXT: ld a0, 48(sp) # 8-byte Folded Reload
-; CHECK-NEXT: ld a2, 40(sp) # 8-byte Folded Reload
-; CHECK-NEXT: ld a4, 32(sp) # 8-byte Folded Reload
-; CHECK-NEXT: ld a6, 24(sp) # 8-byte Folded Reload
-; CHECK-NEXT: ld t1, 16(sp) # 8-byte Folded Reload
-; CHECK-NEXT: ld t3, 8(sp) # 8-byte Folded Reload
-; CHECK-NEXT: ld t5, 0(sp) # 8-byte Folded Reload
+; CHECK-NEXT: lw ra, 44(sp) # 4-byte Folded Reload
+; CHECK-NEXT: lw t0, 40(sp) # 4-byte Folded Reload
+; CHECK-NEXT: ld a6, 32(sp) # 8-byte Folded Reload
+; CHECK-NEXT: ld t1, 24(sp) # 8-byte Folded Reload
+; CHECK-NEXT: ld t3, 16(sp) # 8-byte Folded Reload
+; CHECK-NEXT: ld t5, 8(sp) # 8-byte Folded Reload
; CHECK-NEXT: .cfi_restore ra
; CHECK-NEXT: .cfi_restore t0
-; CHECK-NEXT: .cfi_restore a0
-; CHECK-NEXT: .cfi_restore a1
-; CHECK-NEXT: .cfi_restore a2
-; CHECK-NEXT: .cfi_restore a3
-; CHECK-NEXT: .cfi_restore a4
-; CHECK-NEXT: .cfi_restore a5
; CHECK-NEXT: .cfi_restore a6
; CHECK-NEXT: .cfi_restore a7
; CHECK-NEXT: .cfi_restore t1
@@ -95,7 +67,7 @@ define void @zilsd_push_pop_call() #0 {
; CHECK-NEXT: .cfi_restore t4
; CHECK-NEXT: .cfi_restore t5
; CHECK-NEXT: .cfi_restore t6
-; CHECK-NEXT: addi sp, sp, 64
+; CHECK-NEXT: addi sp, sp, 48
; CHECK-NEXT: .cfi_def_cfa_offset 32
; CHECK-NEXT: mipopret
call void @callee()
More information about the cfe-commits
mailing list