summaryrefslogtreecommitdiffstats
path: root/llvm/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
commit4916267c97941288b9b3111b3e6e964110202344 (patch)
treef6ed1d10a48ede6cccde1a3017db73f0362cb5a1 /llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
parent09a79dcfdfd81a80865c69abd56789ad3d00fd34 (diff)
downloadbcm5719-llvm-4916267c97941288b9b3111b3e6e964110202344.tar.gz
bcm5719-llvm-4916267c97941288b9b3111b3e6e964110202344.zip
fix PR4815: some cases where DeleteDeadInstruction can delete
the instruction BBI points to. llvm-svn: 80768
Diffstat (limited to 'llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 376a098689d..a7b3e7524fa 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/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;
OpenPOWER on IntegriCloud