[llvm] 6aeea12 - [SLP][NFC] Simplify population of `ReducedVals` (#156292)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 1 07:38:17 PDT 2025


Author: Piotr Fusik
Date: 2025-09-01T16:38:13+02:00
New Revision: 6aeea122c51c65189cff023b5bf5b5aa9e28ef5d

URL: https://github.com/llvm/llvm-project/commit/6aeea122c51c65189cff023b5bf5b5aa9e28ef5d
DIFF: https://github.com/llvm/llvm-project/commit/6aeea122c51c65189cff023b5bf5b5aa9e28ef5d.diff

LOG: [SLP][NFC] Simplify population of `ReducedVals` (#156292)

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 3a81d1d24e16c..ac41c92a1cdc3 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -23833,21 +23833,20 @@ class HorizontalReduction {
       stable_sort(PossibleRedValsVect, [](const auto &P1, const auto &P2) {
         return P1.size() > P2.size();
       });
-      int NewIdx = -1;
+      bool First = true;
       for (ArrayRef<Value *> Data : PossibleRedValsVect) {
-        if (NewIdx < 0 ||
-            (!isGoodForReduction(Data) &&
-             (!isa<LoadInst>(Data.front()) ||
-              !isa<LoadInst>(ReducedVals[NewIdx].front()) ||
-              getUnderlyingObject(
-                  cast<LoadInst>(Data.front())->getPointerOperand()) !=
-                  getUnderlyingObject(
-                      cast<LoadInst>(ReducedVals[NewIdx].front())
-                          ->getPointerOperand())))) {
-          NewIdx = ReducedVals.size();
+        if (First) {
+          First = false;
           ReducedVals.emplace_back();
-        }
-        ReducedVals[NewIdx].append(Data.rbegin(), Data.rend());
+        } else if (!isGoodForReduction(Data)) {
+          auto *LI = dyn_cast<LoadInst>(Data.front());
+          auto *LastLI = dyn_cast<LoadInst>(ReducedVals.back().front());
+          if (!LI || !LastLI ||
+              getUnderlyingObject(LI->getPointerOperand()) !=
+                  getUnderlyingObject(LastLI->getPointerOperand()))
+            ReducedVals.emplace_back();
+        }
+        ReducedVals.back().append(Data.rbegin(), Data.rend());
       }
     }
     // Sort the reduced values by number of same/alternate opcode and/or pointer


        


More information about the llvm-commits mailing list