[llvm] [SLP][REVEC] Ignore UserTreeIndex if it is empty. (PR #131993)
Han-Kuan Chen via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 19 08:14:01 PDT 2025
https://github.com/HanKuanChen updated https://github.com/llvm/llvm-project/pull/131993
>From e92f2eee49ad3992aef3bbd0168add57830efffe Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Wed, 19 Mar 2025 02:51:32 -0700
Subject: [PATCH 1/4] [SLP][REVEC] Pre-commit test.
---
...ec-reduced-value-replace-extractelement.ll | 21 +++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 llvm/test/Transforms/SLPVectorizer/X86/revec-reduced-value-replace-extractelement.ll
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/revec-reduced-value-replace-extractelement.ll b/llvm/test/Transforms/SLPVectorizer/X86/revec-reduced-value-replace-extractelement.ll
new file mode 100644
index 0000000000000..2297eae416732
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/revec-reduced-value-replace-extractelement.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S --passes=slp-vectorizer -slp-threshold=-99999 < %s -mtriple=x86_64-unknown-linux-gnu -slp-revec | FileCheck %s
+
+define void @test() {
+bb:
+ br label %bb1
+
+bb1:
+ %phi = phi i32 [ 0, %bb ], [ %mul9, %bb1 ]
+ %phi2 = phi i32 [ 0, %bb ], [ 0, %bb1 ]
+ %trunc = trunc i64 0 to i32
+ %mul = mul i32 0, %trunc
+ %mul3 = mul i32 %trunc, %phi
+ %mul4 = mul i32 %mul3, %mul
+ %mul5 = mul i32 %mul4, %mul
+ %trunc6 = trunc i64 0 to i32
+ %mul7 = mul i32 0, %trunc6
+ %mul8 = mul i32 %mul5, %mul7
+ %mul9 = mul i32 %mul8, %mul7
+ br label %bb1
+}
>From 23ad5592b4a54fff95a936b3e986bd06dcf2ee06 Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Wed, 19 Mar 2025 02:49:49 -0700
Subject: [PATCH 2/4] [SLP][REVEC] Ignore UserTreeIndex if it is empty.
Previously, the all_of check did not consider the case where the
TreeEntry is empty (i.e., when it is the first entry).
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 7 ++++---
.../revec-reduced-value-replace-extractelement.ll | 14 ++++++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index a2200f283168d..084da5607e400 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6449,9 +6449,10 @@ void BoUpSLP::reorderTopToBottom() {
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 (isa<ShuffleVectorInst>(TE->UserTreeIndex.UserTE->getMainOp()))
+ // patterns). Only do reorderNodeWithReuses if the user is not
+ // ShuffleVectorInst.
+ if (TE->UserTreeIndex &&
+ isa<ShuffleVectorInst>(TE->UserTreeIndex.UserTE->getMainOp()))
continue;
assert((!TE->UserTreeIndex ||
!isa<ShuffleVectorInst>(
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/revec-reduced-value-replace-extractelement.ll b/llvm/test/Transforms/SLPVectorizer/X86/revec-reduced-value-replace-extractelement.ll
index 2297eae416732..bdd5971c0c91a 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/revec-reduced-value-replace-extractelement.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/revec-reduced-value-replace-extractelement.ll
@@ -2,6 +2,20 @@
; RUN: opt -S --passes=slp-vectorizer -slp-threshold=-99999 < %s -mtriple=x86_64-unknown-linux-gnu -slp-revec | FileCheck %s
define void @test() {
+; CHECK-LABEL: define void @test() {
+; CHECK-NEXT: [[BB:.*]]:
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 0 to i32
+; CHECK-NEXT: br label %[[BB1:.*]]
+; CHECK: [[BB1]]:
+; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i32> [ zeroinitializer, %[[BB]] ], [ [[TMP4:%.*]], %[[BB1]] ]
+; CHECK-NEXT: [[TMP1:%.*]] = extractelement <2 x i32> [[TMP0]], i32 1
+; CHECK-NEXT: [[TMP2:%.*]] = call i8 @llvm.vector.reduce.mul.v4i8(<4 x i8> zeroinitializer)
+; CHECK-NEXT: [[TMP3:%.*]] = zext i8 [[TMP2]] to i32
+; CHECK-NEXT: [[OP_RDX:%.*]] = mul i32 [[TMP3]], [[TMP1]]
+; CHECK-NEXT: [[OP_RDX1:%.*]] = mul i32 [[OP_RDX]], [[TRUNC]]
+; CHECK-NEXT: [[TMP4]] = insertelement <2 x i32> <i32 0, i32 poison>, i32 [[OP_RDX1]], i32 1
+; CHECK-NEXT: br label %[[BB1]]
+;
bb:
br label %bb1
>From bd6d98c31ef7b4e2a503a2d48002d123f740adca Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Wed, 19 Mar 2025 08:10:56 -0700
Subject: [PATCH 3/4] remove assert
Previously a TreeEntry may have multiple users. If only one of them is
ShuffleVectorInst, then we don't know how to do. But right now a
TreeEntry can only have 1 user.
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 4 ----
1 file changed, 4 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 084da5607e400..e1cca4a18d478 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6454,10 +6454,6 @@ void BoUpSLP::reorderTopToBottom() {
if (TE->UserTreeIndex &&
isa<ShuffleVectorInst>(TE->UserTreeIndex.UserTE->getMainOp()))
continue;
- assert((!TE->UserTreeIndex ||
- !isa<ShuffleVectorInst>(
- TE->UserTreeIndex.UserTE->getMainOp())) &&
- "Does not know how to reorder.");
}
// Update ordering of the operands with the smaller VF than the given
// one.
>From 11dde44f160bfc6e7ca8648d97c110c4963d8570 Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Wed, 19 Mar 2025 08:13:15 -0700
Subject: [PATCH 4/4] apply comment
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index e1cca4a18d478..61c4df68799c6 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6451,7 +6451,7 @@ void BoUpSLP::reorderTopToBottom() {
// because ShuffleVectorInst supports only a limited set of
// patterns). Only do reorderNodeWithReuses if the user is not
// ShuffleVectorInst.
- if (TE->UserTreeIndex &&
+ if (TE->UserTreeIndex && TE->UserTreeIndex.UserTE->hasState() &&
isa<ShuffleVectorInst>(TE->UserTreeIndex.UserTE->getMainOp()))
continue;
}
More information about the llvm-commits
mailing list