diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index f6b51f83ff76f2..a66218dc40f371 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -6725,9 +6725,9 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, bool IsScatterVectorizeUserTE = UserTreeIdx.UserTE && UserTreeIdx.UserTE->State == TreeEntry::ScatterVectorize; - bool AreAllSameInsts = - (S.getOpcode() && allSameBlock(VL)) || - (S.OpValue->getType()->isPointerTy() && IsScatterVectorizeUserTE && + bool AreAllSameBlock = S.getOpcode() && allSameBlock(VL); + bool AreScatterAllGEPSameBlock = + (IsScatterVectorizeUserTE && S.OpValue->getType()->isPointerTy() && VL.size() > 2 && all_of(VL, [&BB](Value *V) { @@ -6741,6 +6741,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, BB && sortPtrAccesses(VL, UserTreeIdx.UserTE->getMainOp()->getType(), *DL, *SE, SortedIndices)); + bool AreAllSameInsts = AreAllSameBlock || AreScatterAllGEPSameBlock; if (!AreAllSameInsts || allConstant(VL) || isSplat(VL) || (isa( S.OpValue) && @@ -6820,9 +6821,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, // Special processing for sorted pointers for ScatterVectorize node with // constant indeces only. - if (AreAllSameInsts && UserTreeIdx.UserTE && - UserTreeIdx.UserTE->State == TreeEntry::ScatterVectorize && - !(S.getOpcode() && allSameBlock(VL))) { + if (!AreAllSameBlock && AreScatterAllGEPSameBlock) { assert(S.OpValue->getType()->isPointerTy() && count_if(VL, IsaPred) >= 2 && "Expected pointers only.");