[llvm] [SLP][REVEC] reorderNodeWithReuses should not be called if all users of a TreeEntry are ShuffleVectorInst. (PR #118260)
Han-Kuan Chen via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 2 08:17:44 PST 2024
https://github.com/HanKuanChen updated https://github.com/llvm/llvm-project/pull/118260
>From 25f59ef4ff0008562994bb8d22d92f1eb04a963b Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Sun, 1 Dec 2024 22:18:32 -0800
Subject: [PATCH 1/4] [SLP][REVEC] Pre-commit test.
---
llvm/test/Transforms/SLPVectorizer/revec.ll | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/llvm/test/Transforms/SLPVectorizer/revec.ll b/llvm/test/Transforms/SLPVectorizer/revec.ll
index b160c0174c0a76..f06f49fc7e5409 100644
--- a/llvm/test/Transforms/SLPVectorizer/revec.ll
+++ b/llvm/test/Transforms/SLPVectorizer/revec.ll
@@ -447,3 +447,22 @@ for.end.loopexit:
store <4 x i32> %4, ptr %out2, align 4
ret void
}
+
+define void @test14(<8 x i1> %0) {
+entry:
+ %sext0 = sext <8 x i1> %0 to <8 x i16>
+ %sext1 = sext <8 x i1> %0 to <8 x i16>
+ %1 = shufflevector <8 x i16> %sext0, <8 x i16> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+ %2 = shufflevector <8 x i16> %sext0, <8 x i16> zeroinitializer, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
+ %3 = shufflevector <8 x i16> %sext1, <8 x i16> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+ %4 = shufflevector <8 x i16> %sext1, <8 x i16> zeroinitializer, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
+ br label %for.end.loopexit
+
+for.end.loopexit:
+ %phi0 = phi <4 x i16> [ %1, %entry ]
+ %phi1 = phi <4 x i16> [ %2, %entry ]
+ %phi2 = phi <4 x i16> [ %3, %entry ]
+ %phi3 = phi <4 x i16> [ %4, %entry ]
+ %or0 = or <4 x i16> %phi1, zeroinitializer
+ ret void
+}
>From 57600b7fcfbf09d040beabd79ceb767221c3c6ad Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Sun, 1 Dec 2024 22:21:14 -0800
Subject: [PATCH 2/4] [SLP][REVEC] reorderNodeWithReuses should not be called
if all users of a TreeEntry are ShuffleVectorInst.
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 17 +++++++++++++++++
llvm/test/Transforms/SLPVectorizer/revec.ll | 15 +++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 04755102643364..74f5df11ed6a9e 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6073,6 +6073,23 @@ void BoUpSLP::reorderTopToBottom() {
TE->Scalars.size();
}) &&
"All users must be of VF size.");
+ if (SLPReVec) {
+ assert(SLPReVec && "Only supported by REVEC.");
+ // ShuffleVectorInst does not do reorderOperands (and it should not
+ // because ShuffleVectorInst supports only a limited set of
+ // patterns). Only do reorderNodeWithReuses if all of the users are
+ // not ShuffleVectorInst.
+ if (all_of(TE->UserTreeIndices, [&](const EdgeInfo &EI) {
+ return isa<ShuffleVectorInst>(EI.UserTE->getMainOp());
+ }))
+ continue;
+ assert(all_of(TE->UserTreeIndices,
+ [&](const EdgeInfo &EI) {
+ return !isa<ShuffleVectorInst>(
+ EI.UserTE->getMainOp());
+ }) &&
+ "Does not know how to reorder.");
+ }
// Update ordering of the operands with the smaller VF than the given
// one.
reorderNodeWithReuses(*TE, Mask);
diff --git a/llvm/test/Transforms/SLPVectorizer/revec.ll b/llvm/test/Transforms/SLPVectorizer/revec.ll
index f06f49fc7e5409..ce13f478d38116 100644
--- a/llvm/test/Transforms/SLPVectorizer/revec.ll
+++ b/llvm/test/Transforms/SLPVectorizer/revec.ll
@@ -449,6 +449,21 @@ for.end.loopexit:
}
define void @test14(<8 x i1> %0) {
+; CHECK-LABEL: @test14(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP1:%.*]] = call <16 x i1> @llvm.vector.insert.v16i1.v8i1(<16 x i1> poison, <8 x i1> [[TMP0:%.*]], i64 0)
+; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <16 x i1> [[TMP1]], <16 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 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
+; CHECK-NEXT: [[TMP3:%.*]] = sext <16 x i1> [[TMP2]] to <16 x i16>
+; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <16 x i16> [[TMP3]], <16 x i16> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
+; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <16 x i16> [[TMP3]], <16 x i16> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
+; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <16 x i16> [[TMP3]], <16 x i16> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 4, i32 5, i32 6, i32 7>
+; CHECK-NEXT: br label [[FOR_END_LOOPEXIT:%.*]]
+; CHECK: for.end.loopexit:
+; CHECK-NEXT: [[TMP7:%.*]] = phi <16 x i16> [ [[TMP6]], [[ENTRY:%.*]] ]
+; CHECK-NEXT: [[TMP8:%.*]] = call <4 x i16> @llvm.vector.extract.v4i16.v16i16(<16 x i16> [[TMP7]], i64 12)
+; CHECK-NEXT: [[OR0:%.*]] = or <4 x i16> [[TMP8]], zeroinitializer
+; CHECK-NEXT: ret void
+;
entry:
%sext0 = sext <8 x i1> %0 to <8 x i16>
%sext1 = sext <8 x i1> %0 to <8 x i16>
>From 1d738c0a576de988cb321601ce2dbf3c8727eb0f Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Mon, 2 Dec 2024 23:57:43 +0800
Subject: [PATCH 3/4] Update llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Co-authored-by: Alexey Bataev <a.bataev at gmx.com>
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 74f5df11ed6a9e..d2aeb413cbd527 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6083,9 +6083,9 @@ void BoUpSLP::reorderTopToBottom() {
return isa<ShuffleVectorInst>(EI.UserTE->getMainOp());
}))
continue;
- assert(all_of(TE->UserTreeIndices,
+ assert(none_of(TE->UserTreeIndices,
[&](const EdgeInfo &EI) {
- return !isa<ShuffleVectorInst>(
+ return isa<ShuffleVectorInst>(
EI.UserTE->getMainOp());
}) &&
"Does not know how to reorder.");
>From 819b6887e5691207e75265c28a4aca006c4bcafe Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Mon, 2 Dec 2024 08:17:28 -0800
Subject: [PATCH 4/4] clang-format
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index d2aeb413cbd527..33657c26356d65 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6084,10 +6084,10 @@ void BoUpSLP::reorderTopToBottom() {
}))
continue;
assert(none_of(TE->UserTreeIndices,
- [&](const EdgeInfo &EI) {
- return isa<ShuffleVectorInst>(
- EI.UserTE->getMainOp());
- }) &&
+ [&](const EdgeInfo &EI) {
+ return isa<ShuffleVectorInst>(
+ EI.UserTE->getMainOp());
+ }) &&
"Does not know how to reorder.");
}
// Update ordering of the operands with the smaller VF than the given
More information about the llvm-commits
mailing list