[llvm] [SLP][REVEC] Fix getStoreMinimumVF only accept scalar types. (PR #132181)
Han-Kuan Chen via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 20 03:50:40 PDT 2025
https://github.com/HanKuanChen created https://github.com/llvm/llvm-project/pull/132181
Fix "Element type of a VectorType must " "be an integer, floating point,
or " "pointer type.".
>From a9094e1260d98cabffe633870b840bd7039dfba2 Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Thu, 20 Mar 2025 03:19:39 -0700
Subject: [PATCH 1/2] [SLP][REVEC] Pre-commit test.
---
.../SLPVectorizer/X86/revec-getStoreMinimumVF.ll | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 llvm/test/Transforms/SLPVectorizer/X86/revec-getStoreMinimumVF.ll
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/revec-getStoreMinimumVF.ll b/llvm/test/Transforms/SLPVectorizer/X86/revec-getStoreMinimumVF.ll
new file mode 100644
index 0000000000000..ed7728eb46a8a
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/revec-getStoreMinimumVF.ll
@@ -0,0 +1,10 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -mtriple=x86_64-unknown-linux-gnu -passes=slp-vectorizer -S -slp-revec %s | FileCheck %s
+
+define void @test() {
+entry:
+ %0 = getelementptr i8, ptr null, i64 4
+ store <4 x i8> zeroinitializer, ptr null, align 1
+ store <4 x i8> zeroinitializer, ptr %0, align 1
+ ret void
+}
>From a52fcc0f1562315ed8f10ab36623859633f6d845 Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Thu, 20 Mar 2025 03:12:17 -0700
Subject: [PATCH 2/2] [SLP][REVEC] Fix getStoreMinimumVF only accept scalar
types.
Fix "Element type of a VectorType must " "be an integer, floating point,
or " "pointer type.".
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 16 ++++++++++++----
.../SLPVectorizer/X86/revec-getStoreMinimumVF.ll | 7 +++++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index a2200f283168d..ad6e0a838cc1b 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -19697,10 +19697,18 @@ bool SLPVectorizerPass::vectorizeStores(
Type *ValueTy = StoreTy;
if (auto *Trunc = dyn_cast<TruncInst>(Store->getValueOperand()))
ValueTy = Trunc->getSrcTy();
- unsigned MinVF = std::max<unsigned>(
- 2, PowerOf2Ceil(TTI->getStoreMinimumVF(
- R.getMinVF(DL->getTypeStoreSizeInBits(StoreTy)), StoreTy,
- ValueTy)));
+ // When REVEC is enabled, StoreTy and ValueTy may be FixedVectorType. But
+ // getStoreMinimumVF only support scalar type as arguments. As a result,
+ // we need to use the element type of StoreTy and ValueTy to retrieve the
+ // VF and then transform it back.
+ // Remember: VF is defined as the number we want to vectorize, not the
+ // number of elements in the final vector.
+ Type *StoreScalarTy = StoreTy->getScalarType();
+ unsigned MinVF = PowerOf2Ceil(TTI->getStoreMinimumVF(
+ R.getMinVF(DL->getTypeStoreSizeInBits(StoreScalarTy)), StoreScalarTy,
+ ValueTy->getScalarType()));
+ MinVF /= getNumElements(StoreTy);
+ MinVF = std::max<unsigned>(2, MinVF);
if (MaxVF < MinVF) {
LLVM_DEBUG(dbgs() << "SLP: Vectorization infeasible as MaxVF (" << MaxVF
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/revec-getStoreMinimumVF.ll b/llvm/test/Transforms/SLPVectorizer/X86/revec-getStoreMinimumVF.ll
index ed7728eb46a8a..3aea112e9edfe 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/revec-getStoreMinimumVF.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/revec-getStoreMinimumVF.ll
@@ -2,6 +2,13 @@
; RUN: opt -mtriple=x86_64-unknown-linux-gnu -passes=slp-vectorizer -S -slp-revec %s | FileCheck %s
define void @test() {
+; CHECK-LABEL: @test(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = call <8 x i8> @llvm.vector.insert.v8i8.v4i8(<8 x i8> poison, <4 x i8> zeroinitializer, i64 0)
+; CHECK-NEXT: [[TMP1:%.*]] = call <8 x i8> @llvm.vector.insert.v8i8.v4i8(<8 x i8> [[TMP0]], <4 x i8> zeroinitializer, i64 4)
+; CHECK-NEXT: store <8 x i8> [[TMP1]], ptr null, align 1
+; CHECK-NEXT: ret void
+;
entry:
%0 = getelementptr i8, ptr null, i64 4
store <4 x i8> zeroinitializer, ptr null, align 1
More information about the llvm-commits
mailing list