[PATCH] D119070: [MachineCombiner] Update iterator while deleting instructions
Darshan Bhat via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 5 22:47:28 PST 2022
DarshanRamakant updated this revision to Diff 406230.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119070/new/
https://reviews.llvm.org/D119070
Files:
llvm/lib/CodeGen/MachineCombiner.cpp
Index: llvm/lib/CodeGen/MachineCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/MachineCombiner.cpp
+++ llvm/lib/CodeGen/MachineCombiner.cpp
@@ -465,6 +465,7 @@
/// \param IncrementalUpdate if true, compute instruction depths incrementally,
/// otherwise invalidate the trace
static void insertDeleteInstructions(MachineBasicBlock *MBB, MachineInstr &MI,
+ MachineBasicBlock::iterator &BlockItr,
SmallVector<MachineInstr *, 16> InsInstrs,
SmallVector<MachineInstr *, 16> DelInstrs,
MachineTraceMetrics::Ensemble *MinInstr,
@@ -485,6 +486,11 @@
MBB->insert((MachineBasicBlock::iterator)&MI, InstrPtr);
for (auto *InstrPtr : DelInstrs) {
+ // If the instructions to be deleted is pointed by cuurent iterator
+ // update the iterator.
+ if (InstrPtr == &*BlockItr) {
+ BlockItr++;
+ }
InstrPtr->eraseFromParent();
// Erase all LiveRegs defined by the removed instruction
for (auto I = RegUnits.begin(); I != RegUnits.end(); ) {
@@ -642,8 +648,9 @@
}
if (reduceRegisterPressure(MI, MBB, InsInstrs, DelInstrs, P)) {
// Replace DelInstrs with InsInstrs.
- insertDeleteInstructions(MBB, MI, InsInstrs, DelInstrs, MinInstr,
- RegUnits, TII, P, IncrementalUpdate);
+ insertDeleteInstructions(MBB, MI, BlockIter, InsInstrs, DelInstrs,
+ MinInstr, RegUnits, TII, P,
+ IncrementalUpdate);
Changed |= true;
// Go back to previous instruction as it may have ILP reassociation
@@ -659,8 +666,8 @@
// resource pressure.
if (SubstituteAlways ||
doSubstitute(NewInstCount, OldInstCount, OptForSize)) {
- insertDeleteInstructions(MBB, MI, InsInstrs, DelInstrs, MinInstr,
- RegUnits, TII, P, IncrementalUpdate);
+ insertDeleteInstructions(MBB, MI, BlockIter, InsInstrs, DelInstrs,
+ MinInstr, RegUnits, TII, P, IncrementalUpdate);
// Eagerly stop after the first pattern fires.
Changed = true;
break;
@@ -682,8 +689,9 @@
LastUpdate = BlockIter;
}
- insertDeleteInstructions(MBB, MI, InsInstrs, DelInstrs, MinInstr,
- RegUnits, TII, P, IncrementalUpdate);
+ insertDeleteInstructions(MBB, MI, BlockIter, InsInstrs, DelInstrs,
+ MinInstr, RegUnits, TII, P,
+ IncrementalUpdate);
// Eagerly stop after the first pattern fires.
Changed = true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119070.406230.patch
Type: text/x-patch
Size: 2865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220206/58886a8c/attachment.bin>
More information about the llvm-commits
mailing list