diff options
author | Owen Anderson <resistor@mac.com> | 2007-08-03 11:03:26 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2007-08-03 11:03:26 +0000 |
commit | 30463f10e2aad2e8bef5bbfa6b8b0b5dde49e009 (patch) | |
tree | dacbd3e32c3f6ab75bd1516213ff6e510774c3aa | |
parent | 16ac627954d00eda4ebadf4b43f5c463861e9174 (diff) | |
download | external_llvm-30463f10e2aad2e8bef5bbfa6b8b0b5dde49e009.zip external_llvm-30463f10e2aad2e8bef5bbfa6b8b0b5dde49e009.tar.gz external_llvm-30463f10e2aad2e8bef5bbfa6b8b0b5dde49e009.tar.bz2 |
Fix a subtle iterator invalidation bug in a recursive algorithm.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40776 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/GVN.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 2384e59..1f3ecfa 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -726,19 +726,21 @@ Value *GVN::GetValueForBlock(BasicBlock *BB, LoadInst* orig, bool top_level) { // If we have already computed this value, return the previously computed val. - Value *&V = Phis[BB]; + Value *V = Phis[BB]; if (V && ! top_level) return V; BasicBlock* singlePred = BB->getSinglePredecessor(); - if (singlePred) - return V = GetValueForBlock(singlePred, orig, Phis); - + if (singlePred) { + V = GetValueForBlock(singlePred, orig, Phis); + Phis[BB] = V; + return V; + } // Otherwise, the idom is the loop, so we need to insert a PHI node. Do so // now, then get values to fill in the incoming values for the PHI. PHINode *PN = new PHINode(orig->getType(), orig->getName()+".rle", BB->begin()); PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB))); - V = PN; + Phis[BB] = PN; bool all_same = true; Value* first = 0; |