[llvm] [SLP][REVEC] Fix false assumption of the source for castToScalarTyElem. (PR #99424)

Han-Kuan Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 17 22:25:07 PDT 2024


https://github.com/HanKuanChen updated https://github.com/llvm/llvm-project/pull/99424

>From 35712db1c23d32ef78bf12bd2cdce74163dfaf8a Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Wed, 17 Jul 2024 22:20:55 -0700
Subject: [PATCH 1/2] [SLP][REVEC] Pre-commit test.

---
 .../Transforms/SLPVectorizer/revec-fix-99411.ll    | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll

diff --git a/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll b/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll
new file mode 100644
index 0000000000000..d015117fc4364
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -mtriple x86_64-unknown-linux-gnu -passes=slp-vectorizer -S %s | FileCheck %s
+
+define void @e() {
+entry:
+  %0 = extractelement <1 x i64> zeroinitializer, i64 0
+  %bf.value = and i64 %0, 0
+  %bf.set = or i64 0, %bf.value
+  store i64 %bf.set, ptr getelementptr inbounds (i8, ptr null, i64 8), align 8
+  %bf.value2 = and i64 0, 0
+  %bf.set4 = or i64 0, %bf.value2
+  store i64 %bf.set4, ptr null, align 8
+  ret void
+}

>From 79d17082a704dd1e5f2fcb432e21d30c5deb564f Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Wed, 17 Jul 2024 20:35:42 -0700
Subject: [PATCH 2/2] [SLP][REVEC] Fix false assumption of the source for
 castToScalarTyElem.

The argument V may come from adjustExtracts, which is the vector operand
of ExtractElementInst. In addition, it is not existed in getTreeEntry.

The vector operand of ExtractElementInst may have a type of <1 x Ty>,
ensuring that the number of elements in ScalarTy and VecTy are equal.

reference: https://github.com/llvm/llvm-project/issues/99411
---
 llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp       | 3 +--
 llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll | 5 +++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index ccb6734d5618c..1201bed539505 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -11850,8 +11850,7 @@ class BoUpSLP::ShuffleInstructionBuilder final : public BaseShuffleAnalysis {
   Value *castToScalarTyElem(Value *V,
                             std::optional<bool> IsSigned = std::nullopt) {
     auto *VecTy = cast<VectorType>(V->getType());
-    assert(getNumElements(ScalarTy) < getNumElements(VecTy) &&
-           (getNumElements(VecTy) % getNumElements(ScalarTy) == 0));
+    assert(getNumElements(VecTy) % getNumElements(ScalarTy) == 0);
     if (VecTy->getElementType() == ScalarTy->getScalarType())
       return V;
     return Builder.CreateIntCast(
diff --git a/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll b/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll
index d015117fc4364..655e4a1aa5483 100644
--- a/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll
+++ b/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll
@@ -2,6 +2,11 @@
 ; RUN: opt -mtriple x86_64-unknown-linux-gnu -passes=slp-vectorizer -S %s | FileCheck %s
 
 define void @e() {
+; CHECK-LABEL: @e(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    store <2 x i64> zeroinitializer, ptr null, align 8
+; CHECK-NEXT:    ret void
+;
 entry:
   %0 = extractelement <1 x i64> zeroinitializer, i64 0
   %bf.value = and i64 %0, 0



More information about the llvm-commits mailing list