From: Devang Patel Date: Mon, 23 Apr 2007 22:42:03 +0000 (+0000) Subject: Fix X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=2a5fa189972c1ecc29f3682a732d15f94b9498f1;p=oota-llvm.git Fix http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070423/048333.html git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36380 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 38cfd91fe1b..6bece9cfb7e 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -416,12 +416,16 @@ bool LoopStrengthReduce::AddUsersIfInteresting(Instruction *I, Loop *L, if (!getSCEVStartAndStride(ISE, L, Start, Stride)) return false; // Non-reducible symbolic expression, bail out. - for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E;) { - Instruction *User = cast(*UI); + std::vector IUsers; + // Collect all I uses now because IVUseShouldUsePostIncValue may + // invalidate use_iterator. + for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E; ++UI) + IUsers.push_back(cast(*UI)); - // Increment iterator now because IVUseShouldUsePostIncValue may remove - // User from the list of I users. - ++UI; + for (unsigned iused_index = 0, iused_size = IUsers.size(); + iused_index != iused_size; ++iused_index) { + + Instruction *User = IUsers[iused_index]; // Do not infinitely recurse on PHI nodes. if (isa(User) && Processed.count(User))