[llvm] 95a960d - [SLP]Do not convert inversed cmp nodes, if they reordered/reused

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 20 06:05:02 PST 2026


Author: Alexey Bataev
Date: 2026-02-20T06:04:51-08:00
New Revision: 95a960daa0ebc4b582dbfebed26981552d94a3cd

URL: https://github.com/llvm/llvm-project/commit/95a960daa0ebc4b582dbfebed26981552d94a3cd
DIFF: https://github.com/llvm/llvm-project/commit/95a960daa0ebc4b582dbfebed26981552d94a3cd.diff

LOG: [SLP]Do not convert inversed cmp nodes, if they reordered/reused

If the cmp node with inversed compares must be reordered/shuffled with
the reuses, disable transformation for such nodes for now, they require
some special processing.

Fixes https://github.com/llvm/llvm-project/pull/181580#issuecomment-3933026221

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
    llvm/test/Transforms/SLPVectorizer/X86/compare-node-with-reuses.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index f49803976c0cb..4caa1707f0f27 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -13541,9 +13541,11 @@ bool BoUpSLP::matchesInversedZExtSelect(
   const auto *Op2TE = getOperandEntry(&SelectTE, 2);
   // Compares must be alternate vectorized, and other operands must be gathers
   // or copyables.
+  // TODO: investigate opportunity for reordered/reused nodes.
   if (CmpTE->State != TreeEntry::Vectorize || !CmpTE->isAltShuffle() ||
       (CmpTE->getOpcode() != Instruction::ICmp &&
        CmpTE->getOpcode() != Instruction::FCmp) ||
+      !CmpTE->ReorderIndices.empty() || !CmpTE->ReuseShuffleIndices.empty() ||
       !Op1TE->ReorderIndices.empty() || !Op1TE->ReuseShuffleIndices.empty() ||
       !Op2TE->ReorderIndices.empty() || !Op2TE->ReuseShuffleIndices.empty())
     return false;

diff  --git a/llvm/test/Transforms/SLPVectorizer/X86/compare-node-with-reuses.ll b/llvm/test/Transforms/SLPVectorizer/X86/compare-node-with-reuses.ll
index be2f2628f9f57..69dfba41b5006 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/compare-node-with-reuses.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/compare-node-with-reuses.ll
@@ -28,8 +28,9 @@ define i16 @test_inc_1(i16 %tnr.coerce) {
 ; CHECK-NEXT:    [[TMP12:%.*]] = shufflevector <4 x i32> [[TMP5]], <4 x i32> poison, <12 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
 ; CHECK-NEXT:    [[TMP13:%.*]] = shufflevector <12 x i32> [[TMP11]], <12 x i32> [[TMP12]], <12 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 12, i32 13, i32 14, i32 15>
 ; CHECK-NEXT:    [[TMP14:%.*]] = icmp ne <12 x i32> [[TMP13]], splat (i32 2147483647)
-; CHECK-NEXT:    [[TMP15:%.*]] = shufflevector <12 x i1> [[TMP14]], <12 x i1> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 0, i32 8, i32 2, i32 9, i32 4, i32 10, i32 6, i32 11>
-; CHECK-NEXT:    [[TMP16:%.*]] = select <16 x i1> [[TMP15]], <16 x i16> <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 0, i16 2, i16 0, i16 2, i16 2, i16 0, i16 2, i16 0>, <16 x i16> <i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 2, i16 0, i16 2, i16 0, i16 0, i16 2, i16 0, i16 2>
+; CHECK-NEXT:    [[TMP15:%.*]] = icmp eq <12 x i32> [[TMP13]], splat (i32 2147483647)
+; CHECK-NEXT:    [[TMP18:%.*]] = shufflevector <12 x i1> [[TMP14]], <12 x i1> [[TMP15]], <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 0, i32 20, i32 2, i32 21, i32 4, i32 22, i32 6, i32 23>
+; CHECK-NEXT:    [[TMP16:%.*]] = select <16 x i1> [[TMP18]], <16 x i16> <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 2, i16 0, i16 2, i16 0, i16 2, i16 0, i16 2, i16 0>, <16 x i16> <i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 2, i16 0, i16 2, i16 0, i16 2, i16 0, i16 2>
 ; CHECK-NEXT:    [[TMP17:%.*]] = call i16 @llvm.vector.reduce.add.v16i16(<16 x i16> [[TMP16]])
 ; CHECK-NEXT:    [[OP_RDX:%.*]] = add i16 [[TMP17]], [[TNR_COERCE]]
 ; CHECK-NEXT:    ret i16 [[OP_RDX]]


        


More information about the llvm-commits mailing list