Skip to content

[M68k] fix call frame destruction elimination #107579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions llvm/lib/Target/M68k/M68kFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

using namespace llvm;

#define DEBUG_TYPE "m68k-frame"

M68kFrameLowering::M68kFrameLowering(const M68kSubtarget &STI, Align Alignment)
: TargetFrameLowering(StackGrowsDown, Alignment, -4), STI(STI),
TII(*STI.getInstrInfo()), TRI(STI.getRegisterInfo()) {
Expand Down Expand Up @@ -231,8 +233,8 @@ MachineBasicBlock::iterator M68kFrameLowering::eliminateCallFramePseudoInstr(
unsigned Opcode = I->getOpcode();
bool IsDestroy = Opcode == TII.getCallFrameDestroyOpcode();
DebugLoc DL = I->getDebugLoc();
uint64_t Amount = !ReserveCallFrame ? I->getOperand(0).getImm() : 0;
uint64_t InternalAmt = (IsDestroy && Amount) ? I->getOperand(1).getImm() : 0;
uint64_t Amount = I->getOperand(0).getImm();
uint64_t InternalAmt = (IsDestroy || Amount) ? I->getOperand(1).getImm() : 0;
I = MBB.erase(I);

if (!ReserveCallFrame) {
Expand Down
74 changes: 72 additions & 2 deletions llvm/test/CodeGen/M68k/multiple-return.ll
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=m68k-linux -verify-machineinstrs | FileCheck %s

define { i32, i32, i32, i32 } @test() {
; CHECK-LABEL: test:
define { i32, i32, i32, i32 } @test0() {
; CHECK-LABEL: test0:
; CHECK: .cfi_startproc
; CHECK-NEXT: ; %bb.0: ; %start
; CHECK-NEXT: move.l (4,%sp), %a0
Expand All @@ -18,3 +18,73 @@ define { i32, i32, i32, i32 } @test() {
start:
ret { i32, i32, i32, i32 } { i32 13, i32 17, i32 19, i32 23 }
}

define void @call_test0() {
; CHECK-LABEL: call_test0:
; CHECK: .cfi_startproc
; CHECK-NEXT: ; %bb.0: ; %start
; CHECK-NEXT: suba.l #20, %sp
; CHECK-NEXT: .cfi_def_cfa_offset -24
; CHECK-NEXT: lea (4,%sp), %a0
; CHECK-NEXT: move.l %a0, (%sp)
; CHECK-NEXT: jsr test0
; CHECK-NEXT: adda.l #16, %sp
; CHECK-NEXT: rts
start:
%val = call { i32, i32, i32, i32 } @test0()
ret void
}

define void @test1(ptr sret({ i32, i32, i32, i32 }) %ret_val) {
; CHECK-LABEL: test1:
; CHECK: .cfi_startproc
; CHECK-NEXT: ; %bb.0: ; %start
; CHECK-NEXT: move.l (4,%sp), %d0
; CHECK-NEXT: move.l (%sp), %a1
; CHECK-NEXT: adda.l #4, %sp
; CHECK-NEXT: move.l %a1, (%sp)
; CHECK-NEXT: rts
start:
ret void
}

define void @call_test1() {
; CHECK-LABEL: call_test1:
; CHECK: .cfi_startproc
; CHECK-NEXT: ; %bb.0: ; %start
; CHECK-NEXT: suba.l #20, %sp
; CHECK-NEXT: .cfi_def_cfa_offset -24
; CHECK-NEXT: lea (4,%sp), %a0
; CHECK-NEXT: move.l %a0, (%sp)
; CHECK-NEXT: jsr test1
; CHECK-NEXT: adda.l #16, %sp
; CHECK-NEXT: rts
start:
%ret_val = alloca { i32, i32, i32, i32 }
call void @test1(ptr %ret_val)
ret void
}

define i32 @test2() {
; CHECK-LABEL: test2:
; CHECK: .cfi_startproc
; CHECK-NEXT: ; %bb.0: ; %start
; CHECK-NEXT: moveq #13, %d0
; CHECK-NEXT: rts
start:
ret i32 13
}

define void @call_test2() {
; CHECK-LABEL: call_test2:
; CHECK: .cfi_startproc
; CHECK-NEXT: ; %bb.0: ; %start
; CHECK-NEXT: suba.l #4, %sp
; CHECK-NEXT: .cfi_def_cfa_offset -8
; CHECK-NEXT: jsr test2
; CHECK-NEXT: adda.l #4, %sp
; CHECK-NEXT: rts
start:
%0 = call i32 @test2()
ret void
}
Loading