[TTI] NFC: Change getCmpSelInstrCost to return InstructionCost

This patch migrates the TTI cost interfaces to return an InstructionCost.

See this patch for the introduction of the type: https://reviews.llvm.org/D91174
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2020-November/146408.html

Reviewed By: dmgreen

Differential Revision: https://reviews.llvm.org/D100203
This commit is contained in:
Sander de Smalen 2021-01-22 21:44:23 +00:00
parent 2285dfb73f
commit db134e2428
17 changed files with 116 additions and 109 deletions

View File

@ -1118,8 +1118,8 @@ public:
/// 'I' parameter. The \p VecPred parameter can be used to indicate the select /// 'I' parameter. The \p VecPred parameter can be used to indicate the select
/// is using a compare with the specified predicate as condition. When vector /// is using a compare with the specified predicate as condition. When vector
/// types are passed, \p VecPred must be used for all lanes. /// types are passed, \p VecPred must be used for all lanes.
int getCmpSelInstrCost( InstructionCost
unsigned Opcode, Type *ValTy, Type *CondTy = nullptr, getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy = nullptr,
CmpInst::Predicate VecPred = CmpInst::BAD_ICMP_PREDICATE, CmpInst::Predicate VecPred = CmpInst::BAD_ICMP_PREDICATE,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
const Instruction *I = nullptr) const; const Instruction *I = nullptr) const;
@ -1583,7 +1583,8 @@ public:
unsigned Index) = 0; unsigned Index) = 0;
virtual int getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, virtual int getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr) = 0; const Instruction *I = nullptr) = 0;
virtual int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, virtual InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I) = 0; const Instruction *I) = 0;
@ -2059,7 +2060,7 @@ public:
const Instruction *I = nullptr) override { const Instruction *I = nullptr) override {
return Impl.getCFInstrCost(Opcode, CostKind, I); return Impl.getCFInstrCost(Opcode, CostKind, I);
} }
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I) override { const Instruction *I) override {

View File

@ -525,7 +525,7 @@ public:
return 1; return 1;
} }
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I) const { const Instruction *I) const {

View File

@ -928,7 +928,7 @@ public:
return BaseT::getCFInstrCost(Opcode, CostKind, I); return BaseT::getCFInstrCost(Opcode, CostKind, I);
} }
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr) { const Instruction *I = nullptr) {
@ -963,7 +963,7 @@ public:
unsigned Num = cast<FixedVectorType>(ValVTy)->getNumElements(); unsigned Num = cast<FixedVectorType>(ValVTy)->getNumElements();
if (CondTy) if (CondTy)
CondTy = CondTy->getScalarType(); CondTy = CondTy->getScalarType();
unsigned Cost = thisT()->getCmpSelInstrCost( InstructionCost Cost = thisT()->getCmpSelInstrCost(
Opcode, ValVTy->getScalarType(), CondTy, VecPred, CostKind, I); Opcode, ValVTy->getScalarType(), CondTy, VecPred, CostKind, I);
// Return the cost of multiple scalar invocation plus the cost of // Return the cost of multiple scalar invocation plus the cost of
@ -1346,7 +1346,7 @@ public:
: TTI::OP_None; : TTI::OP_None;
// fshl: (X << (Z % BW)) | (Y >> (BW - (Z % BW))) // fshl: (X << (Z % BW)) | (Y >> (BW - (Z % BW)))
// fshr: (X << (BW - (Z % BW))) | (Y >> (Z % BW)) // fshr: (X << (BW - (Z % BW))) | (Y >> (Z % BW))
unsigned Cost = 0; InstructionCost Cost = 0;
Cost += Cost +=
thisT()->getArithmeticInstrCost(BinaryOperator::Or, RetTy, CostKind); thisT()->getArithmeticInstrCost(BinaryOperator::Or, RetTy, CostKind);
Cost += Cost +=
@ -1612,7 +1612,7 @@ public:
// abs(X) = select(icmp(X,0),X,sub(0,X)) // abs(X) = select(icmp(X,0),X,sub(0,X))
// minmax(X,Y) = select(icmp(X,Y),X,Y) // minmax(X,Y) = select(icmp(X,Y),X,Y)
Type *CondTy = RetTy->getWithNewBitWidth(1); Type *CondTy = RetTy->getWithNewBitWidth(1);
unsigned Cost = 0; InstructionCost Cost = 0;
// TODO: Ideally getCmpSelInstrCost would accept an icmp condition code. // TODO: Ideally getCmpSelInstrCost would accept an icmp condition code.
Cost += Cost +=
thisT()->getCmpSelInstrCost(BinaryOperator::ICmp, RetTy, CondTy, thisT()->getCmpSelInstrCost(BinaryOperator::ICmp, RetTy, CondTy,
@ -1707,7 +1707,7 @@ public:
// Overflow -> (LHSSign == RHSSign) && (LHSSign != SumSign) // Overflow -> (LHSSign == RHSSign) && (LHSSign != SumSign)
// Sub: // Sub:
// Overflow -> (LHSSign != RHSSign) && (LHSSign != SumSign) // Overflow -> (LHSSign != RHSSign) && (LHSSign != SumSign)
unsigned Cost = 0; InstructionCost Cost = 0;
Cost += thisT()->getArithmeticInstrCost(Opcode, SumTy, CostKind); Cost += thisT()->getArithmeticInstrCost(Opcode, SumTy, CostKind);
Cost += 3 * thisT()->getCmpSelInstrCost( Cost += 3 * thisT()->getCmpSelInstrCost(
Instruction::ICmp, SumTy, OverflowTy, Instruction::ICmp, SumTy, OverflowTy,
@ -1727,7 +1727,7 @@ public:
? BinaryOperator::Add ? BinaryOperator::Add
: BinaryOperator::Sub; : BinaryOperator::Sub;
unsigned Cost = 0; InstructionCost Cost = 0;
Cost += thisT()->getArithmeticInstrCost(Opcode, SumTy, CostKind); Cost += thisT()->getArithmeticInstrCost(Opcode, SumTy, CostKind);
Cost += Cost +=
thisT()->getCmpSelInstrCost(BinaryOperator::ICmp, SumTy, OverflowTy, thisT()->getCmpSelInstrCost(BinaryOperator::ICmp, SumTy, OverflowTy,
@ -2015,7 +2015,7 @@ public:
"expecting floating point or integer type for min/max reduction"); "expecting floating point or integer type for min/max reduction");
CmpOpcode = Instruction::ICmp; CmpOpcode = Instruction::ICmp;
} }
unsigned MinMaxCost = 0; InstructionCost MinMaxCost = 0;
unsigned ShuffleCost = 0; unsigned ShuffleCost = 0;
std::pair<unsigned, MVT> LT = std::pair<unsigned, MVT> LT =
thisT()->getTLI()->getTypeLegalizationCost(DL, Ty); thisT()->getTLI()->getTypeLegalizationCost(DL, Ty);

View File

@ -797,14 +797,12 @@ int TargetTransformInfo::getCFInstrCost(unsigned Opcode,
return Cost; return Cost;
} }
int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, InstructionCost TargetTransformInfo::getCmpSelInstrCost(
Type *CondTy, unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, const Instruction *I) const {
TTI::TargetCostKind CostKind,
const Instruction *I) const {
assert((I == nullptr || I->getOpcode() == Opcode) && assert((I == nullptr || I->getOpcode() == Opcode) &&
"Opcode should reflect passed instruction."); "Opcode should reflect passed instruction.");
int Cost = InstructionCost Cost =
TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind, I); TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind, I);
assert(Cost >= 0 && "TTI should not produce negative costs!"); assert(Cost >= 0 && "TTI should not produce negative costs!");
return Cost; return Cost;

View File

@ -840,8 +840,9 @@ int AArch64TTIImpl::getAddressComputationCost(Type *Ty, ScalarEvolution *SE,
return 1; return 1;
} }
int AArch64TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, InstructionCost AArch64TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Type *CondTy, CmpInst::Predicate VecPred, Type *CondTy,
CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I) { const Instruction *I) {
// TODO: Handle other cost kinds. // TODO: Handle other cost kinds.
@ -1256,7 +1257,7 @@ AArch64TTIImpl::getMinMaxReductionCost(VectorType *Ty, VectorType *CondTy,
"Both vector needs to be scalable"); "Both vector needs to be scalable");
std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Ty); std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Ty);
int LegalizationCost = 0; InstructionCost LegalizationCost = 0;
if (LT.first > 1) { if (LT.first > 1) {
Type *LegalVTy = EVT(LT.second).getTypeForEVT(Ty->getContext()); Type *LegalVTy = EVT(LT.second).getTypeForEVT(Ty->getContext());
unsigned CmpOpcode = unsigned CmpOpcode =

View File

@ -167,7 +167,7 @@ public:
int getAddressComputationCost(Type *Ty, ScalarEvolution *SE, const SCEV *Ptr); int getAddressComputationCost(Type *Ty, ScalarEvolution *SE, const SCEV *Ptr);
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr); const Instruction *I = nullptr);

