aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TailDuplicator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/TailDuplicator.cpp')
-rw-r--r--llvm/lib/CodeGen/TailDuplicator.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp b/llvm/lib/CodeGen/TailDuplicator.cpp
index 575bf555c489..af735f2a0216 100644
--- a/llvm/lib/CodeGen/TailDuplicator.cpp
+++ b/llvm/lib/CodeGen/TailDuplicator.cpp
@@ -216,6 +216,9 @@ bool TailDuplicator::tailDuplicateAndUpdate(
// Rewrite uses that are outside of the original def's block.
MachineRegisterInfo::use_iterator UI = MRI->use_begin(VReg);
+ // Only remove instructions after loop, as DBG_VALUE_LISTs with multiple
+ // uses of VReg may invalidate the use iterator when erased.
+ SmallPtrSet<MachineInstr *, 4> InstrsToRemove;
while (UI != MRI->use_end()) {
MachineOperand &UseMO = *UI;
MachineInstr *UseMI = UseMO.getParent();
@@ -225,13 +228,15 @@ bool TailDuplicator::tailDuplicateAndUpdate(
// a debug instruction that is a kill.
// FIXME: Should it SSAUpdate job to delete debug instructions
// instead of replacing the use with undef?
- UseMI->eraseFromParent();
+ InstrsToRemove.insert(UseMI);
continue;
}
if (UseMI->getParent() == DefBB && !UseMI->isPHI())
continue;
SSAUpdate.RewriteUse(UseMO);
}
+ for (auto *MI : InstrsToRemove)
+ MI->eraseFromParent();
}
SSAUpdateVRs.clear();
@@ -683,7 +688,7 @@ bool TailDuplicator::isSimpleBB(MachineBasicBlock *TailBB) {
return false;
if (TailBB->pred_empty())
return false;
- MachineBasicBlock::iterator I = TailBB->getFirstNonDebugInstr();
+ MachineBasicBlock::iterator I = TailBB->getFirstNonDebugInstr(true);
if (I == TailBB->end())
return true;
return I->isUnconditionalBranch();
@@ -1035,10 +1040,9 @@ void TailDuplicator::removeDeadBlock(
MachineFunction *MF = MBB->getParent();
// Update the call site info.
- std::for_each(MBB->begin(), MBB->end(), [MF](const MachineInstr &MI) {
+ for (const MachineInstr &MI : *MBB)
if (MI.shouldUpdateCallSiteInfo())
MF->eraseCallSiteInfo(&MI);
- });
if (RemovalCallback)
(*RemovalCallback)(MBB);