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 @@ -14133,16 +14133,12 @@ } template -static bool -tryToVectorizeSequence(SmallVectorImpl &Incoming, - function_ref Limit, - function_ref Comparator, - function_ref AreCompatible, - function_ref, bool)> TryToVectorizeHelper, - bool LimitForRegisterSize) { +static bool tryToVectorizeSequence( + SmallVectorImpl &Incoming, function_ref Limit, + function_ref AreCompatible, + function_ref, bool)> TryToVectorizeHelper, + bool LimitForRegisterSize) { bool Changed = false; - // Sort by type, parent, operands. - stable_sort(Incoming, Comparator); // Try to vectorize elements base on their type. SmallVector Candidates; @@ -14320,8 +14316,10 @@ }; SmallVector Vals(PostponedCmps.begin(), PostponedCmps.end()); + stable_sort(Vals, CompareSorter); + OpsChanged |= tryToVectorizeSequence( - Vals, Limit, CompareSorter, AreCompatibleCompares, + Vals, Limit, AreCompatibleCompares, [this, &R](ArrayRef Candidates, bool LimitForRegisterSize) { // Exclude possible reductions from other blocks. bool ArePossiblyReducedInOtherBlock = @@ -14483,8 +14481,10 @@ } } + stable_sort(Incoming, PHICompare); + HaveVectorizedPhiNodes = tryToVectorizeSequence( - Incoming, Limit, PHICompare, AreCompatiblePHIs, + Incoming, Limit, AreCompatiblePHIs, [this, &R](ArrayRef Candidates, bool LimitForRegisterSize) { return tryToVectorizeList(Candidates, R, LimitForRegisterSize); }, @@ -14780,8 +14780,10 @@ if (!isValidElementType(Pair.second.front()->getValueOperand()->getType())) continue; + stable_sort(Pair.second, StoreSorter); + Changed |= tryToVectorizeSequence( - Pair.second, Limit, StoreSorter, AreCompatibleStores, + Pair.second, Limit, AreCompatibleStores, [this, &R](ArrayRef Candidates, bool) { return vectorizeStores(Candidates, R); },