[llvm] 73558dc - [SLP][REVEC] Fix getStoreMinimumVF only accept scalar types. (#132181)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 20 06:04:35 PDT 2025
Author: Han-Kuan Chen
Date: 2025-03-20T21:04:30+08:00
New Revision: 73558dc329ee44465672fc492ec8dcee8afad2fa
URL: https://github.com/llvm/llvm-project/commit/73558dc329ee44465672fc492ec8dcee8afad2fa
DIFF: https://github.com/llvm/llvm-project/commit/73558dc329ee44465672fc492ec8dcee8afad2fa.diff
LOG: [SLP][REVEC] Fix getStoreMinimumVF only accept scalar types. (#132181)
Fix "Element type of a VectorType must " "be an integer, floating point,
or " "pointer type.".
Added:
llvm/test/Transforms/SLPVectorizer/X86/revec-getStoreMinimumVF.ll
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 67518ddfb067d..105b80dc75a83 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -19724,10 +19724,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
new file mode 100644
index 0000000000000..3aea112e9edfe
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/revec-getStoreMinimumVF.ll
@@ -0,0 +1,17 @@
+; 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() {
+; 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
+ store <4 x i8> zeroinitializer, ptr %0, align 1
+ ret void
+}
More information about the llvm-commits
mailing list