Skip to content

Commit d20604e

Browse files
authored
[CostModel] Plumb CostKind into getExtractWithExtendCost (#135523)
This will likely not affect much with the current uses of the function, but if we have getExtractWithExtendCost we can plumb CostKind through it in the same way as other costmodel functions.
1 parent cfeaa39 commit d20604e

File tree

7 files changed

+30
-28
lines changed

7 files changed

+30
-28
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,8 +1420,8 @@ class TargetTransformInfo {
14201420
/// \return The expected cost of a sign- or zero-extended vector extract. Use
14211421
/// Index = -1 to indicate that there is no information about the index value.
14221422
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
1423-
VectorType *VecTy,
1424-
unsigned Index) const;
1423+
VectorType *VecTy, unsigned Index,
1424+
TTI::TargetCostKind CostKind) const;
14251425

14261426
/// \return The expected cost of control-flow related instructions such as
14271427
/// Phi, Ret, Br, Switch.
@@ -2210,9 +2210,10 @@ class TargetTransformInfo::Concept {
22102210
Type *Src, CastContextHint CCH,
22112211
TTI::TargetCostKind CostKind,
22122212
const Instruction *I) const = 0;
2213-
virtual InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
2214-
VectorType *VecTy,
2215-
unsigned Index) const = 0;
2213+
virtual InstructionCost
2214+
getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy,
2215+
unsigned Index,
2216+
TTI::TargetCostKind CostKind) const = 0;
22162217
virtual InstructionCost
22172218
getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind,
22182219
const Instruction *I = nullptr) const = 0;
@@ -2947,10 +2948,11 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
29472948
const Instruction *I) const override {
29482949
return Impl.getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
29492950
}
2950-
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
2951-
VectorType *VecTy,
2952-
unsigned Index) const override {
2953-
return Impl.getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
2951+
InstructionCost
2952+
getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy,
2953+
unsigned Index,
2954+
TTI::TargetCostKind CostKind) const override {
2955+
return Impl.getExtractWithExtendCost(Opcode, Dst, VecTy, Index, CostKind);
29542956
}
29552957
InstructionCost
29562958
getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind,

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,8 @@ class TargetTransformInfoImplBase {
700700
}
701701

702702
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
703-
VectorType *VecTy,
704-
unsigned Index) const {
703+
VectorType *VecTy, unsigned Index,
704+
TTI::TargetCostKind CostKind) const {
705705
return 1;
706706
}
707707

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,9 +1333,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
13331333
}
13341334

13351335
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
1336-
VectorType *VecTy,
1337-
unsigned Index) const {
1338-
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
1336+
VectorType *VecTy, unsigned Index,
1337+
TTI::TargetCostKind CostKind) const {
13391338
return thisT()->getVectorInstrCost(Instruction::ExtractElement, VecTy,
13401339
CostKind, Index, nullptr, nullptr) +
13411340
thisT()->getCastInstrCost(Opcode, Dst, VecTy->getElementType(),

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,9 +1049,10 @@ InstructionCost TargetTransformInfo::getCastInstrCost(
10491049
}
10501050

10511051
InstructionCost TargetTransformInfo::getExtractWithExtendCost(
1052-
unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index) const {
1052+
unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index,
1053+
TTI::TargetCostKind CostKind) const {
10531054
InstructionCost Cost =
1054-
TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
1055+
TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index, CostKind);
10551056
assert(Cost >= 0 && "TTI should not produce negative costs!");
10561057
return Cost;
10571058
}

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,10 +3557,10 @@ InstructionCost AArch64TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
35573557
BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I));
35583558
}
35593559

3560-
InstructionCost AArch64TTIImpl::getExtractWithExtendCost(unsigned Opcode,
3561-
Type *Dst,
3562-
VectorType *VecTy,
3563-
unsigned Index) const {
3560+
InstructionCost
3561+
AArch64TTIImpl::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
3562+
VectorType *VecTy, unsigned Index,
3563+
TTI::TargetCostKind CostKind) const {
35643564

35653565
// Make sure we were given a valid extend opcode.
35663566
assert((Opcode == Instruction::SExt || Opcode == Instruction::ZExt) &&
@@ -3575,7 +3575,6 @@ InstructionCost AArch64TTIImpl::getExtractWithExtendCost(unsigned Opcode,
35753575

35763576
// Get the cost for the extract. We compute the cost (if any) for the extend
35773577
// below.
3578-
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
35793578
InstructionCost Cost = getVectorInstrCost(Instruction::ExtractElement, VecTy,
35803579
CostKind, Index, nullptr, nullptr);
35813580

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
192192
const Instruction *I = nullptr) const;
193193

194194
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
195-
VectorType *VecTy,
196-
unsigned Index) const;
195+
VectorType *VecTy, unsigned Index,
196+
TTI::TargetCostKind CostKind) const;
197197

198198
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind,
199199
const Instruction *I = nullptr) const;

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5793,7 +5793,7 @@ static InstructionCost getExtractWithExtendCost(
57935793
TTI.getCastInstrCost(Opcode, Dst, SubTp, TTI::CastContextHint::None,
57945794
CostKind);
57955795
}
5796-
return TTI.getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
5796+
return TTI.getExtractWithExtendCost(Opcode, Dst, VecTy, Index, CostKind);
57975797
}
57985798

57995799
/// Correctly creates insert_subvector, checking that the index is multiple of
@@ -12412,9 +12412,9 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
1241212412
all_of(Ext->users(), IsaPred<GetElementPtrInst>)) {
1241312413
// Use getExtractWithExtendCost() to calculate the cost of
1241412414
// extractelement/ext pair.
12415-
Cost -=
12416-
TTI.getExtractWithExtendCost(Ext->getOpcode(), Ext->getType(),
12417-
EE->getVectorOperandType(), Idx);
12415+
Cost -= TTI.getExtractWithExtendCost(
12416+
Ext->getOpcode(), Ext->getType(), EE->getVectorOperandType(),
12417+
Idx, CostKind);
1241812418
// Add back the cost of s|zext which is subtracted separately.
1241912419
Cost += TTI.getCastInstrCost(
1242012420
Ext->getOpcode(), Ext->getType(), EE->getType(),
@@ -13035,7 +13035,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
1303513035
// Use getExtractWithExtendCost() to calculate the cost of
1303613036
// extractelement/ext pair.
1303713037
InstructionCost Cost = TTI->getExtractWithExtendCost(
13038-
Ext->getOpcode(), Ext->getType(), SrcVecTy, *getExtractIndex(I));
13038+
Ext->getOpcode(), Ext->getType(), SrcVecTy, *getExtractIndex(I),
13039+
CostKind);
1303913040
// Subtract the cost of s|zext which is subtracted separately.
1304013041
Cost -= TTI->getCastInstrCost(
1304113042
Ext->getOpcode(), Ext->getType(), I->getType(),

0 commit comments

Comments
 (0)