[llvm] [ARM] Check all terms in emitPopInst when clearing Restored for LR. (PR #75527)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 15 12:58:04 PST 2023
================
@@ -1645,9 +1645,21 @@ void ARMFrameLowering::emitPopInst(MachineBasicBlock &MBB,
// Fold the return instruction into the LDM.
DeleteRet = true;
LdmOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_RET : ARM::LDMIA_RET;
- // We 'restore' LR into PC so it is not live out of the return block:
- // Clear Restored bit.
- Info.setRestored(false);
+ // Check if all terminators do not implicitly use LR. Then we can
+ // 'restore' LR into PC so it is not live out of the return block: Clear
+ // Restored bit.
+ if (all_of(MF, [MI](const MachineBasicBlock &MBB) {
+ return all_of(MBB.terminators(), [MI](const MachineInstr &Term) {
+ // MI's terminator is to be re-written, don't check the old
+ // opcode.
+ if (&*MI == &Term)
+ return true;
+ return Term.getOpcode() == ARM::LDMIA_RET ||
+ Term.getOpcode() == ARM::t2LDMIA_RET ||
+ Term.getOpcode() == ARM::tPOP_RET;
----------------
efriedma-quic wrote:
Should we checking for isReturn()? This is going to reject any block containing a branch.
Checking all blocks here is O(N^2) in the number of epilogues; can we move this later somehow?
There's corresponding code in Thumb1FrameLowering.cpp which needs a similar fix.
https://github.com/llvm/llvm-project/pull/75527
More information about the llvm-commits
mailing list