From 190673610f41be171589be8a0263d8c10a8f3edf Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Sat, 17 Aug 2013 11:04:47 +0000 Subject: [PATCH] PR 16899: Do not modify the basic block using the iterator, but keep the next value. This avoids crashes due to invalidation. Patch by Joey Gouly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188605 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Vectorize/SLPVectorizer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Transforms/Vectorize/SLPVectorizer.cpp b/lib/Transforms/Vectorize/SLPVectorizer.cpp index 506346d3583..ee9c5f2de7d 100644 --- a/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -1895,12 +1895,14 @@ bool SLPVectorizer::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) { if (Incoming.size() > 1) Changed |= tryToVectorizeList(Incoming, R); - for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e; ++it) { - if (isa(it)) + llvm::Instruction *I; + for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e;) { + I = it++; + if (isa(I)) continue; // Try to vectorize reductions that use PHINodes. - if (PHINode *P = dyn_cast(it)) { + if (PHINode *P = dyn_cast(I)) { // Check that the PHI is a reduction PHI. if (P->getNumIncomingValues() != 2) return Changed; @@ -1922,7 +1924,7 @@ bool SLPVectorizer::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) { } // Try to vectorize trees that start at compare instructions. - if (CmpInst *CI = dyn_cast(it)) { + if (CmpInst *CI = dyn_cast(I)) { if (tryToVectorizePair(CI->getOperand(0), CI->getOperand(1), R)) { Changed |= true; continue;