Skip to content

Commit 9134ff1

Browse files
committed
Revert TTI changes, customize getScalarizationOverhead instead
1 parent 7bf8d93 commit 9134ff1

File tree

6 files changed

+31
-53
lines changed

6 files changed

+31
-53
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,12 +1482,6 @@ class TargetTransformInfo {
14821482
InstructionCost getInsertExtractValueCost(unsigned Opcode,
14831483
TTI::TargetCostKind CostKind) const;
14841484

1485-
/// \return The cost of ISD::BUILD_VECTOR, or nullopt if the cost should be
1486-
/// inferred from insert element and shuffle ops.
1487-
std::optional<InstructionCost>
1488-
getBuildVectorCost(VectorType *VecTy, ArrayRef<Value *> Operands,
1489-
TargetCostKind CostKind) const;
1490-
14911485
/// \return The cost of replication shuffle of \p VF elements typed \p EltTy
14921486
/// \p ReplicationFactor times.
14931487
///
@@ -2225,10 +2219,6 @@ class TargetTransformInfo::Concept {
22252219
TTI::TargetCostKind CostKind,
22262220
unsigned Index) = 0;
22272221

2228-
virtual std::optional<InstructionCost>
2229-
getBuildVectorCost(VectorType *VecTy, ArrayRef<Value *> Operands,
2230-
TargetCostKind CostKind) = 0;
2231-
22322222
virtual InstructionCost
22332223
getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF,
22342224
const APInt &DemandedDstElts,
@@ -2957,12 +2947,6 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
29572947
unsigned Index) override {
29582948
return Impl.getVectorInstrCost(I, Val, CostKind, Index);
29592949
}
2960-
std::optional<InstructionCost>
2961-
getBuildVectorCost(VectorType *VecTy, ArrayRef<Value *> Operands,
2962-
TTI::TargetCostKind CostKind) override {
2963-
return Impl.getBuildVectorCost(VecTy, Operands, CostKind);
2964-
}
2965-
29662950
InstructionCost
29672951
getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF,
29682952
const APInt &DemandedDstElts,

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -741,12 +741,6 @@ class TargetTransformInfoImplBase {
741741
return 1;
742742
}
743743

744-
std::optional<InstructionCost>
745-
getBuildVectorCost(VectorType *Val, ArrayRef<Value *> Operands,
746-
TTI::TargetCostKind CostKind) const {
747-
return std::nullopt;
748-
}
749-
750744
unsigned getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF,
751745
const APInt &DemandedDstElts,
752746
TTI::TargetCostKind CostKind) {

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,12 +1432,6 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
14321432
Op1);
14331433
}
14341434

1435-
std::optional<InstructionCost>
1436-
getBuildVectorCost(VectorType *VecTy, ArrayRef<Value *> Operands,
1437-
TTI::TargetCostKind CostKind) {
1438-
return std::nullopt;
1439-
}
1440-
14411435
InstructionCost getReplicationShuffleCost(Type *EltTy, int ReplicationFactor,
14421436
int VF,
14431437
const APInt &DemandedDstElts,

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,13 +1124,6 @@ InstructionCost TargetTransformInfo::getInsertExtractValueCost(
11241124
return Cost;
11251125
}
11261126

1127-
std::optional<InstructionCost>
1128-
TargetTransformInfo::getBuildVectorCost(VectorType *VecTy,
1129-
ArrayRef<Value *> Operands,
1130-
TargetCostKind CostKind) const {
1131-
return TTIImpl->getBuildVectorCost(VecTy, Operands, CostKind);
1132-
}
1133-
11341127
InstructionCost TargetTransformInfo::getReplicationShuffleCost(
11351128
Type *EltTy, int ReplicationFactor, int VF, const APInt &DemandedDstElts,
11361129
TTI::TargetCostKind CostKind) const {

llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.h

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,40 @@ class NVPTXTTIImpl : public BasicTTIImplBase<NVPTXTTIImpl> {
105105
TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
106106
ArrayRef<const Value *> Args = {}, const Instruction *CxtI = nullptr);
107107

108-
std::optional<InstructionCost>
109-
getBuildVectorCost(VectorType *VecTy, ArrayRef<Value *> Operands,
110-
TTI::TargetCostKind CostKind) {
111-
if (CostKind != TTI::TCK_RecipThroughput)
112-
return std::nullopt;
113-
auto VT = getTLI()->getValueType(DL, VecTy);
114-
if (all_of(Operands, [](Value *Op) { return isa<Constant>(Op); }))
115-
return TTI::TCC_Free;
116-
if (Isv2x16VT(VT))
117-
return 1; // Single vector mov
118-
if (VT == MVT::v4i8) {
108+
InstructionCost getScalarizationOverhead(VectorType *InTy,
109+
const APInt &DemandedElts,
110+
bool Insert, bool Extract,
111+
TTI::TargetCostKind CostKind,
112+
ArrayRef<Value *> VL = {}) {
113+
if (!InTy->getElementCount().isFixed())
114+
return InstructionCost::getInvalid();
115+
116+
auto VT = getTLI()->getValueType(DL, InTy);
117+
auto NumElements = InTy->getElementCount().getFixedValue();
118+
InstructionCost Cost = 0;
119+
if (Insert && !VL.empty()) {
120+
bool AllConstant = all_of(seq(NumElements), [&](int Idx) {
121+
return !DemandedElts[Idx] || isa<Constant>(VL[Idx]);
122+
});
123+
if (AllConstant) {
124+
Cost += TTI::TCC_Free;
125+
Insert = false;
126+
}
127+
}
128+
if (Insert && Isv2x16VT(VT)) {
129+
// Can be built in a single mov
130+
Cost += 1;
131+
Insert = false;
132+
}
133+
if (Insert && VT == MVT::v4i8) {
119134
InstructionCost Cost = 3; // 3 x PRMT
120-
for (auto *Op : Operands)
121-
if (!isa<Constant>(Op))
135+
for (auto Idx : seq(NumElements))
136+
if (DemandedElts[Idx])
122137
Cost += 1; // zext operand to i32
123-
return Cost;
138+
Insert = false;
124139
}
125-
return std::nullopt;
140+
return Cost + BaseT::getScalarizationOverhead(InTy, DemandedElts, Insert,
141+
Extract, CostKind, VL);
126142
}
127143

128144
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11096,9 +11096,6 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
1109611096
if ((!Root && allConstant(VL)) || all_of(VL, IsaPred<UndefValue>))
1109711097
return TTI::TCC_Free;
1109811098
auto *VecTy = getWidenedType(ScalarTy, VL.size());
11099-
if (auto Cost = TTI.getBuildVectorCost(VecTy, VL, CostKind);
11100-
Cost.has_value())
11101-
return *Cost;
1110211099
InstructionCost GatherCost = 0;
1110311100
SmallVector<Value *> Gathers(VL);
1110411101
if (!Root && isSplat(VL)) {

0 commit comments

Comments
 (0)