Skip to content

Commit 917d375

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 734660b commit 917d375

File tree

7 files changed

+29
-26
lines changed

7 files changed

+29
-26
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
@@ -696,8 +696,8 @@ class TargetTransformInfoImplBase {
696696
}
697697

698698
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
699-
VectorType *VecTy,
700-
unsigned Index) const {
699+
VectorType *VecTy, unsigned Index,
700+
TTI::TargetCostKind CostKind) const {
701701
return 1;
702702
}
703703

llvm/include/llvm/CodeGen/BasicTTIImpl.h

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

13351335
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
1336-
VectorType *VecTy, unsigned Index) {
1337-
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
1336+
VectorType *VecTy, unsigned Index,
1337+
TTI::TargetCostKind CostKind) {
13381338
return thisT()->getVectorInstrCost(Instruction::ExtractElement, VecTy,
13391339
CostKind, Index, nullptr, nullptr) +
13401340
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
@@ -3556,10 +3556,10 @@ InstructionCost AArch64TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
35563556
BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I));
35573557
}
35583558

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

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

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

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
189189
const Instruction *I = nullptr);
190190

191191
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
192-
VectorType *VecTy, unsigned Index);
192+
VectorType *VecTy, unsigned Index,
193+
TTI::TargetCostKind CostKind);
193194

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

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5451,7 +5451,7 @@ static InstructionCost getExtractWithExtendCost(
54515451
TTI.getCastInstrCost(Opcode, Dst, SubTp, TTI::CastContextHint::None,
54525452
CostKind);
54535453
}
5454-
return TTI.getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
5454+
return TTI.getExtractWithExtendCost(Opcode, Dst, VecTy, Index, CostKind);
54555455
}
54565456

54575457
/// Correctly creates insert_subvector, checking that the index is multiple of
@@ -12045,9 +12045,9 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
1204512045
all_of(Ext->users(), IsaPred<GetElementPtrInst>)) {
1204612046
// Use getExtractWithExtendCost() to calculate the cost of
1204712047
// extractelement/ext pair.
12048-
Cost -=
12049-
TTI.getExtractWithExtendCost(Ext->getOpcode(), Ext->getType(),
12050-
EE->getVectorOperandType(), Idx);
12048+
Cost -= TTI.getExtractWithExtendCost(
12049+
Ext->getOpcode(), Ext->getType(), EE->getVectorOperandType(),
12050+
Idx, CostKind);
1205112051
// Add back the cost of s|zext which is subtracted separately.
1205212052
Cost += TTI.getCastInstrCost(
1205312053
Ext->getOpcode(), Ext->getType(), EE->getType(),
@@ -12668,7 +12668,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
1266812668
// Use getExtractWithExtendCost() to calculate the cost of
1266912669
// extractelement/ext pair.
1267012670
InstructionCost Cost = TTI->getExtractWithExtendCost(
12671-
Ext->getOpcode(), Ext->getType(), SrcVecTy, *getExtractIndex(I));
12671+
Ext->getOpcode(), Ext->getType(), SrcVecTy, *getExtractIndex(I),
12672+
CostKind);
1267212673
// Subtract the cost of s|zext which is subtracted separately.
1267312674
Cost -= TTI->getCastInstrCost(
1267412675
Ext->getOpcode(), Ext->getType(), I->getType(),

0 commit comments

Comments
 (0)