[PATCH] D14986: Fix Thumb1 epilogue generation
A. Skrobov via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 25 05:46:32 PST 2015
tyomitch created this revision.
tyomitch added reviewers: qcolombet, jroelofs.
tyomitch added a subscriber: llvm-commits.
Herald added a subscriber: rengolin.
This had been broken for a very long time, but nobody noticed until
D14357 enabled shrink-wrapping by default.
http://reviews.llvm.org/D14986
Files:
lib/Target/ARM/Thumb1FrameLowering.cpp
test/CodeGen/Thumb/thumb-shrink-wrapping.ll
Index: test/CodeGen/Thumb/thumb-shrink-wrapping.ll
===================================================================
--- test/CodeGen/Thumb/thumb-shrink-wrapping.ll
+++ test/CodeGen/Thumb/thumb-shrink-wrapping.ll
@@ -39,7 +39,8 @@
;
; With shrink-wrapping, epilogue is just after the call.
; ENABLE-NEXT: add sp, #8
-; ENABLE-NEXT: pop {r7, lr}
+; ENABLE-NEXT: pop {r7, r1}
+; ENABLE-NEXT: mov lr, r1
;
; CHECK: [[EXIT_LABEL]]:
;
Index: lib/Target/ARM/Thumb1FrameLowering.cpp
===================================================================
--- lib/Target/ARM/Thumb1FrameLowering.cpp
+++ lib/Target/ARM/Thumb1FrameLowering.cpp
@@ -406,11 +406,11 @@
if (AFI->getArgRegsSaveSize())
return true;
- bool IsV4PopReturn = false;
for (const CalleeSavedInfo &CSI : MF.getFrameInfo()->getCalleeSavedInfo())
if (CSI.getReg() == ARM::LR)
- IsV4PopReturn = true;
- return IsV4PopReturn && STI.hasV4TOps() && !STI.hasV5TOps();
+ return true;
+
+ return false;
}
bool Thumb1FrameLowering::emitPopSpecialFixUp(MachineBasicBlock &MBB,
@@ -429,8 +429,9 @@
// and copy that value into LR.
auto MBBI = MBB.getFirstTerminator();
if (!ArgRegsSaveSize && MBBI != MBB.end() &&
- MBBI->getOpcode() == ARM::tBX_RET) {
- if (!DoIt)
+ (MBBI->getOpcode() == ARM::tBX_RET ||
+ MBBI->getOpcode() == ARM::tPOP_RET)) {
+ if (!DoIt || MBBI->getOpcode() == ARM::tPOP_RET)
return true;
MachineInstrBuilder MIB =
AddDefaultPred(
@@ -459,10 +460,10 @@
if (MBBI != MBB.end()) {
dl = MBBI->getDebugLoc();
auto InstUpToMBBI = MBB.end();
- // The post-decrement is on purpose here.
- // We want to have the liveness right before MBBI.
- while (InstUpToMBBI-- != MBBI)
- UsedRegs.stepBackward(*InstUpToMBBI);
+ while (InstUpToMBBI != MBBI)
+ // The pre-decrement is on purpose here.
+ // We want to have the liveness right before MBBI.
+ UsedRegs.stepBackward(*--InstUpToMBBI);
}
// Look for a register that can be directly use in the POP.
@@ -509,8 +510,14 @@
}
assert(PopReg && "Do not know how to get LR");
- AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::tPOP)))
- .addReg(PopReg, RegState::Define);
+ MachineInstr *Pop;
+ if (MBBI == MBB.end()) {
+ Pop = &MBB.back();
+ assert(Pop->getOpcode() == ARM::tPOP);
+ Pop->RemoveOperand(Pop->findRegisterDefOperandIdx(ARM::LR));
+ } else
+ Pop = AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::tPOP)));
+ Pop->addOperand(MachineOperand::CreateReg(PopReg, true));
emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, ArgRegsSaveSize);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14986.41136.patch
Type: text/x-patch
Size: 2625 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151125/9587b22b/attachment.bin>
More information about the llvm-commits
mailing list