Index: lib/Transforms/Vectorize/SLPVectorizer.cpp =================================================================== --- lib/Transforms/Vectorize/SLPVectorizer.cpp +++ lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -4768,7 +4768,7 @@ if (!Root) return false; - if (Root->getParent() != BB) + if (Root->getParent() != BB || isa(Root)) return false; // Start analysis starting from Root instruction. If horizontal reduction is // found, try to vectorize it. If it is not a horizontal reduction or @@ -4789,7 +4789,7 @@ if (!V) continue; auto *Inst = dyn_cast(V); - if (!Inst || isa(Inst)) + if (!Inst) continue; if (auto *BI = dyn_cast(Inst)) { HorizontalReduction HorRdx; @@ -4825,7 +4825,10 @@ // Try to vectorize operands. if (++Level < RecursionMaxDepth) for (auto *Op : Inst->operand_values()) - Stack.emplace_back(Op, Level); + if (VisitedInstrs.insert(Op).second) + if (auto *I = dyn_cast(Op)) + if (!isa(Inst) && I->getParent() == BB) + Stack.emplace_back(Op, Level); } return Res; }