[llvm] [SLP][REVEC] Fix insertelement has multiple uses. (PR #102329)
Han-Kuan Chen via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 8 06:53:40 PDT 2024
https://github.com/HanKuanChen updated https://github.com/llvm/llvm-project/pull/102329
>From 54c45cab614a59003098af8568aee0988ca57152 Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Tue, 30 Jul 2024 01:12:35 -0700
Subject: [PATCH 1/4] [SLP][REVEC] Pre-commit test.
---
llvm/test/Transforms/SLPVectorizer/revec.ll | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/llvm/test/Transforms/SLPVectorizer/revec.ll b/llvm/test/Transforms/SLPVectorizer/revec.ll
index d6dd4128de9c7e..c415d7f4d4a466 100644
--- a/llvm/test/Transforms/SLPVectorizer/revec.ll
+++ b/llvm/test/Transforms/SLPVectorizer/revec.ll
@@ -124,3 +124,15 @@ entry:
store <8 x i1> %6, ptr %7, align 1
ret void
}
+
+define void @test5(ptr %ptr0, ptr %ptr1) {
+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
+}
>From 3ef216cff9c5d3c7c3c5493e06c436549a4e4d37 Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Thu, 1 Aug 2024 17:32:43 -0700
Subject: [PATCH 2/4] [SLP][REVEC] Fix insertelement has multiple uses.
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 8 ++++++++
llvm/test/Transforms/SLPVectorizer/revec.ll | 11 +++++++++++
2 files changed, 19 insertions(+)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 4186b17e644b0b..7f098899311c03 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6402,6 +6402,14 @@ BoUpSLP::TreeEntry::EntryState BoUpSLP::getScalarsVectorizationState(
return TreeEntry::NeedToGather;
}
+ if (any_of(VL, [&SourceVectors](Value *V) {
+ if (SourceVectors.contains(V))
+ return !V->hasOneUse();
+ // The last InsertElement can have multiple uses.
+ return false;
+ }))
+ 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 c415d7f4d4a466..d7c3ccd8c9ce8a 100644
--- a/llvm/test/Transforms/SLPVectorizer/revec.ll
+++ b/llvm/test/Transforms/SLPVectorizer/revec.ll
@@ -126,6 +126,17 @@ entry:
}
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
>From d154dc57458449b0a4720e661604cbbd083c7052 Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Thu, 8 Aug 2024 06:17:46 -0700
Subject: [PATCH 3/4] [SLP][REVEC] Apply comments.
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 7f098899311c03..33d891da7399bd 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6403,12 +6403,13 @@ BoUpSLP::TreeEntry::EntryState BoUpSLP::getScalarsVectorizationState(
}
if (any_of(VL, [&SourceVectors](Value *V) {
- if (SourceVectors.contains(V))
- return !V->hasOneUse();
// The last InsertElement can have multiple uses.
- return false;
- }))
+ return SourceVectors.contains(V) && !V->hasOneUse();
+ })) {
+ LLVM_DEBUG(dbgs() << "SLP: Gather of insertelement vectors with "
+ "multiple uses.\n");
return TreeEntry::NeedToGather;
+ }
return TreeEntry::Vectorize;
}
>From 24b89e03c2a7c1f7b06fac314bdbf94d1bda2ad3 Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Thu, 8 Aug 2024 06:53:27 -0700
Subject: [PATCH 4/4] [SLP][REVEC] Apply comments.
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 33d891da7399bd..009b2fb2ca342d 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6406,6 +6406,7 @@ BoUpSLP::TreeEntry::EntryState BoUpSLP::getScalarsVectorizationState(
// 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;
More information about the llvm-commits
mailing list