Skip to content

Commit 725656b

Browse files
authored
[M68k] Emit RTE for interrupt handler. (#72787)
Fixes #64833
1 parent 67f9cd4 commit 725656b

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

llvm/lib/Target/M68k/M68kExpandPseudo.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,11 @@ bool M68kExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
252252
return true;
253253
}
254254
case M68k::RET: {
255-
// Adjust stack to erase error code
256-
int64_t StackAdj = MBBI->getOperand(0).getImm();
257-
MachineInstrBuilder MIB;
258-
259-
if (StackAdj == 0) {
260-
MIB = BuildMI(MBB, MBBI, DL, TII->get(M68k::RTS));
255+
if (MBB.getParent()->getFunction().getCallingConv() ==
256+
CallingConv::M68k_INTR) {
257+
BuildMI(MBB, MBBI, DL, TII->get(M68k::RTE));
258+
} else if (int64_t StackAdj = MBBI->getOperand(0).getImm(); StackAdj == 0) {
259+
BuildMI(MBB, MBBI, DL, TII->get(M68k::RTS));
261260
} else {
262261
// Copy return address from stack to a free address(A0 or A1) register
263262
// TODO check if pseudo expand uses free address register

llvm/lib/Target/M68k/M68kInstrControl.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ def RTS : MxInst<(outs), (ins), "rts", []> {
327327
let Inst = (descend 0b0100, 0b1110, 0b0111, 0b0101);
328328
}
329329

330+
def RTE: MxInst<(outs), (ins), "rte", []> {
331+
let Inst = (descend 0b0100, 0b1110, 0b0111, 0b0011);
332+
}
333+
330334
let isCodeGenOnly = 1 in
331335
def RET : MxPseudo<(outs), (ins i32imm:$adj, variable_ops),
332336
[(MxRet timm:$adj)]>;

llvm/test/CodeGen/M68k/CConv/rte.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
2+
; RUN: llc -mtriple m68k -o - %s | FileCheck %s
3+
4+
define cc101 void @interrupt_handler() {
5+
; CHECK-LABEL: interrupt_handler:
6+
; CHECK: .cfi_startproc
7+
; CHECK-NEXT: ; %bb.0: ; %entry
8+
; CHECK-NEXT: rte
9+
entry:
10+
ret void
11+
}

0 commit comments

Comments
 (0)