summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/DeadStoreElimination.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-09-02 06:31:02 +0000
committerChris Lattner <sabre@nondot.org>2009-09-02 06:31:02 +0000
commit40ef630a4626365faeef8696f611e18d1a69f63a (patch)
treef10ca5b73ace27e3b5dd6eb3fd3deaf6157c7c9f /lib/Transforms/Scalar/DeadStoreElimination.cpp
parent20a2faa980293534da366a59b5cd9cd00588b1b7 (diff)
downloadllvm-40ef630a4626365faeef8696f611e18d1a69f63a.tar.gz
llvm-40ef630a4626365faeef8696f611e18d1a69f63a.tar.bz2
llvm-40ef630a4626365faeef8696f611e18d1a69f63a.tar.xz
fix PR4815: some cases where DeleteDeadInstruction can delete
the instruction BBI points to. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80768 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/DeadStoreElimination.cpp')
-rw-r--r--lib/Transforms/Scalar/DeadStoreElimination.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 376a098689..a7b3e7524f 100644
--- a/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -83,7 +83,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
bool MadeChange = false;
- // Do a top-down walk on the BB
+ // Do a top-down walk on the BB.
for (BasicBlock::iterator BBI = BB.begin(), BBE = BB.end(); BBI != BBE; ) {
Instruction *Inst = BBI++;
@@ -124,7 +124,10 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
DeleteDeadInstruction(DepStore);
NumFastStores++;
MadeChange = true;
-
+
+ // DeleteDeadInstruction can delete the current instruction in loop
+ // cases, reset BBI.
+ BBI = Inst;
if (BBI != BB.begin())
--BBI;
continue;
@@ -135,8 +138,15 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
if (LoadInst *DepLoad = dyn_cast<LoadInst>(InstDep.getInst())) {
if (SI->getPointerOperand() == DepLoad->getPointerOperand() &&
SI->getOperand(0) == DepLoad) {
+ // DeleteDeadInstruction can delete the current instruction. Save BBI
+ // in case we need it.
+ WeakVH NextInst(BBI);
+
DeleteDeadInstruction(SI);
- if (BBI != BB.begin())
+
+ if (NextInst == 0) // Next instruction deleted.
+ BBI = BB.begin();
+ else if (BBI != BB.begin()) // Revisit this instruction if possible.
--BBI;
NumFastStores++;
MadeChange = true;