[llvm] [SLP] Account for vectorizable reduction consumers (PR #227303)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 06:05:15 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h b/llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h
index db268423b..3b29ba56a 100644
--- a/llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h
+++ b/llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h
@@ -143,11 +143,10 @@ private:
   /// Make an attempt to vectorize reduction and then try to vectorize
   /// postponed binary operations.
   /// \returns true on any successfull vectorization.
-  bool
-  vectorizeRootInstruction(PHINode *P, Instruction *Root, BasicBlock *BB,
-                           slpvectorizer::BoUpSLP &R,
-                           SmallSetVector<Instruction *, 8> &FMACandidates,
-                           bool AllowNonPowerOf2Analysis = false);
+  bool vectorizeRootInstruction(PHINode *P, Instruction *Root, BasicBlock *BB,
+                                slpvectorizer::BoUpSLP &R,
+                                SmallSetVector<Instruction *, 8> &FMACandidates,
+                                bool AllowNonPowerOf2Analysis = false);
 
   /// Try to vectorize trees that start at insertvalue instructions.
   bool vectorizeInsertValueInst(InsertValueInst *IVI, BasicBlock *BB,
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 676b03c3b..c540d655d 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -32720,9 +32720,9 @@ public:
           ReduxWidth = bit_floor(ReduxWidth);
         return ReduxWidth;
       };
-      if (!isAllowedNonPowerOf2VF(
-              ReduxWidth, VectorizeNonPowerOf2 ||
-                              V.allowsReductionNonPowerOf2Analysis()))
+      if (!isAllowedNonPowerOf2VF(ReduxWidth,
+                                  VectorizeNonPowerOf2 ||
+                                      V.allowsReductionNonPowerOf2Analysis()))
         ReduxWidth = GetVectorFactor(ReduxWidth);
       ReduxWidth = std::min(ReduxWidth, MaxElts);
 
@@ -33027,14 +33027,12 @@ public:
                      << ", vector-store=" << VectorStoreCost << "\n");
           return ScalarCost - VectorCost;
         };
-        InstructionCost ConsumerBenefit =
-            V.allowsReductionNonPowerOf2Analysis()
-                ? GetConsumerBundleBenefit()
-                : InstructionCost(0);
-        bool UseCombinedCost =
-            ConsumerBenefit.isValid() &&
-            ConsumerBenefit > SLPCostThreshold &&
-            Cost - ConsumerBenefit < -SLPCostThreshold;
+        InstructionCost ConsumerBenefit = V.allowsReductionNonPowerOf2Analysis()
+                                              ? GetConsumerBundleBenefit()
+                                              : InstructionCost(0);
+        bool UseCombinedCost = ConsumerBenefit.isValid() &&
+                               ConsumerBenefit > SLPCostThreshold &&
+                               Cost - ConsumerBenefit < -SLPCostThreshold;
         if (UseCombinedCost)
           Cost -= ConsumerBenefit;
         bool DisallowedNonPowerOf2 =

``````````

</details>


https://github.com/llvm/llvm-project/pull/227303


More information about the llvm-commits mailing list