-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SLP][REVEC] Make getExtractWithExtendCost support FixedVectorType as Dst. #134822
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
HanKuanChen
merged 3 commits into
llvm:main
from
HanKuanChen:slp-revec-getExtractWithExtendCost
Apr 10, 2025
Merged
[SLP][REVEC] Make getExtractWithExtendCost support FixedVectorType as Dst. #134822
HanKuanChen
merged 3 commits into
llvm:main
from
HanKuanChen:slp-revec-getExtractWithExtendCost
Apr 10, 2025
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
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-vectorizers Author: Han-Kuan Chen (HanKuanChen) ChangesFull diff: https://github.com/llvm/llvm-project/pull/134822.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index e6559f26be8c2..6a96d6e40674c 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -5399,6 +5399,25 @@ static InstructionCost getVectorInstrCost(
ScalarUserAndIdx);
}
+/// This is similar to TargetTransformInfo::getExtractWithExtendCost, but if Dst
+/// is a FixedVectorType, a vector will be extracted instead of a scalar.
+static InstructionCost getExtractWithExtendCost(const TargetTransformInfo &TTI,
+ unsigned Opcode, Type *Dst,
+ VectorType *VecTy,
+ unsigned Index) {
+ if (auto *ScalarTy = dyn_cast<FixedVectorType>(Dst)) {
+ assert(SLPReVec && "Only supported by REVEC.");
+ TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
+ auto *SubTp =
+ getWidenedType(VecTy->getElementType(), ScalarTy->getNumElements());
+ return getShuffleCost(TTI, TTI::SK_ExtractSubvector, VecTy, {}, CostKind,
+ Index * ScalarTy->getNumElements(), SubTp) +
+ TTI.getCastInstrCost(Opcode, Dst, SubTp, TTI::CastContextHint::None,
+ CostKind);
+ }
+ return TTI.getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
+}
+
/// Correctly creates insert_subvector, checking that the index is multiple of
/// the subvectors length. Otherwise, generates shuffle using \p Generator or
/// using default shuffle.
@@ -14088,13 +14107,15 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals,
const TreeEntry *Entry = &EU.E;
auto It = MinBWs.find(Entry);
if (It != MinBWs.end()) {
- auto *MinTy = IntegerType::get(F->getContext(), It->second.first);
+ Type *MinTy = IntegerType::get(F->getContext(), It->second.first);
+ if (auto *VecTy = dyn_cast<FixedVectorType>(ScalarTy))
+ MinTy = getWidenedType(MinTy, VecTy->getNumElements());
unsigned Extend = isKnownNonNegative(EU.Scalar, SimplifyQuery(*DL))
? Instruction::ZExt
: Instruction::SExt;
VecTy = getWidenedType(MinTy, BundleWidth);
- ExtraCost = TTI->getExtractWithExtendCost(Extend, EU.Scalar->getType(),
- VecTy, EU.Lane);
+ ExtraCost =
+ getExtractWithExtendCost(*TTI, Extend, ScalarTy, VecTy, EU.Lane);
} else {
ExtraCost =
getVectorInstrCost(*TTI, ScalarTy, Instruction::ExtractElement, VecTy,
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/revec-getExtractWithExtendCost.ll b/llvm/test/Transforms/SLPVectorizer/X86/revec-getExtractWithExtendCost.ll
new file mode 100644
index 0000000000000..8d3d9f2979298
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/revec-getExtractWithExtendCost.ll
@@ -0,0 +1,27 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -mtriple=x86_64-unknown-linux-gnu -mattr=+avx10.2-512 -passes=slp-vectorizer -S -slp-revec %s | FileCheck %s
+
+define void @test() {
+; CHECK-LABEL: @test(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = sub <8 x i64> zeroinitializer, splat (i64 1)
+; CHECK-NEXT: [[TMP1:%.*]] = sub <8 x i64> zeroinitializer, zeroinitializer
+; CHECK-NEXT: [[TMP2:%.*]] = or <8 x i64> [[TMP0]], zeroinitializer
+; CHECK-NEXT: [[TMP3:%.*]] = trunc <8 x i64> [[TMP0]] to <8 x i32>
+; CHECK-NEXT: [[TMP4:%.*]] = trunc <8 x i64> [[TMP1]] to <8 x i32>
+; CHECK-NEXT: [[TMP5:%.*]] = getelementptr i8, ptr null, i64 32
+; CHECK-NEXT: store <8 x i32> [[TMP3]], ptr null, align 4
+; CHECK-NEXT: store <8 x i32> [[TMP4]], ptr [[TMP5]], align 4
+; CHECK-NEXT: ret void
+;
+entry:
+ %0 = sub <8 x i64> zeroinitializer, splat (i64 1)
+ %1 = sub <8 x i64> zeroinitializer, zeroinitializer
+ %2 = or <8 x i64> %0, zeroinitializer
+ %3 = trunc <8 x i64> %0 to <8 x i32>
+ %4 = trunc <8 x i64> %1 to <8 x i32>
+ %5 = getelementptr i8, ptr null, i64 32
+ store <8 x i32> %3, ptr null, align 4
+ store <8 x i32> %4, ptr %5, align 4
+ ret void
+}
|
alexey-bataev
approved these changes
Apr 10, 2025
var-const
pushed a commit
to ldionne/llvm-project
that referenced
this pull request
Apr 17, 2025
qiaojbao
pushed a commit
to GPUOpen-Drivers/llvm-project
that referenced
this pull request
Apr 29, 2025
Local branch origin/amd-gfx 6efc92e Merged main:e3f5a1bfc58b into origin/amd-gfx:6b6e30e6b6dc Remote branch main d02a704 [SLP][REVEC] Make getExtractWithExtendCost support FixedVectorType as Dst. (llvm#134822)
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.
No description provided.