View File

@ -830,7 +830,8 @@ int ARMTTIImpl::getVectorInstrCost(unsigned Opcode, Type *ValTy,
return BaseT::getVectorInstrCost(Opcode, ValTy, Index); return BaseT::getVectorInstrCost(Opcode, ValTy, Index);
} }
int ARMTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, InstructionCost ARMTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I) { const Instruction *I) {
@ -902,7 +903,7 @@ int ARMTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
if (Sel != I) if (Sel != I)
return 0; return 0;
IntrinsicCostAttributes CostAttrs(IID, ValTy, {ValTy, ValTy}); IntrinsicCostAttributes CostAttrs(IID, ValTy, {ValTy, ValTy});
return *getIntrinsicInstrCost(CostAttrs, CostKind).getValue(); return getIntrinsicInstrCost(CostAttrs, CostKind);
} }
} }

View File

@ -206,7 +206,7 @@ public:
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr); const Instruction *I = nullptr);
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr); const Instruction *I = nullptr);

View File

@ -44,12 +44,12 @@ public:
return TTI::TCC_Basic; return TTI::TCC_Basic;
} }
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const llvm::Instruction *I = nullptr) { const llvm::Instruction *I = nullptr) {
if (Opcode == Instruction::Select) if (Opcode == Instruction::Select)
return SCEVCheapExpansionBudget; return SCEVCheapExpansionBudget.getValue();
return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind, return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
I); I);

