Index: include/llvm/Transforms/Vectorize/SLPVectorizer.h =================================================================== --- include/llvm/Transforms/Vectorize/SLPVectorizer.h +++ include/llvm/Transforms/Vectorize/SLPVectorizer.h @@ -82,8 +82,8 @@ ArrayRef BuildVector = None, bool AllowReorder = false); - /// \brief Try to vectorize a chain that may start at the operands of \V; - bool tryToVectorize(BinaryOperator *V, slpvectorizer::BoUpSLP &R); + /// \brief Try to vectorize a chain that may start at the operands of \p I. + bool tryToVectorize(Instruction *I, slpvectorizer::BoUpSLP &R); /// \brief Vectorize the store instructions collected in Stores. bool vectorizeStoreChains(slpvectorizer::BoUpSLP &R); Index: lib/Transforms/Vectorize/SLPVectorizer.cpp =================================================================== --- lib/Transforms/Vectorize/SLPVectorizer.cpp +++ lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -4085,15 +4085,18 @@ return Changed; } -bool SLPVectorizerPass::tryToVectorize(BinaryOperator *V, BoUpSLP &R) { - if (!V) +bool SLPVectorizerPass::tryToVectorize(Instruction *I, BoUpSLP &R) { + if (!I) + return false; + + if (!isa(I) && !isa(I)) return false; - Value *P = V->getParent(); + Value *P = I->getParent(); // Vectorize in current basic block only. - auto *Op0 = dyn_cast(V->getOperand(0)); - auto *Op1 = dyn_cast(V->getOperand(1)); + auto *Op0 = dyn_cast(I->getOperand(0)); + auto *Op1 = dyn_cast(I->getOperand(1)); if (!Op0 || !Op1 || Op0->getParent() != P || Op1->getParent() != P) return false; @@ -4666,10 +4669,10 @@ /// if it can be done. /// \returns true if a horizontal reduction was matched and reduced. /// \returns false if a horizontal reduction was not matched. -static bool canBeVectorized( - PHINode *P, Instruction *Root, BasicBlock *BB, BoUpSLP &R, - TargetTransformInfo *TTI, - const function_ref Vectorize) { +static bool +canBeVectorized(PHINode *P, Instruction *Root, BasicBlock *BB, BoUpSLP &R, + TargetTransformInfo *TTI, + const function_ref Vectorize) { if (!ShouldVectorizeHor) return false; @@ -4714,7 +4717,7 @@ } } P = nullptr; - if (Vectorize(dyn_cast(Inst), R)) { + if (Vectorize(Inst, R)) { Res = true; continue; } @@ -4745,8 +4748,8 @@ P = nullptr; // Try to match and vectorize a horizontal reduction. return canBeVectorized(P, I, BB, R, TTI, - [this](BinaryOperator *BI, BoUpSLP &R) -> bool { - return tryToVectorize(BI, R); + [this](Instruction *I, BoUpSLP &R) -> bool { + return tryToVectorize(I, R); }); } @@ -4854,9 +4857,12 @@ } } - // Try to vectorize trees that start at compare instructions. - if (CmpInst *CI = dyn_cast(it)) { - if (tryToVectorizePair(CI->getOperand(0), CI->getOperand(1), R)) { + if (auto *BI = dyn_cast(it)) { + if (!BI->isConditional()) + continue; + + // Try to vectorize trees that start at logical/compare instructions. + if (vectorizeRootInstruction(nullptr, BI->getCondition(), BB, R, TTI)) { Changed = true; // We would like to start over since some instructions are deleted // and the iterator may become invalid value. @@ -4864,17 +4870,6 @@ e = BB->end(); continue; } - - for (int I = 0; I < 2; ++I) { - if (vectorizeRootInstruction(nullptr, CI->getOperand(I), BB, R, TTI)) { - Changed = true; - // We would like to start over since some instructions are deleted - // and the iterator may become invalid value. - it = BB->begin(); - e = BB->end(); - break; - } - } continue; }