@@ -15727,13 +15727,10 @@ InstructionCost BoUpSLP::getGatherCost(ArrayRef<Value *> VL, bool ForPoisonSrc,
15727
15727
Type *ScalarTy) const {
15728
15728
const unsigned VF = VL.size();
15729
15729
auto *VecTy = getWidenedType(ScalarTy, VF);
15730
- bool DuplicateNonConst = false;
15731
15730
// Find the cost of inserting/extracting values from the vector.
15732
15731
// Check if the same elements are inserted several times and count them as
15733
15732
// shuffle candidates.
15734
- APInt ShuffledElements = APInt::getZero(VF);
15735
15733
APInt DemandedElements = APInt::getZero(VF);
15736
- DenseMap<Value *, unsigned> UniqueElements;
15737
15734
constexpr TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
15738
15735
InstructionCost Cost;
15739
15736
auto EstimateInsertCost = [&](unsigned I, Value *V) {
@@ -15742,32 +15739,18 @@ InstructionCost BoUpSLP::getGatherCost(ArrayRef<Value *> VL, bool ForPoisonSrc,
15742
15739
Cost += TTI->getCastInstrCost(Instruction::Trunc, ScalarTy, V->getType(),
15743
15740
TTI::CastContextHint::None, CostKind);
15744
15741
};
15745
- SmallVector<int> ShuffleMask(VF, PoisonMaskElem);
15746
15742
SmallVector<int> ConstantShuffleMask(VF, PoisonMaskElem);
15747
15743
std::iota(ConstantShuffleMask.begin(), ConstantShuffleMask.end(), 0);
15748
15744
for (auto [I, V] : enumerate(VL)) {
15749
15745
// No need to shuffle duplicates for constants.
15750
- if ((ForPoisonSrc && isConstant(V)) || isa<UndefValue>(V)) {
15751
- ShuffledElements.setBit(I);
15752
- ShuffleMask[I] = isa<PoisonValue>(V) ? PoisonMaskElem : I;
15746
+ if ((ForPoisonSrc && isConstant(V)) || isa<UndefValue>(V))
15753
15747
continue;
15754
- }
15755
15748
15756
15749
if (isConstant(V)) {
15757
15750
ConstantShuffleMask[I] = I + VF;
15758
- ShuffleMask[I] = I;
15759
- continue;
15760
- }
15761
- auto Res = UniqueElements.try_emplace(V, I);
15762
- if (Res.second) {
15763
- EstimateInsertCost(I, V);
15764
- ShuffleMask[I] = I;
15765
15751
continue;
15766
15752
}
15767
-
15768
- DuplicateNonConst = true;
15769
- ShuffledElements.setBit(I);
15770
- ShuffleMask[I] = Res.first->second;
15753
+ EstimateInsertCost(I, V);
15771
15754
}
15772
15755
// FIXME: add a cost for constant vector materialization.
15773
15756
bool IsAnyNonUndefConst =
@@ -15776,15 +15759,6 @@ InstructionCost BoUpSLP::getGatherCost(ArrayRef<Value *> VL, bool ForPoisonSrc,
15776
15759
if (!ForPoisonSrc && IsAnyNonUndefConst) {
15777
15760
Cost += ::getShuffleCost(*TTI, TargetTransformInfo::SK_PermuteTwoSrc, VecTy,
15778
15761
ConstantShuffleMask);
15779
- // Update the shuffle mask for shuffling with incoming source (all elements
15780
- // are used!) or with constant subvector.
15781
- for_each(enumerate(ShuffleMask), [&](auto P) {
15782
- if ((!ForPoisonSrc && P.value() == PoisonMaskElem) ||
15783
- ConstantShuffleMask[P.index()] != PoisonMaskElem)
15784
- P.value() = P.index();
15785
- else if (P.value() != PoisonMaskElem)
15786
- P.value() += VF;
15787
- });
15788
15762
}
15789
15763
15790
15764
// 2. Insert unique non-constants.
@@ -15793,10 +15767,6 @@ InstructionCost BoUpSLP::getGatherCost(ArrayRef<Value *> VL, bool ForPoisonSrc,
15793
15767
/*Insert=*/true,
15794
15768
/*Extract=*/false, CostKind,
15795
15769
ForPoisonSrc && !IsAnyNonUndefConst, VL);
15796
- // 3. Shuffle duplicates.
15797
- if (DuplicateNonConst)
15798
- Cost += ::getShuffleCost(*TTI, TargetTransformInfo::SK_PermuteSingleSrc,
15799
- VecTy, ShuffleMask, CostKind);
15800
15770
return Cost;
15801
15771
}
15802
15772
0 commit comments