View File

@ -244,7 +244,7 @@ unsigned HexagonTTIImpl::getInterleavedMemoryOpCost(
CostKind); CostKind);
} }
unsigned HexagonTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, InstructionCost HexagonTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Type *CondTy, Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,

View File

@ -134,8 +134,7 @@ public:
Align Alignment, unsigned AddressSpace, Align Alignment, unsigned AddressSpace,
TTI::TargetCostKind CostKind = TTI::TCK_SizeAndLatency, TTI::TargetCostKind CostKind = TTI::TCK_SizeAndLatency,
bool UseMaskForCond = false, bool UseMaskForGaps = false); bool UseMaskForCond = false, bool UseMaskForGaps = false);
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr); const Instruction *I = nullptr);

View File

@ -1026,16 +1026,17 @@ InstructionCost PPCTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
return Cost; return Cost;
} }
int PPCTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, InstructionCost PPCTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I) { const Instruction *I) {
int Cost = InstructionCost Cost =
BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind, I); BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind, I);
// TODO: Handle other cost kinds. // TODO: Handle other cost kinds.
if (CostKind != TTI::TCK_RecipThroughput) if (CostKind != TTI::TCK_RecipThroughput)
return Cost; return Cost;
return *vectorCostAdjustment(Cost, Opcode, ValTy, nullptr).getValue(); return vectorCostAdjustment(Cost, Opcode, ValTy, nullptr);
} }
int PPCTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) { int PPCTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) {

View File

@ -116,7 +116,7 @@ public:
const Instruction *I = nullptr); const Instruction *I = nullptr);
int getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, int getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr); const Instruction *I = nullptr);
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr); const Instruction *I = nullptr);

View File

@ -865,8 +865,9 @@ static unsigned getOperandsExtensionCost(const Instruction *I) {
return ExtCost; return ExtCost;
} }
int SystemZTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, InstructionCost SystemZTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Type *CondTy, CmpInst::Predicate VecPred, Type *CondTy,
CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I) { const Instruction *I) {
if (CostKind != TTI::TCK_RecipThroughput) if (CostKind != TTI::TCK_RecipThroughput)

View File

@ -97,7 +97,7 @@ public:
TTI::CastContextHint CCH, TTI::CastContextHint CCH,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr); const Instruction *I = nullptr);
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr); const Instruction *I = nullptr);

View File

