diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 76701dba5840a..1142d21128031 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -553,8 +553,8 @@ static std::optional getExtractIndex(Instruction *E) { /// successful, the matched scalars are replaced by poison values in \p VL for /// future analysis. static std::optional -tryToGatherExtractElements(SmallVectorImpl &VL, - SmallVectorImpl &Mask) { +tryToGatherSingleRegisterExtractElements(MutableArrayRef VL, + SmallVectorImpl &Mask) { // Scan list of gathered scalars for extractelements that can be represented // as shuffles. MapVector> VectorOpToIdx; @@ -641,7 +641,7 @@ tryToGatherExtractElements(SmallVectorImpl &VL, if (!Res) { // TODO: try to check other subsets if possible. // Restore the original VL if attempt was not successful. - VL.swap(SavedVL); + copy(SavedVL, VL.begin()); return std::nullopt; } // Restore unused scalars from mask, if some of the extractelements were not @@ -7616,7 +7616,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef VectorizedVals, std::optional GatherShuffle; SmallVector Entries; // Check for gathered extracts. - ExtractShuffle = tryToGatherExtractElements(GatheredScalars, ExtractMask); + ExtractShuffle = tryToGatherSingleRegisterExtractElements(GatheredScalars, ExtractMask); SmallVector IgnoredVals; if (UserIgnoreList) IgnoredVals.assign(UserIgnoreList->begin(), UserIgnoreList->end()); @@ -10166,7 +10166,8 @@ ResTy BoUpSLP::processBuildVector(const TreeEntry *E, Args &...Params) { Type *ScalarTy = GatheredScalars.front()->getType(); if (!all_of(GatheredScalars, UndefValue::classof)) { // Check for gathered extracts. - ExtractShuffle = tryToGatherExtractElements(GatheredScalars, ExtractMask); + ExtractShuffle = + tryToGatherSingleRegisterExtractElements(GatheredScalars, ExtractMask); SmallVector IgnoredVals; if (UserIgnoreList) IgnoredVals.assign(UserIgnoreList->begin(), UserIgnoreList->end());