[clang] 555ed01 - [RISCV] Add Codegen support for ACLIC (#238325)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 26 21:58:01 PST 2026
Author: Zeyi Xu
Date: 2026-11-27T05:57:54Z
New Revision: 555ed01ab2f190b1db1502cad2d44d808f298224
URL: https://github.com/llvm/llvm-project/commit/555ed01ab2f190b1db1502cad2d44d808f298224
DIFF: https://github.com/llvm/llvm-project/commit/555ed01ab2f190b1db1502cad2d44d808f298224.diff
LOG: [RISCV] Add Codegen support for ACLIC (#238325)
This commit adds support for the `preemptible` and `push-pop` interrupt
kinds from the RISC-V Advanced Core-Local Interrupt Controller (ACLIC)
fast interrupt extensions.
AI Usage: GPT 5.6 Sol/6/6.2 Astra, Opus 5/5.5, Fable 5.1/5.2 and Gemini
Neon were used for pre-commit self-reviewing.
Added:
clang/test/Sema/riscv-interrupt-attr-aclic.c
llvm/test/CodeGen/RISCV/aclic-interrupt-attr-error.ll
llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll
llvm/test/CodeGen/RISCV/aclic-interrupt-zilsd.ll
Modified:
clang/docs/ReleaseNotes.md
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/Targets/RISCV.cpp
clang/lib/Sema/SemaRISCV.cpp
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/lib/Target/RISCV/RISCVInstrInfo.td
llvm/lib/Target/RISCV/RISCVInstrInfoSmip.td
llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp
llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 9abf809be593c8..f8115a8aff6afa 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1545,6 +1545,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 35afd9d197cfde..2158d2514645fd 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2482,6 +2482,8 @@ def RISCVInterrupt : InheritableAttr, TargetSpecificAttr<TargetRISCV> {
"supervisor",
"machine",
"rnmi",
+ "preemptible",
+ "push-pop",
"qci-nest",
"qci-nonest",
"SiFive-CLIC-preemptible",
@@ -2491,6 +2493,8 @@ def RISCVInterrupt : InheritableAttr, TargetSpecificAttr<TargetRISCV> {
"supervisor",
"machine",
"rnmi",
+ "preemptible",
+ "pushpop",
"qcinest",
"qcinonest",
"SiFiveCLICPreemptible",
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 459603215450fb..d05e35d873f833 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3355,13 +3355,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`. If there is no parameter, then it defaults to
-`machine`.
+`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
@@ -3385,6 +3394,7 @@ 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)
}];
diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp
index 96dad3d044c05f..9d59805afe9428 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -1140,7 +1140,9 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
if (!Attr)
return;
- StringRef Kind = "machine";
+ std::string Kind = "machine";
+ bool HasPreemptible = false;
+ bool HasPushPop = false;
bool HasSiFiveCLICPreemptible = false;
bool HasSiFiveCLICStackSwap = false;
for (RISCVInterruptAttr::InterruptType type : Attr->interrupt()) {
@@ -1155,6 +1157,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;
@@ -1178,6 +1186,10 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
}
}
+ 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 907123cd6379c0..f3bd0734c7a6b9 100644
--- a/clang/lib/Sema/SemaRISCV.cpp
+++ b/clang/lib/Sema/SemaRISCV.cpp
@@ -1680,6 +1680,10 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
if (!AL.checkAtMostNumArgs(SemaRef, 3))
return;
+ bool HasMachine = false;
+ bool HasSupervisor = false;
+ bool HasPreemptible = false;
+ bool HasPushPop = false;
bool HasSiFiveCLICType = 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 ACLIC modifiers, or with SiFive CLIC
+ // types.
+ HasMachine = true;
+ break;
+ case RISCVInterruptAttr::supervisor:
+ HasSupervisor = 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::supervisor:
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;
}
@@ -1732,7 +1744,13 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
return;
}
- if (HasUnaryType && HasSiFiveCLICType) {
+ if (HasMachine && HasSupervisor) {
+ Diag(AL.getLoc(), diag::err_riscv_attribute_interrupt_invalid_combination);
+ return;
+ }
+
+ if (HasSiFiveCLICType &&
+ (HasUnaryType || HasSupervisor || HasPreemptible || HasPushPop)) {
Diag(AL.getLoc(), diag::err_riscv_attribute_interrupt_invalid_combination);
return;
}
@@ -1752,6 +1770,34 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
for (RISCVInterruptAttr::InterruptType Type : Types) {
switch (Type) {
+ case RISCVInterruptAttr::rnmi: {
+ if (!HasFeature("smrnmi")) {
+ Diag(AL.getLoc(),
+ diag::err_riscv_attribute_interrupt_requires_extension)
+ << RISCVInterruptAttr::ConvertInterruptTypeToStr(Type) << "Smrnmi";
+ 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;
// The QCI interrupt types require Xqciint
case RISCVInterruptAttr::qcinest:
case RISCVInterruptAttr::qcinonest: {
@@ -1773,14 +1819,6 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
return;
}
} break;
- case RISCVInterruptAttr::rnmi: {
- if (!HasFeature("smrnmi")) {
- Diag(AL.getLoc(),
- diag::err_riscv_attribute_interrupt_requires_extension)
- << RISCVInterruptAttr::ConvertInterruptTypeToStr(Type) << "Smrnmi";
- 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..90faec2a46df69
--- /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
+
+#if defined(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/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 82b350daa19c66..a3d5212eba24ff 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -73,6 +73,23 @@ 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 RV64I/E.
+static uint64_t getACLICInterruptPushAmount(const MachineFunction &MF) {
+ const auto &STI = MF.getSubtarget<RISCVSubtarget>();
+ if (STI.is64Bit())
+ return 48;
+ 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},
@@ -250,9 +267,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;
@@ -260,7 +278,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);
@@ -268,13 +286,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();
}
@@ -294,7 +312,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);
@@ -374,7 +392,95 @@ 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), RISCV::X5)
+ .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), RISCV::X5)
+ .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), RISCV::X0)
+ .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), RISCV::X0)
+ .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))
@@ -603,14 +709,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;
});
@@ -677,6 +785,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();
@@ -1026,6 +1152,17 @@ 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 CFIBuilder(MBB, MBBI, MachineInstr::FrameSetup);
+ CFIBuilder.buildDefCFAOffset(RVFI->getACLICInterruptStackSize());
+ 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`
emitSiFiveCLICStackSwap(MF, MBB, MBBI, DL, MachineInstr::FrameSetup);
@@ -1083,7 +1220,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;
}
@@ -1182,6 +1319,8 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
MachineInstr::FrameSetup);
}
+ emitACLICPreemptibleSaves(MF, MBB, MBBI, DL);
+
// Save SiFive CLIC CSRs into Stack
emitSiFiveCLICPreemptibleSaves(MF, MBB, MBBI, DL);
@@ -1417,9 +1556,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();
@@ -1493,6 +1633,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) {
@@ -1573,12 +1714,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);
@@ -1757,9 +1898,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 ||
@@ -1982,8 +2121,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.
@@ -2043,6 +2183,11 @@ void RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
llvm::is_contained(llvm::make_first_range(FixedCSRFIQCIInterruptMap),
EvenReg))
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 =
@@ -2055,8 +2200,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>
@@ -2372,12 +2517,18 @@ 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())
+ //
+ // 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;
// 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
@@ -2437,13 +2588,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!
@@ -2487,6 +2644,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(); });
@@ -2810,16 +2981,20 @@ bool RISCVFrameLowering::restoreCalleeSavedRegisters(
}
bool RISCVFrameLowering::enableShrinkWrapping(const MachineFunction &MF) const {
- // Keep the conventional code flow when not optimizing.
- if (MF.getFunction().hasOptNone())
+ const auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
+ if (RVFI->isACLICPreemptibleInterrupt(MF) ||
+ RVFI->isACLICPushPopInterrupt(MF))
return false;
// 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;
+ // Keep the conventional code flow when not optimizing.
+ if (MF.getFunction().hasOptNone())
+ return false;
+
return true;
}
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index cba289900f30b5..4577de46ff4528 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -29175,6 +29175,12 @@ SDValue RISCVTargetLowering::LowerFormalArguments(
"machine",
"supervisor",
"rnmi",
+ "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",
@@ -29193,6 +29199,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");
}
@@ -30082,9 +30102,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;
@@ -30092,6 +30114,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 2faffc2835212e..589843e01b715c 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..e80f5830b3d6ca 100644
--- a/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp
@@ -73,6 +73,15 @@ RISCVMachineFunctionInfo::getInterruptStackKind(
return StringSwitch<RISCVMachineFunctionInfo::InterruptStackKind>(
InterruptVal)
+ .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)
.Case("qci-nest", InterruptStackKind::QCINest)
.Case("qci-nonest", InterruptStackKind::QCINoNest)
.Case("SiFive-CLIC-preemptible",
@@ -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..423c6d4f9b9fac 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; }
@@ -186,6 +190,12 @@ class RISCVMachineFunctionInfo : public MachineFunctionInfo {
enum class InterruptStackKind {
None = 0,
+ ACLICPreemptible,
+ ACLICSupervisorPreemptible,
+ ACLICPushPop,
+ ACLICSupervisorPushPop,
+ ACLICPreemptiblePushPop,
+ ACLICSupervisorPreemptiblePushPop,
QCINest,
QCINoNest,
SiFiveCLICPreemptible,
@@ -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,38 @@ 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 {
+ return llvm::is_contained(InterruptCSRFrameIndexes, FI);
+ }
// 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/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..4e0f78659df0a2
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-attr.ll
@@ -0,0 +1,1981 @@
+; 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
+; 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()
+
+; 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
+;
+; 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
+}
+
+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
+;
+; 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
+}
+
+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
+;
+; 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
+}
+
+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
+;
+; 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
+}
+
+define void @m_push_pop() #2 {
+; RV32-LABEL: m_push_pop:
+; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; 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
+; 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: .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
+; 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: .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
+; 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
+;
+; RV64E-LABEL: m_push_pop:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; 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
+; 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
+}
+
+define void @s_push_pop() #3 {
+; RV32-LABEL: s_push_pop:
+; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; 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
+; 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: .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
+; 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: .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
+; 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
+;
+; RV64E-LABEL: s_push_pop:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; 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
+; 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
+}
+
+define void @m_combined() #4 {
+; RV32-LABEL: m_combined:
+; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; 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
+; 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: .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
+; 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: .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
+; 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
+;
+; RV64E-LABEL: m_combined:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; 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
+; 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
+}
+
+define void @s_combined() #5 {
+; RV32-LABEL: s_combined:
+; RV32: # %bb.0:
+; RV32-NEXT: .cfi_def_cfa_offset 32
+; 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
+; 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: .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
+; 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: .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
+; 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
+;
+; RV64E-LABEL: s_combined:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; 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
+; 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
+}
+
+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_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
+; 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: .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
+; 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: .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
+; 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
+;
+; RV64E-LABEL: m_push_pop_large:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; 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
+; 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
+ 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: .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_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_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_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
+}
+
+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_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_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_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_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
+}
+
+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_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
+; 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: .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
+; 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: .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
+; 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
+;
+; RV64E-LABEL: m_push_pop_fp:
+; RV64E: # %bb.0:
+; RV64E-NEXT: .cfi_def_cfa_offset 48
+; 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
+; 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
+}
+
+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_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 #
+; 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: .cfi_def_cfa_offset 24
+; 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 #
+; 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: .cfi_def_cfa_offset 48
+; 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 #
+; 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: .cfi_def_cfa_offset 48
+; 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 #
+; 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" }
+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" }
+attributes #9 = { "frame-pointer"="none" "interrupt"="machine-push-pop" shadowcallstack }
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..9a27886a8728a9
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-frame-pointer.ll
@@ -0,0 +1,282 @@
+; 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: .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
+; 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: .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
+; 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: .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
+; 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" }
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..85378728def1b5
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/aclic-interrupt-zilsd.ll
@@ -0,0 +1,77 @@
+; 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: .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
+}
+
+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: .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 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, 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 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, 48
+; CHECK-NEXT: .cfi_def_cfa_offset 32
+; CHECK-NEXT: mipopret
+ call void @callee()
+ ret void
+}
+
+attributes #0 = { "frame-pointer"="none" "interrupt"="machine-push-pop" }
More information about the cfe-commits
mailing list