@ -2089,7 +2089,8 @@ InstructionCost X86TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I)); BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I));
} }
int X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, InstructionCost X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I) { const Instruction *I) {
@ -3275,19 +3276,20 @@ int X86TTIImpl::getMaskedMemoryOpCost(unsigned Opcode, Type *SrcTy,
!isPowerOf2_32(NumElem)) { !isPowerOf2_32(NumElem)) {
// Scalarization // Scalarization
APInt DemandedElts = APInt::getAllOnesValue(NumElem); APInt DemandedElts = APInt::getAllOnesValue(NumElem);
int MaskSplitCost = InstructionCost MaskSplitCost =
getScalarizationOverhead(MaskTy, DemandedElts, false, true); getScalarizationOverhead(MaskTy, DemandedElts, false, true);
int ScalarCompareCost = getCmpSelInstrCost( InstructionCost ScalarCompareCost = getCmpSelInstrCost(
Instruction::ICmp, Type::getInt8Ty(SrcVTy->getContext()), nullptr, Instruction::ICmp, Type::getInt8Ty(SrcVTy->getContext()), nullptr,
CmpInst::BAD_ICMP_PREDICATE, CostKind); CmpInst::BAD_ICMP_PREDICATE, CostKind);
int BranchCost = getCFInstrCost(Instruction::Br, CostKind); InstructionCost BranchCost = getCFInstrCost(Instruction::Br, CostKind);
int MaskCmpCost = NumElem * (BranchCost + ScalarCompareCost); InstructionCost MaskCmpCost = NumElem * (BranchCost + ScalarCompareCost);
int ValueSplitCost = InstructionCost ValueSplitCost =
getScalarizationOverhead(SrcVTy, DemandedElts, IsLoad, IsStore); getScalarizationOverhead(SrcVTy, DemandedElts, IsLoad, IsStore);
int MemopCost = int MemopCost =
NumElem * BaseT::getMemoryOpCost(Opcode, SrcVTy->getScalarType(), NumElem * BaseT::getMemoryOpCost(Opcode, SrcVTy->getScalarType(),
Alignment, AddressSpace, CostKind); Alignment, AddressSpace, CostKind);
return MemopCost + ValueSplitCost + MaskSplitCost + MaskCmpCost; return *(MemopCost + ValueSplitCost + MaskSplitCost + MaskCmpCost)
.getValue();
} }
// Legalize the type. // Legalize the type.
@ -3713,10 +3715,12 @@ InstructionCost X86TTIImpl::getMinMaxCost(Type *Ty, Type *CondTy,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
// Otherwise fall back to cmp+select. // Otherwise fall back to cmp+select.
return getCmpSelInstrCost(CmpOpcode, Ty, CondTy, CmpInst::BAD_ICMP_PREDICATE, InstructionCost Result =
getCmpSelInstrCost(CmpOpcode, Ty, CondTy, CmpInst::BAD_ICMP_PREDICATE,
CostKind) + CostKind) +
getCmpSelInstrCost(Instruction::Select, Ty, CondTy, getCmpSelInstrCost(Instruction::Select, Ty, CondTy,
CmpInst::BAD_ICMP_PREDICATE, CostKind); CmpInst::BAD_ICMP_PREDICATE, CostKind);
return Result;
} }
InstructionCost InstructionCost
@ -4185,20 +4189,20 @@ int X86TTIImpl::getGSVectorCost(unsigned Opcode, Type *SrcVTy, const Value *Ptr,
/// AddressSpace - pointer[s] address space. /// AddressSpace - pointer[s] address space.
/// ///
/// FIXME: Add TargetCostKind support. /// FIXME: Add TargetCostKind support.
int X86TTIImpl::getGSScalarCost(unsigned Opcode, Type *SrcVTy, InstructionCost X86TTIImpl::getGSScalarCost(unsigned Opcode, Type *SrcVTy,
bool VariableMask, Align Alignment, bool VariableMask, Align Alignment,
unsigned AddressSpace) { unsigned AddressSpace) {
unsigned VF = cast<FixedVectorType>(SrcVTy)->getNumElements(); unsigned VF = cast<FixedVectorType>(SrcVTy)->getNumElements();
APInt DemandedElts = APInt::getAllOnesValue(VF); APInt DemandedElts = APInt::getAllOnesValue(VF);
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
int MaskUnpackCost = 0; InstructionCost MaskUnpackCost = 0;
if (VariableMask) { if (VariableMask) {
auto *MaskTy = auto *MaskTy =
FixedVectorType::get(Type::getInt1Ty(SrcVTy->getContext()), VF); FixedVectorType::get(Type::getInt1Ty(SrcVTy->getContext()), VF);
MaskUnpackCost = MaskUnpackCost =
getScalarizationOverhead(MaskTy, DemandedElts, false, true); getScalarizationOverhead(MaskTy, DemandedElts, false, true);
int ScalarCompareCost = getCmpSelInstrCost( InstructionCost ScalarCompareCost = getCmpSelInstrCost(
Instruction::ICmp, Type::getInt1Ty(SrcVTy->getContext()), nullptr, Instruction::ICmp, Type::getInt1Ty(SrcVTy->getContext()), nullptr,
CmpInst::BAD_ICMP_PREDICATE, CostKind); CmpInst::BAD_ICMP_PREDICATE, CostKind);
int BranchCost = getCFInstrCost(Instruction::Br, CostKind); int BranchCost = getCFInstrCost(Instruction::Br, CostKind);

View File

@ -133,7 +133,7 @@ public:
TTI::CastContextHint CCH, TTI::CastContextHint CCH,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr); const Instruction *I = nullptr);
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr); const Instruction *I = nullptr);
@ -236,8 +236,9 @@ public:
bool enableInterleavedAccessVectorization(); bool enableInterleavedAccessVectorization();
private: private:
int getGSScalarCost(unsigned Opcode, Type *DataTy, bool VariableMask, InstructionCost getGSScalarCost(unsigned Opcode, Type *DataTy,
Align Alignment, unsigned AddressSpace); bool VariableMask, Align Alignment,
unsigned AddressSpace);
int getGSVectorCost(unsigned Opcode, Type *DataTy, const Value *Ptr, int getGSVectorCost(unsigned Opcode, Type *DataTy, const Value *Ptr,
Align Alignment, unsigned AddressSpace); Align Alignment, unsigned AddressSpace);