summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2012-08-17 14:38:59 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2012-08-17 14:38:59 +0000
commit714f595c98302ea5fcd5fba3badd360e50c6394e (patch)
treea96ef0e5a61067984ca59f0f57b49ec406a3872e /llvm/lib/CodeGen
parent4901f0d2a25da6b678c3d6eb25ea73e0bdb7a229 (diff)
downloadbcm5719-llvm-714f595c98302ea5fcd5fba3badd360e50c6394e.tar.gz
bcm5719-llvm-714f595c98302ea5fcd5fba3badd360e50c6394e.zip
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. llvm-svn: 162099
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/PeepholeOptimizer.cpp11
1 files changed, 2 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/PeepholeOptimizer.cpp b/llvm/lib/CodeGen/PeepholeOptimizer.cpp
index 096df7bf6a1..9099862bd31 100644
--- a/llvm/lib/CodeGen/PeepholeOptimizer.cpp
+++ b/llvm/lib/CodeGen/PeepholeOptimizer.cpp
@@ -496,11 +496,11 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
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 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
MI->isKill() || MI->isInlineAsm() || MI->isDebugValue() ||
MI->hasUnmodeledSideEffects()) {
FoldAsLoadDefReg = 0;
- ++MII;
continue;
}
if (MI->mayStore() || MI->isCall())
@@ -521,7 +520,6 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
// MI is deleted.
LocalMIs.erase(MI);
Changed = true;
- MII = First ? I->begin() : llvm::next(PMII);
continue;
}
@@ -553,14 +551,9 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
// MI is replaced with FoldMI.
Changed = true;
- PMII = FoldMI;
- MII = llvm::next(PMII);
continue;
}
}
- First = false;
- PMII = MII;
- ++MII;
}
}
OpenPOWER on IntegriCloud