[llvm] 9e03920 - [SLP]Ignore root gather node, when searching for reuses

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 09:16:29 PDT 2024


Author: Alexey Bataev
Date: 2024-10-21T09:16:16-07:00
New Revision: 9e03920cbf946e7ba282e99213707643a23ae5fb

URL: https://github.com/llvm/llvm-project/commit/9e03920cbf946e7ba282e99213707643a23ae5fb
DIFF: https://github.com/llvm/llvm-project/commit/9e03920cbf946e7ba282e99213707643a23ae5fb.diff

LOG: [SLP]Ignore root gather node, when searching for reuses

Root gather/buildvector node should be ignored when SLP vectorizer tries
to find matching gather nodes, vectorized earlier. This node is
definitely the last one in the pipeline and it does not have users. It
may cause the compiler crash

Fixes #113143

Added: 
    llvm/test/Transforms/SLPVectorizer/X86/root-gather-reused-scalar.ll

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 1098bf578d2d73..a11e3f3815cbf7 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -12466,7 +12466,7 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(
     // Build a list of tree entries where V is used.
     SmallPtrSet<const TreeEntry *, 4> VToTEs;
     for (const TreeEntry *TEPtr : ValueToGatherNodes.find(V)->second) {
-      if (TEPtr == TE)
+      if (TEPtr == TE || TEPtr->Idx == 0)
         continue;
       assert(any_of(TEPtr->Scalars,
                     [&](Value *V) { return GatheredScalars.contains(V); }) &&

diff  --git a/llvm/test/Transforms/SLPVectorizer/X86/root-gather-reused-scalar.ll b/llvm/test/Transforms/SLPVectorizer/X86/root-gather-reused-scalar.ll
new file mode 100644
index 00000000000000..7850bb89c8e416
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/root-gather-reused-scalar.ll
@@ -0,0 +1,40 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+
+define void @test(ptr %a, i32 %0, i32 %1, i1 %cmp1) {
+; CHECK-LABEL: define void @test(
+; CHECK-SAME: ptr [[A:%.*]], i32 [[TMP0:%.*]], i32 [[TMP1:%.*]], i1 [[CMP1:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TMP2:%.*]] = load i32, ptr [[A]], align 4
+; CHECK-NEXT:    [[TOBOOL10_NOT:%.*]] = icmp eq i32 [[TMP0]], 0
+; CHECK-NEXT:    [[CMP4_3:%.*]] = icmp ne i32 [[TMP1]], 0
+; CHECK-NEXT:    [[TMP3:%.*]] = and i1 [[CMP4_3]], [[TOBOOL10_NOT]]
+; CHECK-NEXT:    [[CMP2_2:%.*]] = xor i1 [[TOBOOL10_NOT]], true
+; CHECK-NEXT:    [[CONV3_2:%.*]] = zext i1 [[CMP2_2]] to i32
+; CHECK-NEXT:    [[CMP4_2:%.*]] = icmp ne i32 [[TMP2]], [[CONV3_2]]
+; CHECK-NEXT:    [[CMP2_1:%.*]] = xor i1 [[CMP1]], true
+; CHECK-NEXT:    [[CONV3_1:%.*]] = zext i1 [[CMP2_1]] to i32
+; CHECK-NEXT:    [[CMP4_1:%.*]] = icmp ne i32 [[TMP2]], [[CONV3_1]]
+; CHECK-NEXT:    [[TMP4:%.*]] = select i1 [[TMP3]], i1 [[CMP4_2]], i1 false
+; CHECK-NEXT:    [[TMP5:%.*]] = select i1 [[TMP4]], i1 [[CMP4_1]], i1 false
+; CHECK-NEXT:    [[AND_3:%.*]] = zext i1 [[TMP5]] to i32
+; CHECK-NEXT:    store i32 [[AND_3]], ptr [[A]], align 4
+; CHECK-NEXT:    ret void
+;
+entry:
+  %2 = load i32, ptr %a, align 4
+  %tobool10.not = icmp eq i32 %0, 0
+  %cmp4.3 = icmp ne i32 %1, 0
+  %3 = and i1 %cmp4.3, %tobool10.not
+  %cmp2.2 = xor i1 %tobool10.not, true
+  %conv3.2 = zext i1 %cmp2.2 to i32
+  %cmp4.2 = icmp ne i32 %2, %conv3.2
+  %cmp2.1 = xor i1 %cmp1, true
+  %conv3.1 = zext i1 %cmp2.1 to i32
+  %cmp4.1 = icmp ne i32 %2, %conv3.1
+  %4 = select i1 %3, i1 %cmp4.2, i1 false
+  %5 = select i1 %4, i1 %cmp4.1, i1 false
+  %and.3 = zext i1 %5 to i32
+  store i32 %and.3, ptr %a, align 4
+  ret void
+}


        


More information about the llvm-commits mailing list