[llvm] [VectorCombine] Fix typo in foldPermuteOfBinops cost calculation (PR #178072)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 26 14:54:22 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: None (calebwat)

<details>
<summary>Changes</summary>

Addresses an issue in #<!-- -->173153. This patch expanded the supported ops for folding binary ops through shuffles, but seemingly had a typo which could inaccurately increase the unmodified cost.

---
Full diff: https://github.com/llvm/llvm-project/pull/178072.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/Vectorize/VectorCombine.cpp (+1-1) 
- (added) llvm/test/Transforms/VectorCombine/X86/binop-shuffle-mask1-cm.ll (+18) 


``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index fbb3b820c4f05..71f6293073453 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -2490,7 +2490,7 @@ bool VectorCombine::foldPermuteOfBinops(Instruction &I) {
   }
   if (Match1) {
     InstructionCost Shuf1Cost = TTI.getShuffleCost(
-        TargetTransformInfo::SK_PermuteTwoSrc, BinOpTy, Op0Ty, Mask0, CostKind,
+        TargetTransformInfo::SK_PermuteTwoSrc, BinOpTy, Op1Ty, Mask1, CostKind,
         0, nullptr, {Op10, Op11}, cast<Instruction>(BinOp->getOperand(1)));
     OldCost += Shuf1Cost;
     if (!BinOp->hasOneUse() || !BinOp->getOperand(1)->hasOneUse())
diff --git a/llvm/test/Transforms/VectorCombine/X86/binop-shuffle-mask1-cm.ll b/llvm/test/Transforms/VectorCombine/X86/binop-shuffle-mask1-cm.ll
new file mode 100644
index 0000000000000..5fa7c7dcdd4f9
--- /dev/null
+++ b/llvm/test/Transforms/VectorCombine/X86/binop-shuffle-mask1-cm.ll
@@ -0,0 +1,18 @@
+; RUN: opt -passes=vector-combine -debug-only=vector-combine -disable-output < %s 2>&1 | FileCheck %s
+target triple = "x86_64-unknown-linux-gnu"
+
+; Test that the cost modeling for folding shuffled binops uses the correct
+; values for the masks of each operand.
+
+; CHECK: Found a shuffle feeding a shuffled binop:   [[SHUF:%.*]] = shufflevector <4 x i8> [[PREV_SHUF:%.*]], <4 x i8> poison, <8 x i32> <i32 0, i32 poison, i32 1, i32 poison, i32 2, i32 poison, i32 3, i32 poison>
+; CHECK-NEXT:  OldCost: 3 vs NewCost: 5
+
+
+define <8 x i8> @test(<4 x i8> %0) #0 {
+  %2 = shufflevector <4 x i8> %0, <4 x i8> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 6, i32 7>
+  %3 = xor <4 x i8> %0, %2
+  %4 = shufflevector <4 x i8> %3, <4 x i8> poison, <8 x i32> <i32 0, i32 poison, i32 1, i32 poison, i32 2, i32 poison, i32 3, i32 poison>
+  ret <8 x i8> %4
+}
+
+attributes #0 = { "target-cpu"="core-avx2" }

``````````

</details>


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


More information about the llvm-commits mailing list