[llvm] 7a4fc74 - [SLP][REVEC] Fix insertelement has multiple uses. (#102329)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 8 08:23:14 PDT 2024


Author: Han-Kuan Chen
Date: 2024-08-08T23:23:10+08:00
New Revision: 7a4fc7491ce8083d81f1bffa7fa9546cb53aa5e0

URL: https://github.com/llvm/llvm-project/commit/7a4fc7491ce8083d81f1bffa7fa9546cb53aa5e0
DIFF: https://github.com/llvm/llvm-project/commit/7a4fc7491ce8083d81f1bffa7fa9546cb53aa5e0.diff

LOG: [SLP][REVEC] Fix insertelement has multiple uses. (#102329)

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
    llvm/test/Transforms/SLPVectorizer/revec.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index d14dd1dabd5fc..575d178374844 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6419,6 +6419,16 @@ BoUpSLP::TreeEntry::EntryState BoUpSLP::getScalarsVectorizationState(
       return TreeEntry::NeedToGather;
     }
 
+    if (any_of(VL, [&SourceVectors](Value *V) {
+          // The last InsertElement can have multiple uses.
+          return SourceVectors.contains(V) && !V->hasOneUse();
+        })) {
+      assert(SLPReVec && "Only supported by REVEC.");
+      LLVM_DEBUG(dbgs() << "SLP: Gather of insertelement vectors with "
+                           "multiple uses.\n");
+      return TreeEntry::NeedToGather;
+    }
+
     return TreeEntry::Vectorize;
   }
   case Instruction::Load: {

diff  --git a/llvm/test/Transforms/SLPVectorizer/revec.ll b/llvm/test/Transforms/SLPVectorizer/revec.ll
index d6dd4128de9c7..d7c3ccd8c9ce8 100644
--- a/llvm/test/Transforms/SLPVectorizer/revec.ll
+++ b/llvm/test/Transforms/SLPVectorizer/revec.ll
@@ -124,3 +124,26 @@ entry:
   store <8 x i1> %6, ptr %7, align 1
   ret void
 }
+
+define void @test5(ptr %ptr0, ptr %ptr1) {
+; CHECK-LABEL: @test5(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[GETELEMENTPTR0:%.*]] = getelementptr i8, ptr null, i64 0
+; CHECK-NEXT:    [[TMP0:%.*]] = insertelement <4 x ptr> <ptr null, ptr null, ptr undef, ptr undef>, ptr [[GETELEMENTPTR0]], i32 2
+; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <4 x ptr> [[TMP0]], ptr null, i32 3
+; CHECK-NEXT:    [[TMP2:%.*]] = icmp ult <4 x ptr> zeroinitializer, [[TMP1]]
+; CHECK-NEXT:    [[TMP3:%.*]] = insertelement <4 x ptr> <ptr poison, ptr null, ptr null, ptr null>, ptr [[PTR0:%.*]], i32 0
+; CHECK-NEXT:    [[TMP4:%.*]] = insertelement <4 x ptr> [[TMP1]], ptr [[PTR1:%.*]], i32 3
+; CHECK-NEXT:    [[TMP5:%.*]] = icmp ult <4 x ptr> [[TMP3]], [[TMP4]]
+; CHECK-NEXT:    ret void
+;
+entry:
+  %getelementptr0 = getelementptr i8, ptr null, i64 0
+  %0 = insertelement <4 x ptr> <ptr null, ptr null, ptr undef, ptr undef>, ptr %getelementptr0, i32 2
+  %1 = insertelement <4 x ptr> %0, ptr null, i32 3
+  %2 = icmp ult <4 x ptr> zeroinitializer, %1
+  %3 = insertelement <4 x ptr> <ptr poison, ptr null, ptr null, ptr null>, ptr %ptr0, i32 0
+  %4 = insertelement <4 x ptr> %1, ptr %ptr1, i32 3
+  %5 = icmp ult <4 x ptr> %3, %4
+  ret void
+}


        


More information about the llvm-commits mailing list