diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 506346d35833..ee9c5f2de7d5 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/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;