[llvm] 41c97af - [SLP][NFC]Remove handling of duplicates from getGatherCost
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 16 03:53:14 PDT 2025
Author: Alexey Bataev
Date: 2025-04-16T06:53:10-04:00
New Revision: 41c97afea055a5b7264167ec47b8c14c0f471f2f
URL: https://github.com/llvm/llvm-project/commit/41c97afea055a5b7264167ec47b8c14c0f471f2f
DIFF: https://github.com/llvm/llvm-project/commit/41c97afea055a5b7264167ec47b8c14c0f471f2f.diff
LOG: [SLP][NFC]Remove handling of duplicates from getGatherCost
Duplicates are handled in BoUpSLP::processBuildVector (see TryPackScalars), support for duplicates in getGatherCost is not needed anymore.
Reviewers: hiraditya, RKSimon
Reviewed By: hiraditya, RKSimon
Pull Request: https://github.com/llvm/llvm-project/pull/135834
Added:
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 b48674f6993e3..f9acc276f37f9 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -15727,13 +15727,10 @@ InstructionCost BoUpSLP::getGatherCost(ArrayRef<Value *> VL, bool ForPoisonSrc,
Type *ScalarTy) const {
const unsigned VF = VL.size();
auto *VecTy = getWidenedType(ScalarTy, VF);
- bool DuplicateNonConst = false;
// Find the cost of inserting/extracting values from the vector.
// Check if the same elements are inserted several times and count them as
// shuffle candidates.
- APInt ShuffledElements = APInt::getZero(VF);
APInt DemandedElements = APInt::getZero(VF);
- DenseMap<Value *, unsigned> UniqueElements;
constexpr TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
InstructionCost Cost;
auto EstimateInsertCost = [&](unsigned I, Value *V) {
@@ -15742,32 +15739,18 @@ InstructionCost BoUpSLP::getGatherCost(ArrayRef<Value *> VL, bool ForPoisonSrc,
Cost += TTI->getCastInstrCost(Instruction::Trunc, ScalarTy, V->getType(),
TTI::CastContextHint::None, CostKind);
};
- SmallVector<int> ShuffleMask(VF, PoisonMaskElem);
SmallVector<int> ConstantShuffleMask(VF, PoisonMaskElem);
std::iota(ConstantShuffleMask.begin(), ConstantShuffleMask.end(), 0);
for (auto [I, V] : enumerate(VL)) {
// No need to shuffle duplicates for constants.
- if ((ForPoisonSrc && isConstant(V)) || isa<UndefValue>(V)) {
- ShuffledElements.setBit(I);
- ShuffleMask[I] = isa<PoisonValue>(V) ? PoisonMaskElem : I;
+ if ((ForPoisonSrc && isConstant(V)) || isa<UndefValue>(V))
continue;
- }
if (isConstant(V)) {
ConstantShuffleMask[I] = I + VF;
- ShuffleMask[I] = I;
- continue;
- }
- auto Res = UniqueElements.try_emplace(V, I);
- if (Res.second) {
- EstimateInsertCost(I, V);
- ShuffleMask[I] = I;
continue;
}
-
- DuplicateNonConst = true;
- ShuffledElements.setBit(I);
- ShuffleMask[I] = Res.first->second;
+ EstimateInsertCost(I, V);
}
// FIXME: add a cost for constant vector materialization.
bool IsAnyNonUndefConst =
@@ -15776,15 +15759,6 @@ InstructionCost BoUpSLP::getGatherCost(ArrayRef<Value *> VL, bool ForPoisonSrc,
if (!ForPoisonSrc && IsAnyNonUndefConst) {
Cost += ::getShuffleCost(*TTI, TargetTransformInfo::SK_PermuteTwoSrc, VecTy,
ConstantShuffleMask);
- // Update the shuffle mask for shuffling with incoming source (all elements
- // are used!) or with constant subvector.
- for_each(enumerate(ShuffleMask), [&](auto P) {
- if ((!ForPoisonSrc && P.value() == PoisonMaskElem) ||
- ConstantShuffleMask[P.index()] != PoisonMaskElem)
- P.value() = P.index();
- else if (P.value() != PoisonMaskElem)
- P.value() += VF;
- });
}
// 2. Insert unique non-constants.
@@ -15793,10 +15767,6 @@ InstructionCost BoUpSLP::getGatherCost(ArrayRef<Value *> VL, bool ForPoisonSrc,
/*Insert=*/true,
/*Extract=*/false, CostKind,
ForPoisonSrc && !IsAnyNonUndefConst, VL);
- // 3. Shuffle duplicates.
- if (DuplicateNonConst)
- Cost += ::getShuffleCost(*TTI, TargetTransformInfo::SK_PermuteSingleSrc,
- VecTy, ShuffleMask, CostKind);
return Cost;
}
More information about the llvm-commits
mailing list