[llvm-commits] [llvm] r162099 - /llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Fri Aug 17 07:39:00 PDT 2012
Author: stoklund
Date: Fri Aug 17 09:38:59 2012
New Revision: 162099
URL: http://llvm.org/viewvc/llvm-project?rev=162099&view=rev
Log:
Use standard pattern for iterate+erase.
Increment the MBB iterator at the top of the loop to properly handle the
current (and previous) instructions getting erased.
This fixes PR13625.
Modified:
llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp
Modified: llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp?rev=162099&r1=162098&r2=162099&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp (original)
+++ llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp Fri Aug 17 09:38:59 2012
@@ -496,11 +496,11 @@
ImmDefMIs.clear();
FoldAsLoadDefReg = 0;
- bool First = true;
- MachineBasicBlock::iterator PMII;
for (MachineBasicBlock::iterator
MII = I->begin(), MIE = I->end(); MII != MIE; ) {
MachineInstr *MI = &*MII;
+ // We may be erasing MI below, increment MII now.
+ ++MII;
LocalMIs.insert(MI);
// If there exists an instruction which belongs to the following
@@ -509,7 +509,6 @@
MI->isKill() || MI->isInlineAsm() || MI->isDebugValue() ||
MI->hasUnmodeledSideEffects()) {
FoldAsLoadDefReg = 0;
- ++MII;
continue;
}
if (MI->mayStore() || MI->isCall())
@@ -521,7 +520,6 @@
// MI is deleted.
LocalMIs.erase(MI);
Changed = true;
- MII = First ? I->begin() : llvm::next(PMII);
continue;
}
@@ -553,14 +551,9 @@
// MI is replaced with FoldMI.
Changed = true;
- PMII = FoldMI;
- MII = llvm::next(PMII);
continue;
}
}
- First = false;
- PMII = MII;
- ++MII;
}
}
More information about the llvm-commits
mailing list