-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SLP][REVEC] Make MinBWs support vector instructions. #103049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If ScalarTy is FixedVectorType, it should remain as FixedVectorType.
@llvm/pr-subscribers-llvm-transforms Author: Han-Kuan Chen (HanKuanChen) ChangesIf ScalarTy is FixedVectorType, it should remain as FixedVectorType. Full diff: https://github.com/llvm/llvm-project/pull/103049.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 8a08d766a8ed4..ebfb11f841086 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -9527,8 +9527,12 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
// that the costs will be accurate.
auto It = MinBWs.find(E);
Type *OrigScalarTy = ScalarTy;
- if (It != MinBWs.end())
+ if (It != MinBWs.end()) {
+ auto VecTy = dyn_cast<FixedVectorType>(ScalarTy);
ScalarTy = IntegerType::get(F->getContext(), It->second.first);
+ if (VecTy)
+ ScalarTy = getWidenedType(ScalarTy, VecTy->getNumElements());
+ }
auto *VecTy = getWidenedType(ScalarTy, VL.size());
unsigned EntryVF = E->getVectorFactor();
auto *FinalVecTy = getWidenedType(ScalarTy, EntryVF);
@@ -13127,8 +13131,12 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
else if (auto *IE = dyn_cast<InsertElementInst>(V))
ScalarTy = IE->getOperand(1)->getType();
auto It = MinBWs.find(E);
- if (It != MinBWs.end())
+ if (It != MinBWs.end()) {
+ auto VecTy = dyn_cast<FixedVectorType>(ScalarTy);
ScalarTy = IntegerType::get(F->getContext(), It->second.first);
+ if (VecTy)
+ ScalarTy = getWidenedType(ScalarTy, VecTy->getNumElements());
+ }
auto *VecTy = getWidenedType(ScalarTy, E->Scalars.size());
if (E->isGather()) {
// Set insert point for non-reduction initial nodes.
@@ -16003,8 +16011,9 @@ void BoUpSLP::computeMinimumValueSizes() {
}
unsigned VF = E.getVectorFactor();
- auto *TreeRootIT =
- dyn_cast<IntegerType>(E.Scalars.front()->getType()->getScalarType());
+ Type *ScalarTy = E.Scalars.front()->getType();
+ unsigned ScalarTyNumElements = getNumElements(ScalarTy);
+ auto *TreeRootIT = dyn_cast<IntegerType>(ScalarTy->getScalarType());
if (!TreeRootIT || !Opcode)
return 0u;
@@ -16012,7 +16021,8 @@ void BoUpSLP::computeMinimumValueSizes() {
[&](Value *V) { return AnalyzedMinBWVals.contains(V); }))
return 0u;
- unsigned NumParts = TTI->getNumberOfParts(getWidenedType(TreeRootIT, VF));
+ unsigned NumParts = TTI->getNumberOfParts(
+ getWidenedType(TreeRootIT, VF * ScalarTyNumElements));
// The maximum bit width required to represent all the values that can be
// demoted without loss of precision. It would be safe to truncate the roots
@@ -16034,7 +16044,8 @@ void BoUpSLP::computeMinimumValueSizes() {
// we can truncate the roots to this narrower type.
for (Value *Root : E.Scalars) {
unsigned NumSignBits = ComputeNumSignBits(Root, *DL, 0, AC, nullptr, DT);
- TypeSize NumTypeBits = DL->getTypeSizeInBits(Root->getType());
+ TypeSize NumTypeBits =
+ DL->getTypeSizeInBits(Root->getType()->getScalarType());
unsigned BitWidth1 = NumTypeBits - NumSignBits;
// If we can't prove that the sign bit is zero, we must add one to the
// maximum bit width to account for the unknown sign bit. This preserves
@@ -16206,7 +16217,8 @@ void BoUpSLP::computeMinimumValueSizes() {
// type, we can proceed with the narrowing. Otherwise, do nothing.
if (MaxBitWidth == 0 ||
MaxBitWidth >=
- cast<IntegerType>(TreeRoot.front()->getType())->getBitWidth()) {
+ cast<IntegerType>(TreeRoot.front()->getType()->getScalarType())
+ ->getBitWidth()) {
if (UserIgnoreList)
AnalyzedMinBWVals.insert(TreeRoot.begin(), TreeRoot.end());
continue;
diff --git a/llvm/test/Transforms/SLPVectorizer/revec.ll b/llvm/test/Transforms/SLPVectorizer/revec.ll
index 9ce9db1d360cc..31ee107c81cd4 100644
--- a/llvm/test/Transforms/SLPVectorizer/revec.ll
+++ b/llvm/test/Transforms/SLPVectorizer/revec.ll
@@ -272,3 +272,27 @@ for.body:
%5 = phi <2 x float> [ %5, %for.body ], [ zeroinitializer, %entry ]
br i1 false, label %for0, label %for.body
}
+
+define void @test9() {
+; CHECK-LABEL: @test9(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = call <8 x i16> @llvm.vector.insert.v8i16.v4i16(<8 x i16> poison, <4 x i16> zeroinitializer, i64 0)
+; CHECK-NEXT: [[TMP1:%.*]] = call <8 x i16> @llvm.vector.insert.v8i16.v4i16(<8 x i16> [[TMP0]], <4 x i16> zeroinitializer, i64 4)
+; CHECK-NEXT: br label [[FOR_BODY13:%.*]]
+; CHECK: for.body13:
+; CHECK-NEXT: [[TMP2:%.*]] = trunc <8 x i16> [[TMP1]] to <8 x i1>
+; CHECK-NEXT: [[TMP3:%.*]] = zext <8 x i1> [[TMP2]] to <8 x i32>
+; CHECK-NEXT: store <8 x i32> [[TMP3]], ptr null, align 4
+; CHECK-NEXT: br label [[FOR_BODY13]]
+;
+entry:
+ br label %for.body13
+
+for.body13: ; preds = %for.body13, %entry
+ %vmovl.i111 = sext <4 x i16> zeroinitializer to <4 x i32>
+ %vmovl.i110 = sext <4 x i16> zeroinitializer to <4 x i32>
+ store <4 x i32> %vmovl.i111, ptr null, align 4
+ %add.ptr29 = getelementptr i8, ptr null, i64 16
+ store <4 x i32> %vmovl.i110, ptr %add.ptr29, align 4
+ br label %for.body13
+}
|
alexey-bataev
approved these changes
Aug 13, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If ScalarTy is FixedVectorType, it should remain as FixedVectorType.