Skip to content

Commit ff496f6

Browse files
committed
[CostModel] Plumb CostKind into getExtractWithExtendCost
This will likely not affect much with the uses of the function, but if we have getExtractWithExtendCost we can plumb CostKind through it in the same way as other functions.
1 parent 8639b36 commit ff496f6

File tree

7 files changed

+29
-28
lines changed

7 files changed

+29
-28
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 10 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.
@@ -2196,9 +2196,9 @@ class TargetTransformInfo::Concept {
21962196
Type *Src, CastContextHint CCH,
21972197
TTI::TargetCostKind CostKind,
21982198
const Instruction *I) = 0;
2199-
virtual InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
2200-
VectorType *VecTy,
2201-
unsigned Index) = 0;
2199+
virtual InstructionCost
2200+
getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy,
2201+
unsigned Index, TTI::TargetCostKind CostKind) = 0;
22022202
virtual InstructionCost getCFInstrCost(unsigned Opcode,
22032203
TTI::TargetCostKind CostKind,
22042204
const Instruction *I = nullptr) = 0;
@@ -2919,10 +2919,11 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
29192919
const Instruction *I) override {
29202920
return Impl.getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
29212921
}
2922-
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
2923-
VectorType *VecTy,
2924-
unsigned Index) override {
2925-
return Impl.getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
2922+
InstructionCost
2923+
getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy,
2924+
unsigned Index,
2925+
TTI::TargetCostKind CostKind) override {
2926+
return Impl.getExtractWithExtendCost(Opcode, Dst, VecTy, Index, CostKind);
29262927
}
29272928
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind,
29282929
const Instruction *I = nullptr) override {

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,8 @@ class TargetTransformInfoImplBase {
698698
}
699699

700700
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
701-
VectorType *VecTy,
702-
unsigned Index) const {
701+
VectorType *VecTy, unsigned Index,
702+
TTI::TargetCostKind CostKind) const {
703703
return 1;
704704
}
705705

llvm/include/llvm/CodeGen/BasicTTIImpl.h

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

13371337
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
1338-
VectorType *VecTy,
1339-
unsigned Index) const {
1340-
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
1338+
VectorType *VecTy, unsigned Index,
1339+
TTI::TargetCostKind CostKind) const {
13411340
return thisT()->getVectorInstrCost(Instruction::ExtractElement, VecTy,
13421341
CostKind, Index, nullptr, nullptr) +
13431342
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)