[llvm] [SLP][REVEC] Fix CreateInsertElement does not use the correct result if MinBWs applied. (PR #104558)
Han-Kuan Chen via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 16 00:24:27 PDT 2024
https://github.com/HanKuanChen created https://github.com/llvm/llvm-project/pull/104558
None
>From 03c603e7289c224065290b57ded5d01dd589a611 Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Fri, 16 Aug 2024 00:16:47 -0700
Subject: [PATCH 1/2] [SLP][REVEC] Pre-commit test.
---
llvm/test/Transforms/SLPVectorizer/revec.ll | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/llvm/test/Transforms/SLPVectorizer/revec.ll b/llvm/test/Transforms/SLPVectorizer/revec.ll
index 59201da1d9ac1a..8878dc3b5a7360 100644
--- a/llvm/test/Transforms/SLPVectorizer/revec.ll
+++ b/llvm/test/Transforms/SLPVectorizer/revec.ll
@@ -336,3 +336,16 @@ entry:
store <4 x i32> %vmovl.i108, ptr %add.ptr35, align 4
ret void
}
+
+define void @test11(<2 x i64> %0, i64 %1, <2 x i64> %2) {
+entry:
+ %3 = insertelement <2 x i64> %0, i64 %1, i32 1
+ %4 = add <2 x i64> <i64 5, i64 0>, %2
+ %5 = trunc <2 x i64> %3 to <2 x i8>
+ %6 = trunc <2 x i64> %4 to <2 x i8>
+ %7 = urem <2 x i8> %5, zeroinitializer
+ %8 = urem <2 x i8> %6, zeroinitializer
+ %9 = icmp ne <2 x i8> %7, zeroinitializer
+ %10 = icmp ne <2 x i8> %8, zeroinitializer
+ ret void
+}
>From 271e9f0f365503539180b02daec11ac00007f4ec Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Fri, 16 Aug 2024 00:18:47 -0700
Subject: [PATCH 2/2] [SLP][REVEC] Fix CreateInsertElement does not use the
correct result if MinBWs applied.
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 2 +-
llvm/test/Transforms/SLPVectorizer/revec.ll | 15 +++++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index feffd9ae3c99b7..d9d710041d3c3f 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -11977,7 +11977,7 @@ Value *BoUpSLP::gather(ArrayRef<Value *> VL, Value *Root, Type *ScalarTy) {
if (auto *VecTy = dyn_cast<FixedVectorType>(Scalar->getType())) {
assert(SLPReVec && "FixedVectorType is not expected.");
Vec = InsElt = Builder.CreateInsertVector(
- Vec->getType(), Vec, V,
+ Vec->getType(), Vec, Scalar,
Builder.getInt64(Pos * VecTy->getNumElements()));
auto *II = dyn_cast<IntrinsicInst>(InsElt);
if (!II || II->getIntrinsicID() != Intrinsic::vector_insert)
diff --git a/llvm/test/Transforms/SLPVectorizer/revec.ll b/llvm/test/Transforms/SLPVectorizer/revec.ll
index 8878dc3b5a7360..ad1a57c7176197 100644
--- a/llvm/test/Transforms/SLPVectorizer/revec.ll
+++ b/llvm/test/Transforms/SLPVectorizer/revec.ll
@@ -338,6 +338,21 @@ entry:
}
define void @test11(<2 x i64> %0, i64 %1, <2 x i64> %2) {
+; CHECK-LABEL: @test11(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP3:%.*]] = insertelement <2 x i64> [[TMP0:%.*]], i64 [[TMP1:%.*]], i32 1
+; CHECK-NEXT: [[TMP4:%.*]] = add <2 x i64> <i64 5, i64 0>, [[TMP2:%.*]]
+; CHECK-NEXT: [[TMP5:%.*]] = trunc <2 x i64> [[TMP4]] to <2 x i16>
+; CHECK-NEXT: [[TMP6:%.*]] = call <4 x i16> @llvm.vector.insert.v4i16.v2i16(<4 x i16> poison, <2 x i16> [[TMP5]], i64 0)
+; CHECK-NEXT: [[TMP7:%.*]] = trunc <2 x i64> [[TMP3]] to <2 x i16>
+; CHECK-NEXT: [[TMP8:%.*]] = call <4 x i16> @llvm.vector.insert.v4i16.v2i16(<4 x i16> [[TMP6]], <2 x i16> [[TMP7]], i64 2)
+; CHECK-NEXT: [[TMP9:%.*]] = trunc <4 x i16> [[TMP8]] to <4 x i8>
+; CHECK-NEXT: [[TMP10:%.*]] = call <4 x i8> @llvm.vector.insert.v4i8.v2i8(<4 x i8> poison, <2 x i8> zeroinitializer, i64 0)
+; CHECK-NEXT: [[TMP11:%.*]] = call <4 x i8> @llvm.vector.insert.v4i8.v2i8(<4 x i8> [[TMP10]], <2 x i8> zeroinitializer, i64 2)
+; CHECK-NEXT: [[TMP12:%.*]] = urem <4 x i8> [[TMP9]], [[TMP11]]
+; CHECK-NEXT: [[TMP13:%.*]] = icmp ne <4 x i8> [[TMP12]], [[TMP11]]
+; CHECK-NEXT: ret void
+;
entry:
%3 = insertelement <2 x i64> %0, i64 %1, i32 1
%4 = add <2 x i64> <i64 5, i64 0>, %2
More information about the llvm-commits
mailing list