[llvm] [VectorCombine] Support multi-use binary ops and operands in shuffle folding (PR #173153)

via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 20 07:41:06 PST 2025


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 -- llvm/lib/Transforms/Vectorize/VectorCombine.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/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index aa1f48f7a..7103ce61f 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -2280,8 +2280,7 @@ bool VectorCombine::foldConcatOfBoolMasks(Instruction &I) {
 bool VectorCombine::foldPermuteOfBinops(Instruction &I) {
   BinaryOperator *BinOp;
   ArrayRef<int> OuterMask;
-  if (!match(&I,
-             m_Shuffle(m_BinOp(BinOp), m_Undef(), m_Mask(OuterMask))))
+  if (!match(&I, m_Shuffle(m_BinOp(BinOp), m_Undef(), m_Mask(OuterMask))))
     return false;
 
   // Don't introduce poison into div/rem.
@@ -2290,12 +2289,10 @@ bool VectorCombine::foldPermuteOfBinops(Instruction &I) {
 
   Value *Op00, *Op01, *Op10, *Op11;
   ArrayRef<int> Mask0, Mask1;
-  bool Match0 =
-      match(BinOp->getOperand(0),
-            m_Shuffle(m_Value(Op00), m_Value(Op01), m_Mask(Mask0)));
-  bool Match1 =
-      match(BinOp->getOperand(1),
-            m_Shuffle(m_Value(Op10), m_Value(Op11), m_Mask(Mask1)));
+  bool Match0 = match(BinOp->getOperand(0),
+                      m_Shuffle(m_Value(Op00), m_Value(Op01), m_Mask(Mask0)));
+  bool Match1 = match(BinOp->getOperand(1),
+                      m_Shuffle(m_Value(Op10), m_Value(Op11), m_Mask(Mask1)));
   if (!Match0 && !Match1)
     return false;
 
@@ -2339,7 +2336,7 @@ bool VectorCombine::foldPermuteOfBinops(Instruction &I) {
   bool IsIdentity1 = ShuffleDstTy == Op1Ty &&
       all_of(NewMask1, [NumOpElts](int M) { return M < (int)NumOpElts; }) &&
       ShuffleVectorInst::isIdentityMask(NewMask1, NumOpElts);
-  
+
   bool WillRemoveBinOp = BinOp->hasOneUse();
   // Try to merge shuffles across the binop if the new shuffles are not costly.
   InstructionCost OldCost =
@@ -2350,15 +2347,15 @@ bool VectorCombine::foldPermuteOfBinops(Instruction &I) {
     bool WillRemoveShuf0 = BinOp->getOperand(0)->hasOneUse();
     bool WillRemoveShuf1 = BinOp->getOperand(1)->hasOneUse();
     if (Match0 && WillRemoveShuf0)
-        OldCost +=
-            TTI.getShuffleCost(TargetTransformInfo::SK_PermuteTwoSrc, BinOpTy,
-                                Op0Ty, Mask0, CostKind, 0, nullptr, {Op00, Op01},
-                                cast<Instruction>(BinOp->getOperand(0)));
+      OldCost +=
+          TTI.getShuffleCost(TargetTransformInfo::SK_PermuteTwoSrc, BinOpTy,
+                             Op0Ty, Mask0, CostKind, 0, nullptr, {Op00, Op01},
+                             cast<Instruction>(BinOp->getOperand(0)));
     if (Match1 && WillRemoveShuf1)
-        OldCost +=
-            TTI.getShuffleCost(TargetTransformInfo::SK_PermuteTwoSrc, BinOpTy,
-                                Op1Ty, Mask1, CostKind, 0, nullptr, {Op10, Op11},
-                                cast<Instruction>(BinOp->getOperand(1)));
+      OldCost +=
+          TTI.getShuffleCost(TargetTransformInfo::SK_PermuteTwoSrc, BinOpTy,
+                             Op1Ty, Mask1, CostKind, 0, nullptr, {Op10, Op11},
+                             cast<Instruction>(BinOp->getOperand(1)));
   }
 
   InstructionCost NewCost =

``````````

</details>


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


More information about the llvm-commits mailing list