Skip to content

Commit 41ac94d

Browse files
authored
Merge pull request #3118 from TNorthover/eng/PR-79726989
ARM: don't return by popping PC if we have to adjust the stack afterwards
2 parents 2466031 + b7c5736 commit 41ac94d

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

llvm/lib/Target/ARM/ARMFrameLowering.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,19 +1134,16 @@ void ARMFrameLowering::emitPopInst(MachineBasicBlock &MBB,
11341134
// The aligned reloads from area DPRCS2 are not inserted here.
11351135
if (Reg >= ARM::D8 && Reg < ARM::D8 + NumAlignedDPRCS2Regs)
11361136
continue;
1137-
11381137
if (Reg == ARM::LR && !isTailCall && !isVarArg && !isInterrupt &&
1139-
!isCmseEntry && !isTrap && STI.hasV5TOps()) {
1140-
if (MBB.succ_empty()) {
1141-
Reg = ARM::PC;
1142-
// Fold the return instruction into the LDM.
1143-
DeleteRet = true;
1144-
LdmOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_RET : ARM::LDMIA_RET;
1145-
// We 'restore' LR into PC so it is not live out of the return block:
1146-
// Clear Restored bit.
1147-
Info.setRestored(false);
1148-
} else
1149-
LdmOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_UPD : ARM::LDMIA_UPD;
1138+
!isCmseEntry && !isTrap && AFI->getArgumentStackToRestore() == 0 &&
1139+
STI.hasV5TOps() && MBB.succ_empty()) {
1140+
Reg = ARM::PC;
1141+
// Fold the return instruction into the LDM.
1142+
DeleteRet = true;
1143+
LdmOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_RET : ARM::LDMIA_RET;
1144+
// We 'restore' LR into PC so it is not live out of the return block:
1145+
// Clear Restored bit.
1146+
Info.setRestored(false);
11501147
}
11511148

11521149
// If NoGap is true, pop consecutive registers and then leave the rest

llvm/test/CodeGen/ARM/tailcc-call.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,15 @@ define tailcc void @fromtail_toC() {
191191
call void @Ccallee_stack4([4 x i32] undef, i32 42)
192192
ret void
193193
}
194+
195+
; Don't try to return by popping pc if there's stack to reclaim.
196+
define tailcc void @notail_stackclean([4 x i32], i32) {
197+
; COMMON-LABEL: notail_stackclean:
198+
; COMMON: pop {r7, lr}
199+
; COMMON: add sp, #8
200+
; COMMON: bx lr
201+
202+
203+
call void @callee_stack0()
204+
ret void
205+
}

0 commit comments

Comments
 (0)