diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -14501,53 +14501,50 @@ }; bool HaveVectorizedPhiNodes = false; - do { - // Collect the incoming values from the PHIs. - Incoming.clear(); - for (Instruction &I : *BB) { - PHINode *P = dyn_cast(&I); - if (!P) - break; + // Collect the incoming values from the PHIs. + Incoming.clear(); + for (Instruction &I : *BB) { + PHINode *P = dyn_cast(&I); + if (!P) + break; - // No need to analyze deleted, vectorized and non-vectorizable - // instructions. - if (!VisitedInstrs.count(P) && !R.isDeleted(P) && - isValidElementType(P->getType())) - Incoming.push_back(P); - } + // No need to analyze deleted, vectorized and non-vectorizable + // instructions. + if (!VisitedInstrs.count(P) && !R.isDeleted(P) && + isValidElementType(P->getType())) + Incoming.push_back(P); + } - // Find the corresponding non-phi nodes for better matching when trying to - // build the tree. - for (Value *V : Incoming) { - SmallVectorImpl &Opcodes = - PHIToOpcodes.try_emplace(V).first->getSecond(); - if (!Opcodes.empty()) + // Find the corresponding non-phi nodes for better matching when trying to + // build the tree. + for (Value *V : Incoming) { + SmallVectorImpl &Opcodes = + PHIToOpcodes.try_emplace(V).first->getSecond(); + if (!Opcodes.empty()) + continue; + SmallVector Nodes(1, V); + SmallPtrSet Visited; + while (!Nodes.empty()) { + auto *PHI = cast(Nodes.pop_back_val()); + if (!Visited.insert(PHI).second) continue; - SmallVector Nodes(1, V); - SmallPtrSet Visited; - while (!Nodes.empty()) { - auto *PHI = cast(Nodes.pop_back_val()); - if (!Visited.insert(PHI).second) + for (Value *V : PHI->incoming_values()) { + if (auto *PHI1 = dyn_cast((V))) { + Nodes.push_back(PHI1); continue; - for (Value *V : PHI->incoming_values()) { - if (auto *PHI1 = dyn_cast((V))) { - Nodes.push_back(PHI1); - continue; - } - Opcodes.emplace_back(V); } + Opcodes.emplace_back(V); } } + } - HaveVectorizedPhiNodes = tryToVectorizeSequence( - Incoming, PHICompare, AreCompatiblePHIs, - [this, &R](ArrayRef Candidates, bool LimitForRegisterSize) { - return tryToVectorizeList(Candidates, R, LimitForRegisterSize); - }, - /*LimitForRegisterSize=*/true, R); - Changed |= HaveVectorizedPhiNodes; - VisitedInstrs.insert(Incoming.begin(), Incoming.end()); - } while (HaveVectorizedPhiNodes); + HaveVectorizedPhiNodes = tryToVectorizeSequence( + Incoming, PHICompare, AreCompatiblePHIs, + [this, &R](ArrayRef Candidates, bool LimitForRegisterSize) { + return tryToVectorizeList(Candidates, R, LimitForRegisterSize); + }, + /*LimitForRegisterSize=*/true, R); + Changed |= HaveVectorizedPhiNodes; VisitedInstrs.clear();