[TTI] Use OperandValueInfo in getArithmeticInstrCost implementation [NFC]

This change completes the process of replacing OperandValueKind and OperandValueProperties which were previously passed independently in this API with a single container class which contains both.

This is the change which motivated the whole sequence which preceeded it.  In an original spike version of this change, I'd noticed a nasty bug: I'd changed the signature without changing names, and as result, we silently passed additional information through a callsite which previously dropped the power-of-two fact.  This might be harmless in most cases, but at least a couple clearly dependend for correctness on not passing that property through.

I did my best to split off prior changes which reduced the scope of this one, and which made it possible to use compiler assistance.  For instance, every parameter which changes type in this change also changes name.  This was intentional to make sure that every call site possible effected must show up in the diff.  This let me audit each one closely.
This commit is contained in:
Philip Reames 2022-08-20 08:07:28 -07:00 committed by Philip Reames
parent af29db64b2
commit 104fa367ee
24 changed files with 162 additions and 248 deletions

View File

@ -916,6 +916,10 @@ public:
bool isPowerOf2() const { bool isPowerOf2() const {
return Properties == OP_PowerOf2; return Properties == OP_PowerOf2;
} }
OperandValueInfo getNoProps() const {
return {Kind, OP_None};
}
}; };
/// \return the number of registers in the target-provided register class. /// \return the number of registers in the target-provided register class.
@ -1729,12 +1733,7 @@ public:
virtual unsigned getMaxInterleaveFactor(unsigned VF) = 0; virtual unsigned getMaxInterleaveFactor(unsigned VF) = 0;
virtual InstructionCost getArithmeticInstrCost( virtual InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
OperandValueKind Opd1Info, OperandValueKind Opd2Info, OperandValueInfo Opd1Info, OperandValueInfo Opd2Info,
OperandValueProperties Opd1PropInfo, OperandValueProperties Opd2PropInfo,
ArrayRef<const Value *> Args, const Instruction *CxtI = nullptr) = 0;
virtual InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
OperandValueInfo Op1Info, OperandValueInfo Op2Info,
ArrayRef<const Value *> Args, const Instruction *CxtI = nullptr) = 0; ArrayRef<const Value *> Args, const Instruction *CxtI = nullptr) = 0;
virtual InstructionCost getShuffleCost(ShuffleKind Kind, VectorType *Tp, virtual InstructionCost getShuffleCost(ShuffleKind Kind, VectorType *Tp,
@ -2282,24 +2281,12 @@ public:
BlockFrequencyInfo *BFI) override { BlockFrequencyInfo *BFI) override {
return Impl.getEstimatedNumberOfCaseClusters(SI, JTSize, PSI, BFI); return Impl.getEstimatedNumberOfCaseClusters(SI, JTSize, PSI, BFI);
} }
InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
OperandValueKind Opd1Info, OperandValueKind Opd2Info,
OperandValueProperties Opd1PropInfo, OperandValueProperties Opd2PropInfo,
ArrayRef<const Value *> Args,
const Instruction *CxtI = nullptr) override {
return Impl.getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, Opd2Info,
Opd1PropInfo, Opd2PropInfo, Args, CxtI);
}
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
OperandValueInfo Opd1Info, OperandValueInfo Opd2Info, OperandValueInfo Opd1Info, OperandValueInfo Opd2Info,
ArrayRef<const Value *> Args, ArrayRef<const Value *> Args,
const Instruction *CxtI = nullptr) override { const Instruction *CxtI = nullptr) override {
return Impl.getArithmeticInstrCost(Opcode, Ty, CostKind, return Impl.getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, Opd2Info,
Opd1Info.Kind, Opd2Info.Kind,
Opd1Info.Properties, Opd2Info.Properties,
Args, CxtI); Args, CxtI);
} }

View File

@ -486,9 +486,8 @@ public:
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info, TTI::OperandValueInfo Opd1Info, TTI::OperandValueInfo Opd2Info,
TTI::OperandValueProperties Opd1PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI = nullptr) const { const Instruction *CxtI = nullptr) const {
// FIXME: A number of transformation tests seem to require these values // FIXME: A number of transformation tests seem to require these values
// which seems a little odd for how arbitary there are. // which seems a little odd for how arbitary there are.
@ -1074,18 +1073,13 @@ public:
case Instruction::Or: case Instruction::Or:
case Instruction::Xor: case Instruction::Xor:
case Instruction::FNeg: { case Instruction::FNeg: {
const auto [Op1VK, Op1VP] = TTI::getOperandInfo(U->getOperand(0)); const TTI::OperandValueInfo Op1Info = TTI::getOperandInfo(U->getOperand(0));
TTI::OperandValueProperties Op2VP = TTI::OP_None; TTI::OperandValueInfo Op2Info;
TTI::OperandValueKind Op2VK = TTI::OK_AnyValue; if (Opcode != Instruction::FNeg)
if (Opcode != Instruction::FNeg) { Op2Info = TTI::getOperandInfo(U->getOperand(1));
auto Info = TTI::getOperandInfo(U->getOperand(1));
Op2VK = Info.Kind;
Op2VP = Info.Properties;
}
SmallVector<const Value *, 2> Operands(U->operand_values()); SmallVector<const Value *, 2> Operands(U->operand_values());
return TargetTTI->getArithmeticInstrCost(Opcode, Ty, CostKind, return TargetTTI->getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
Op1VK, Op2VK, Op2Info, Operands, I);
Op1VP, Op2VP, Operands, I);
} }
case Instruction::IntToPtr: case Instruction::IntToPtr:
case Instruction::PtrToInt: case Instruction::PtrToInt:
@ -1140,15 +1134,15 @@ public:
match(U, m_LogicalOr(m_Value(Op0), m_Value(Op1)))) { match(U, m_LogicalOr(m_Value(Op0), m_Value(Op1)))) {
// select x, y, false --> x & y // select x, y, false --> x & y
// select x, true, y --> x | y // select x, true, y --> x | y
const auto [Op1VK, Op1VP] = TTI::getOperandInfo(Op0); const auto Op1Info = TTI::getOperandInfo(Op0);
const auto [Op2VK, Op2VP] = TTI::getOperandInfo(Op1); const auto Op2Info = TTI::getOperandInfo(Op1);
assert(Op0->getType()->getScalarSizeInBits() == 1 && assert(Op0->getType()->getScalarSizeInBits() == 1 &&
Op1->getType()->getScalarSizeInBits() == 1); Op1->getType()->getScalarSizeInBits() == 1);
SmallVector<const Value *, 2> Operands{Op0, Op1}; SmallVector<const Value *, 2> Operands{Op0, Op1};
return TargetTTI->getArithmeticInstrCost( return TargetTTI->getArithmeticInstrCost(
match(U, m_LogicalOr()) ? Instruction::Or : Instruction::And, Ty, match(U, m_LogicalOr()) ? Instruction::Or : Instruction::And, Ty,
CostKind, Op1VK, Op2VK, Op1VP, Op2VP, Operands, I); CostKind, Op1Info, Op2Info, Operands, I);
} }
Type *CondTy = U->getOperand(0)->getType(); Type *CondTy = U->getOperand(0)->getType();
return TargetTTI->getCmpSelInstrCost(Opcode, U->getType(), CondTy, return TargetTTI->getCmpSelInstrCost(Opcode, U->getType(), CondTy,

View File

@ -818,10 +818,8 @@ public:
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueInfo Opd1Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, TTI::OperandValueInfo Opd2Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
ArrayRef<const Value *> Args = ArrayRef<const Value *>(), ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
const Instruction *CxtI = nullptr) { const Instruction *CxtI = nullptr) {
// Check if any of the operands are vector operands. // Check if any of the operands are vector operands.
@ -833,7 +831,6 @@ public:
if (CostKind != TTI::TCK_RecipThroughput) if (CostKind != TTI::TCK_RecipThroughput)
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind,
Opd1Info, Opd2Info, Opd1Info, Opd2Info,
Opd1PropInfo, Opd2PropInfo,
Args, CxtI); Args, CxtI);
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty); std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
@ -866,8 +863,7 @@ public:
LT.second)) { LT.second)) {
unsigned DivOpc = IsSigned ? Instruction::SDiv : Instruction::UDiv; unsigned DivOpc = IsSigned ? Instruction::SDiv : Instruction::UDiv;
InstructionCost DivCost = thisT()->getArithmeticInstrCost( InstructionCost DivCost = thisT()->getArithmeticInstrCost(
DivOpc, Ty, CostKind, Opd1Info, Opd2Info, Opd1PropInfo, DivOpc, Ty, CostKind, Opd1Info, Opd2Info);
Opd2PropInfo);
InstructionCost MulCost = InstructionCost MulCost =
thisT()->getArithmeticInstrCost(Instruction::Mul, Ty, CostKind); thisT()->getArithmeticInstrCost(Instruction::Mul, Ty, CostKind);
InstructionCost SubCost = InstructionCost SubCost =
@ -886,7 +882,7 @@ public:
if (auto *VTy = dyn_cast<FixedVectorType>(Ty)) { if (auto *VTy = dyn_cast<FixedVectorType>(Ty)) {
InstructionCost Cost = thisT()->getArithmeticInstrCost( InstructionCost Cost = thisT()->getArithmeticInstrCost(
Opcode, VTy->getScalarType(), CostKind, Opd1Info, Opd2Info, Opcode, VTy->getScalarType(), CostKind, Opd1Info, Opd2Info,
Opd1PropInfo, Opd2PropInfo, Args, CxtI); Args, CxtI);
// Return the cost of multiple scalar invocation plus the cost of // Return the cost of multiple scalar invocation plus the cost of
// inserting and extracting the values. // inserting and extracting the values.
SmallVector<Type *> Tys(Args.size(), Ty); SmallVector<Type *> Tys(Args.size(), Ty);
@ -1565,13 +1561,14 @@ public:
const Value *X = Args[0]; const Value *X = Args[0];
const Value *Y = Args[1]; const Value *Y = Args[1];
const Value *Z = Args[2]; const Value *Z = Args[2];
const auto [OpKindX, OpPropsX] = TTI::getOperandInfo(X); const TTI::OperandValueInfo OpInfoX = TTI::getOperandInfo(X);
const auto [OpKindY, OpPropsY] = TTI::getOperandInfo(Y); const TTI::OperandValueInfo OpInfoY = TTI::getOperandInfo(Y);
const auto [OpKindZ, OpPropsZ] = TTI::getOperandInfo(Z); const TTI::OperandValueInfo OpInfoZ = TTI::getOperandInfo(Z);
TTI::OperandValueKind OpKindBW = TTI::OK_UniformConstantValue; const TTI::OperandValueInfo OpInfoBW =
TTI::OperandValueProperties OpPropsBW = {TTI::OK_UniformConstantValue,
isPowerOf2_32(RetTy->getScalarSizeInBits()) ? TTI::OP_PowerOf2 isPowerOf2_32(RetTy->getScalarSizeInBits()) ? TTI::OP_PowerOf2
: 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))
InstructionCost Cost = 0; InstructionCost Cost = 0;
@ -1580,15 +1577,15 @@ public:
Cost += Cost +=
thisT()->getArithmeticInstrCost(BinaryOperator::Sub, RetTy, CostKind); thisT()->getArithmeticInstrCost(BinaryOperator::Sub, RetTy, CostKind);
Cost += thisT()->getArithmeticInstrCost( Cost += thisT()->getArithmeticInstrCost(
BinaryOperator::Shl, RetTy, CostKind, OpKindX, OpKindZ, OpPropsX); BinaryOperator::Shl, RetTy, CostKind, OpInfoX,
{OpInfoZ.Kind, TTI::OP_None});
Cost += thisT()->getArithmeticInstrCost( Cost += thisT()->getArithmeticInstrCost(
BinaryOperator::LShr, RetTy, CostKind, OpKindY, OpKindZ, OpPropsY); BinaryOperator::LShr, RetTy, CostKind, OpInfoY,
{OpInfoZ.Kind, TTI::OP_None});
// Non-constant shift amounts requires a modulo. // Non-constant shift amounts requires a modulo.
if (OpKindZ != TTI::OK_UniformConstantValue && if (!OpInfoZ.isConstant())
OpKindZ != TTI::OK_NonUniformConstantValue)
Cost += thisT()->getArithmeticInstrCost(BinaryOperator::URem, RetTy, Cost += thisT()->getArithmeticInstrCost(BinaryOperator::URem, RetTy,
CostKind, OpKindZ, OpKindBW, CostKind, OpInfoZ, OpInfoBW);
OpPropsZ, OpPropsBW);
// For non-rotates (X != Y) we must add shift-by-zero handling costs. // For non-rotates (X != Y) we must add shift-by-zero handling costs.
if (X != Y) { if (X != Y) {
Type *CondTy = RetTy->getWithNewBitWidth(1); Type *CondTy = RetTy->getWithNewBitWidth(1);
@ -1855,7 +1852,7 @@ public:
Pred, CostKind); Pred, CostKind);
// TODO: Should we add an OperandValueProperties::OP_Zero property? // TODO: Should we add an OperandValueProperties::OP_Zero property?
Cost += thisT()->getArithmeticInstrCost( Cost += thisT()->getArithmeticInstrCost(
BinaryOperator::Sub, RetTy, CostKind, TTI::OK_UniformConstantValue); BinaryOperator::Sub, RetTy, CostKind, {TTI::OK_UniformConstantValue, TTI::OP_None});
return Cost; return Cost;
} }
case Intrinsic::smax: case Intrinsic::smax:
@ -1930,11 +1927,12 @@ public:
Cost += 2 * thisT()->getCastInstrCost(Instruction::Trunc, RetTy, ExtTy, Cost += 2 * thisT()->getCastInstrCost(Instruction::Trunc, RetTy, ExtTy,
CCH, CostKind); CCH, CostKind);
Cost += thisT()->getArithmeticInstrCost(Instruction::LShr, RetTy, Cost += thisT()->getArithmeticInstrCost(Instruction::LShr, RetTy,
CostKind, TTI::OK_AnyValue, CostKind,
TTI::OK_UniformConstantValue); {TTI::OK_AnyValue, TTI::OP_None},
{TTI::OK_UniformConstantValue, TTI::OP_None});
Cost += thisT()->getArithmeticInstrCost(Instruction::Shl, RetTy, CostKind, Cost += thisT()->getArithmeticInstrCost(Instruction::Shl, RetTy, CostKind,
TTI::OK_AnyValue, {TTI::OK_AnyValue, TTI::OP_None},
TTI::OK_UniformConstantValue); {TTI::OK_UniformConstantValue, TTI::OP_None});
Cost += thisT()->getArithmeticInstrCost(Instruction::Or, RetTy, CostKind); Cost += thisT()->getArithmeticInstrCost(Instruction::Or, RetTy, CostKind);
return Cost; return Cost;
} }
@ -1995,13 +1993,15 @@ public:
Cost += 2 * thisT()->getCastInstrCost(Instruction::Trunc, MulTy, ExtTy, Cost += 2 * thisT()->getCastInstrCost(Instruction::Trunc, MulTy, ExtTy,
CCH, CostKind); CCH, CostKind);
Cost += thisT()->getArithmeticInstrCost(Instruction::LShr, ExtTy, Cost += thisT()->getArithmeticInstrCost(Instruction::LShr, ExtTy,
CostKind, TTI::OK_AnyValue, CostKind,
TTI::OK_UniformConstantValue); {TTI::OK_AnyValue, TTI::OP_None},
{TTI::OK_UniformConstantValue, TTI::OP_None});
if (IsSigned) if (IsSigned)
Cost += thisT()->getArithmeticInstrCost(Instruction::AShr, MulTy, Cost += thisT()->getArithmeticInstrCost(Instruction::AShr, MulTy,
CostKind, TTI::OK_AnyValue, CostKind,
TTI::OK_UniformConstantValue); {TTI::OK_AnyValue, TTI::OP_None},
{TTI::OK_UniformConstantValue, TTI::OP_None});
Cost += thisT()->getCmpSelInstrCost( Cost += thisT()->getCmpSelInstrCost(
BinaryOperator::ICmp, MulTy, OverflowTy, CmpInst::ICMP_NE, CostKind); BinaryOperator::ICmp, MulTy, OverflowTy, CmpInst::ICMP_NE, CostKind);

View File

@ -771,8 +771,7 @@ InstructionCost TargetTransformInfo::getArithmeticInstrCost(
ArrayRef<const Value *> Args, const Instruction *CxtI) const { ArrayRef<const Value *> Args, const Instruction *CxtI) const {
InstructionCost Cost = InstructionCost Cost =
TTIImpl->getArithmeticInstrCost(Opcode, Ty, CostKind, TTIImpl->getArithmeticInstrCost(Opcode, Ty, CostKind,
Op1Info.Kind, Op2Info.Kind, Op1Info, Op2Info,
Op1Info.Properties, Op2Info.Properties,
Args, CxtI); Args, CxtI);
assert(Cost >= 0 && "TTI should not produce negative costs!"); assert(Cost >= 0 && "TTI should not produce negative costs!");
return Cost; return Cost;

View File

@ -1978,18 +1978,14 @@ InstructionCost AArch64TTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
InstructionCost AArch64TTIImpl::getArithmeticInstrCost( InstructionCost AArch64TTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info, TTI::OperandValueInfo Op1Info, TTI::OperandValueInfo Op2Info,
TTI::OperandValueProperties Opd1PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
const TTI::OperandValueInfo Op2Info = {Opd2Info, Opd2PropInfo};
// TODO: Handle more cost kinds. // TODO: Handle more cost kinds.
if (CostKind != TTI::TCK_RecipThroughput) if (CostKind != TTI::TCK_RecipThroughput)
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
Opd2Info, Opd1PropInfo, Op2Info, Args, CxtI);
Opd2PropInfo, Args, CxtI);
// Legalize the type. // Legalize the type.
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty); std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
@ -1997,8 +1993,8 @@ InstructionCost AArch64TTIImpl::getArithmeticInstrCost(
switch (ISD) { switch (ISD) {
default: default:
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
Opd2Info, Opd1PropInfo, Opd2PropInfo); Op2Info);
case ISD::SDIV: case ISD::SDIV:
if (Op2Info.isConstant() && Op2Info.isUniform() && Op2Info.isPowerOf2()) { if (Op2Info.isConstant() && Op2Info.isUniform() && Op2Info.isPowerOf2()) {
// On AArch64, scalar signed division by constants power-of-two are // On AArch64, scalar signed division by constants power-of-two are
@ -2006,17 +2002,15 @@ InstructionCost AArch64TTIImpl::getArithmeticInstrCost(
// The OperandValue properties many not be same as that of previous // The OperandValue properties many not be same as that of previous
// operation; conservatively assume OP_None. // operation; conservatively assume OP_None.
InstructionCost Cost = getArithmeticInstrCost( InstructionCost Cost = getArithmeticInstrCost(
Instruction::Add, Ty, CostKind, Opd1Info, Opd2Info, Instruction::Add, Ty, CostKind,
TargetTransformInfo::OP_None, TargetTransformInfo::OP_None); Op1Info.getNoProps(), Op2Info.getNoProps());
Cost += getArithmeticInstrCost(Instruction::Sub, Ty, CostKind, Opd1Info, Cost += getArithmeticInstrCost(Instruction::Sub, Ty, CostKind,
Opd2Info, TargetTransformInfo::OP_None, Op1Info.getNoProps(), Op2Info.getNoProps());
TargetTransformInfo::OP_None);
Cost += getArithmeticInstrCost( Cost += getArithmeticInstrCost(
Instruction::Select, Ty, CostKind, Opd1Info, Opd2Info, Instruction::Select, Ty, CostKind,
TargetTransformInfo::OP_None, TargetTransformInfo::OP_None); Op1Info.getNoProps(), Op2Info.getNoProps());
Cost += getArithmeticInstrCost(Instruction::AShr, Ty, CostKind, Opd1Info, Cost += getArithmeticInstrCost(Instruction::AShr, Ty, CostKind,
Opd2Info, TargetTransformInfo::OP_None, Op1Info.getNoProps(), Op2Info.getNoProps());
TargetTransformInfo::OP_None);
return Cost; return Cost;
} }
[[fallthrough]]; [[fallthrough]];
@ -2028,29 +2022,24 @@ InstructionCost AArch64TTIImpl::getArithmeticInstrCost(
// sequence MULHS + ADD/SUB + SRA + SRL + ADD, and unsigned division // sequence MULHS + ADD/SUB + SRA + SRL + ADD, and unsigned division
// to MULHS + SUB + SRL + ADD + SRL. // to MULHS + SUB + SRL + ADD + SRL.
InstructionCost MulCost = getArithmeticInstrCost( InstructionCost MulCost = getArithmeticInstrCost(
Instruction::Mul, Ty, CostKind, Opd1Info, Opd2Info, Instruction::Mul, Ty, CostKind, Op1Info.getNoProps(), Op2Info.getNoProps());
TargetTransformInfo::OP_None, TargetTransformInfo::OP_None);
InstructionCost AddCost = getArithmeticInstrCost( InstructionCost AddCost = getArithmeticInstrCost(
Instruction::Add, Ty, CostKind, Opd1Info, Opd2Info, Instruction::Add, Ty, CostKind, Op1Info.getNoProps(), Op2Info.getNoProps());
TargetTransformInfo::OP_None, TargetTransformInfo::OP_None);
InstructionCost ShrCost = getArithmeticInstrCost( InstructionCost ShrCost = getArithmeticInstrCost(
Instruction::AShr, Ty, CostKind, Opd1Info, Opd2Info, Instruction::AShr, Ty, CostKind, Op1Info.getNoProps(), Op2Info.getNoProps());
TargetTransformInfo::OP_None, TargetTransformInfo::OP_None);
return MulCost * 2 + AddCost * 2 + ShrCost * 2 + 1; return MulCost * 2 + AddCost * 2 + ShrCost * 2 + 1;
} }
} }
InstructionCost Cost = BaseT::getArithmeticInstrCost( InstructionCost Cost = BaseT::getArithmeticInstrCost(
Opcode, Ty, CostKind, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo); Opcode, Ty, CostKind, Op1Info, Op2Info);
if (Ty->isVectorTy()) { if (Ty->isVectorTy()) {
// On AArch64, vector divisions are not supported natively and are // On AArch64, vector divisions are not supported natively and are
// expanded into scalar divisions of each pair of elements. // expanded into scalar divisions of each pair of elements.
Cost += getArithmeticInstrCost(Instruction::ExtractElement, Ty, CostKind, Cost += getArithmeticInstrCost(Instruction::ExtractElement, Ty, CostKind,
Opd1Info, Opd2Info, Opd1PropInfo, Op1Info, Op2Info);
Opd2PropInfo);
Cost += getArithmeticInstrCost(Instruction::InsertElement, Ty, CostKind, Cost += getArithmeticInstrCost(Instruction::InsertElement, Ty, CostKind,
Opd1Info, Opd2Info, Opd1PropInfo, Op1Info, Op2Info);
Opd2PropInfo);
// TODO: if one of the arguments is scalar, then it's not necessary to // TODO: if one of the arguments is scalar, then it's not necessary to
// double the cost of handling the vector elements. // double the cost of handling the vector elements.
Cost += Cost; Cost += Cost;
@ -2092,8 +2081,8 @@ InstructionCost AArch64TTIImpl::getArithmeticInstrCost(
if (!Ty->getScalarType()->isFP128Ty()) if (!Ty->getScalarType()->isFP128Ty())
return 2 * LT.first; return 2 * LT.first;
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
Opd2Info, Opd1PropInfo, Opd2PropInfo); Op2Info);
} }
} }

View File

@ -189,10 +189,8 @@ public:
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
ArrayRef<const Value *> Args = ArrayRef<const Value *>(), ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
const Instruction *CxtI = nullptr); const Instruction *CxtI = nullptr);

View File

@ -512,9 +512,8 @@ bool GCNTTIImpl::getTgtMemIntrinsic(IntrinsicInst *Inst,
InstructionCost GCNTTIImpl::getArithmeticInstrCost( InstructionCost GCNTTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info, TTI::OperandValueInfo Op1Info, TTI::OperandValueInfo Op2Info,
TTI::OperandValueProperties Opd1PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
// Legalize the type. // Legalize the type.
@ -657,8 +656,8 @@ InstructionCost GCNTTIImpl::getArithmeticInstrCost(
break; break;
} }
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, Opd2Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info,
Opd1PropInfo, Opd2PropInfo, Args, CxtI); Args, CxtI);
} }
// Return true if there's a potential benefit from using v2f16/v2i16 // Return true if there's a potential benefit from using v2f16/v2i16

View File

@ -148,10 +148,8 @@ public:
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
ArrayRef<const Value *> Args = ArrayRef<const Value *>(), ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
const Instruction *CxtI = nullptr); const Instruction *CxtI = nullptr);

View File

@ -1308,9 +1308,8 @@ InstructionCost ARMTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
InstructionCost ARMTTIImpl::getArithmeticInstrCost( InstructionCost ARMTTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Op1Info, TTI::OperandValueKind Op2Info, TTI::OperandValueInfo Op1Info, TTI::OperandValueInfo Op2Info,
TTI::OperandValueProperties Opd1PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
int ISDOpcode = TLI->InstructionOpcodeToISD(Opcode); int ISDOpcode = TLI->InstructionOpcodeToISD(Opcode);
if (ST->isThumb() && CostKind == TTI::TCK_CodeSize && Ty->isIntegerTy(1)) { if (ST->isThumb() && CostKind == TTI::TCK_CodeSize && Ty->isIntegerTy(1)) {
@ -1378,7 +1377,7 @@ InstructionCost ARMTTIImpl::getArithmeticInstrCost(
return LT.first * Entry->Cost; return LT.first * Entry->Cost;
InstructionCost Cost = BaseT::getArithmeticInstrCost( InstructionCost Cost = BaseT::getArithmeticInstrCost(
Opcode, Ty, CostKind, Op1Info, Op2Info, Opd1PropInfo, Opd2PropInfo); Opcode, Ty, CostKind, Op1Info, Op2Info);
// This is somewhat of a hack. The problem that we are facing is that SROA // This is somewhat of a hack. The problem that we are facing is that SROA
// creates a sequence of shift, and, or instructions to construct values. // creates a sequence of shift, and, or instructions to construct values.
@ -1388,7 +1387,7 @@ InstructionCost ARMTTIImpl::getArithmeticInstrCost(
// To work around this we increase the cost of v2i64 operations to make them // To work around this we increase the cost of v2i64 operations to make them
// seem less beneficial. // seem less beneficial.
if (LT.second == MVT::v2i64 && if (LT.second == MVT::v2i64 &&
Op2Info == TargetTransformInfo::OK_UniformConstantValue) Op2Info.Kind == TargetTransformInfo::OK_UniformConstantValue)
Cost += 4; Cost += 4;
return Cost; return Cost;
@ -1402,7 +1401,7 @@ InstructionCost ARMTTIImpl::getArithmeticInstrCost(
if (!CxtI || !CxtI->hasOneUse() || !CxtI->isShift()) if (!CxtI || !CxtI->hasOneUse() || !CxtI->isShift())
return false; return false;
if (Op2Info != TargetTransformInfo::OK_UniformConstantValue) if (Op2Info.Kind != TargetTransformInfo::OK_UniformConstantValue)
return false; return false;
// Folded into a ADC/ADD/AND/BIC/CMP/EOR/MVN/ORR/ORN/RSB/SBC/SUB // Folded into a ADC/ADD/AND/BIC/CMP/EOR/MVN/ORR/ORN/RSB/SBC/SUB

View File

@ -247,10 +247,8 @@ public:
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Op1Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueKind Op2Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
ArrayRef<const Value *> Args = ArrayRef<const Value *>(), ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
const Instruction *CxtI = nullptr); const Instruction *CxtI = nullptr);

View File

@ -57,19 +57,16 @@ public:
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
ArrayRef<const Value *> Args = ArrayRef<const Value *>(), ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
const Instruction *CxtI = nullptr) { const Instruction *CxtI = nullptr) {
int ISD = TLI->InstructionOpcodeToISD(Opcode); int ISD = TLI->InstructionOpcodeToISD(Opcode);
if (ISD == ISD::ADD && CostKind == TTI::TCK_RecipThroughput) if (ISD == ISD::ADD && CostKind == TTI::TCK_RecipThroughput)
return SCEVCheapExpansionBudget.getValue() + 1; return SCEVCheapExpansionBudget.getValue() + 1;
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
Opd2Info, Opd1PropInfo, Op2Info);
Opd2PropInfo);
} }
TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize,

View File

@ -265,23 +265,21 @@ InstructionCost HexagonTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
InstructionCost HexagonTTIImpl::getArithmeticInstrCost( InstructionCost HexagonTTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info, TTI::OperandValueInfo Op1Info, TTI::OperandValueInfo Op2Info,
TTI::OperandValueProperties Opd1PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
// TODO: Handle more cost kinds. // TODO: Handle more cost kinds.
if (CostKind != TTI::TCK_RecipThroughput) if (CostKind != TTI::TCK_RecipThroughput)
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
Opd2Info, Opd1PropInfo, Op2Info, Args, CxtI);
Opd2PropInfo, Args, CxtI);
if (Ty->isVectorTy()) { if (Ty->isVectorTy()) {
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty); std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
if (LT.second.isFloatingPoint()) if (LT.second.isFloatingPoint())
return LT.first + FloatFactor * getTypeNumElements(Ty); return LT.first + FloatFactor * getTypeNumElements(Ty);
} }
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, Opd2Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info,
Opd1PropInfo, Opd2PropInfo, Args, CxtI); Args, CxtI);
} }
InstructionCost HexagonTTIImpl::getCastInstrCost(unsigned Opcode, Type *DstTy, InstructionCost HexagonTTIImpl::getCastInstrCost(unsigned Opcode, Type *DstTy,

View File

@ -144,10 +144,8 @@ public:
const Instruction *I = nullptr); const Instruction *I = nullptr);
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
ArrayRef<const Value *> Args = ArrayRef<const Value *>(), ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
const Instruction *CxtI = nullptr); const Instruction *CxtI = nullptr);
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,

View File

@ -92,19 +92,16 @@ public:
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
ArrayRef<const Value *> Args = ArrayRef<const Value *>(), ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
const Instruction *CxtI = nullptr) { const Instruction *CxtI = nullptr) {
int ISD = TLI->InstructionOpcodeToISD(Opcode); int ISD = TLI->InstructionOpcodeToISD(Opcode);
switch (ISD) { switch (ISD) {
default: default:
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
Opd2Info, Op2Info);
Opd1PropInfo, Opd2PropInfo);
case ISD::MUL: case ISD::MUL:
case ISD::SDIV: case ISD::SDIV:
case ISD::UDIV: case ISD::UDIV:
@ -114,9 +111,8 @@ public:
// instruction cost was arbitrarily chosen to reduce the desirability // instruction cost was arbitrarily chosen to reduce the desirability
// of emitting arithmetic instructions that are emulated in software. // of emitting arithmetic instructions that are emulated in software.
// TODO: Investigate the performance impact given specialized lowerings. // TODO: Investigate the performance impact given specialized lowerings.
return 64 * BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, return 64 * BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
Opd2Info, Op2Info);
Opd1PropInfo, Opd2PropInfo);
} }
} }
}; };

View File

@ -423,9 +423,8 @@ NVPTXTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
InstructionCost NVPTXTTIImpl::getArithmeticInstrCost( InstructionCost NVPTXTTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info, TTI::OperandValueInfo Op1Info, TTI::OperandValueInfo Op2Info,
TTI::OperandValueProperties Opd1PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
// Legalize the type. // Legalize the type.
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty); std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
@ -434,9 +433,8 @@ InstructionCost NVPTXTTIImpl::getArithmeticInstrCost(
switch (ISD) { switch (ISD) {
default: default:
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
Opd2Info, Op2Info);
Opd1PropInfo, Opd2PropInfo);
case ISD::ADD: case ISD::ADD:
case ISD::MUL: case ISD::MUL:
case ISD::XOR: case ISD::XOR:
@ -448,9 +446,8 @@ InstructionCost NVPTXTTIImpl::getArithmeticInstrCost(
if (LT.second.SimpleTy == MVT::i64) if (LT.second.SimpleTy == MVT::i64)
return 2 * LT.first; return 2 * LT.first;
// Delegate other cases to the basic TTI. // Delegate other cases to the basic TTI.
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
Opd2Info, Op2Info);
Opd1PropInfo, Opd2PropInfo);
} }
} }

View File

@ -95,10 +95,8 @@ public:
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
ArrayRef<const Value *> Args = ArrayRef<const Value *>(), ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
const Instruction *CxtI = nullptr); const Instruction *CxtI = nullptr);

View File

@ -980,9 +980,8 @@ InstructionCost PPCTTIImpl::vectorCostAdjustmentFactor(unsigned Opcode,
InstructionCost PPCTTIImpl::getArithmeticInstrCost( InstructionCost PPCTTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Op1Info, TTI::OperandValueKind Op2Info, TTI::OperandValueInfo Op1Info, TTI::OperandValueInfo Op2Info,
TTI::OperandValueProperties Opd1PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
assert(TLI->InstructionOpcodeToISD(Opcode) && "Invalid opcode"); assert(TLI->InstructionOpcodeToISD(Opcode) && "Invalid opcode");
@ -993,12 +992,11 @@ InstructionCost PPCTTIImpl::getArithmeticInstrCost(
// TODO: Handle more cost kinds. // TODO: Handle more cost kinds.
if (CostKind != TTI::TCK_RecipThroughput) if (CostKind != TTI::TCK_RecipThroughput)
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
Op2Info, Opd1PropInfo, Op2Info, Args, CxtI);
Opd2PropInfo, Args, CxtI);
// Fallback to the default implementation. // Fallback to the default implementation.
InstructionCost Cost = BaseT::getArithmeticInstrCost( InstructionCost Cost = BaseT::getArithmeticInstrCost(
Opcode, Ty, CostKind, Op1Info, Op2Info, Opd1PropInfo, Opd2PropInfo); Opcode, Ty, CostKind, Op1Info, Op2Info);
return Cost * CostFactor; return Cost * CostFactor;
} }

View File

@ -105,10 +105,8 @@ public:
Type *Ty2); Type *Ty2);
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
ArrayRef<const Value *> Args = ArrayRef<const Value *>(), ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
const Instruction *CxtI = nullptr); const Instruction *CxtI = nullptr);
InstructionCost getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, InstructionCost getShuffleCost(TTI::ShuffleKind Kind, Type *Tp,

View File

@ -419,16 +419,14 @@ static unsigned getNumVectorRegs(Type *Ty) {
InstructionCost SystemZTTIImpl::getArithmeticInstrCost( InstructionCost SystemZTTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Op1Info, TTI::OperandValueKind Op2Info, TTI::OperandValueInfo Op1Info, TTI::OperandValueInfo Op2Info,
TTI::OperandValueProperties Opd1PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
// TODO: Handle more cost kinds. // TODO: Handle more cost kinds.
if (CostKind != TTI::TCK_RecipThroughput) if (CostKind != TTI::TCK_RecipThroughput)
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
Op2Info, Opd1PropInfo, Op2Info, Args, CxtI);
Opd2PropInfo, Args, CxtI);
// TODO: return a good value for BB-VECTORIZER that includes the // TODO: return a good value for BB-VECTORIZER that includes the
// immediate loads, which we do not want to count for the loop // immediate loads, which we do not want to count for the loop
@ -589,7 +587,7 @@ InstructionCost SystemZTTIImpl::getArithmeticInstrCost(
// Fallback to the default implementation. // Fallback to the default implementation.
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info,
Opd1PropInfo, Opd2PropInfo, Args, CxtI); Args, CxtI);
} }
InstructionCost SystemZTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, InstructionCost SystemZTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,

View File

@ -85,10 +85,8 @@ public:
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
ArrayRef<const Value *> Args = ArrayRef<const Value *>(), ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
const Instruction *CxtI = nullptr); const Instruction *CxtI = nullptr);
InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *Tp, InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *Tp,

View File

@ -52,16 +52,13 @@ TypeSize WebAssemblyTTIImpl::getRegisterBitWidth(
InstructionCost WebAssemblyTTIImpl::getArithmeticInstrCost( InstructionCost WebAssemblyTTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info, TTI::OperandValueInfo Op1Info, TTI::OperandValueInfo Op2Info,
TTI::OperandValueProperties Opd1PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
const TTI::OperandValueInfo Op2Info = {Opd2Info, Opd2PropInfo};
InstructionCost Cost = InstructionCost Cost =
BasicTTIImplBase<WebAssemblyTTIImpl>::getArithmeticInstrCost( BasicTTIImplBase<WebAssemblyTTIImpl>::getArithmeticInstrCost(
Opcode, Ty, CostKind, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo); Opcode, Ty, CostKind, Op1Info, Op2Info);
if (auto *VTy = dyn_cast<VectorType>(Ty)) { if (auto *VTy = dyn_cast<VectorType>(Ty)) {
switch (Opcode) { switch (Opcode) {

View File

@ -61,10 +61,8 @@ public:
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const; TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const;
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
ArrayRef<const Value *> Args = ArrayRef<const Value *>(), ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
const Instruction *CxtI = nullptr); const Instruction *CxtI = nullptr);
using BaseT::getVectorInstrCost; using BaseT::getVectorInstrCost;

View File

@ -176,13 +176,10 @@ unsigned X86TTIImpl::getMaxInterleaveFactor(unsigned VF) {
InstructionCost X86TTIImpl::getArithmeticInstrCost( InstructionCost X86TTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Op1Kind, TTI::OperandValueKind Op2Kind, TTI::OperandValueInfo Op1Info, TTI::OperandValueInfo Op2Info,
TTI::OperandValueProperties Opd1PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
const TTI::OperandValueInfo Op2Info = {Op2Kind, Opd2PropInfo};
// vXi8 multiplications are always promoted to vXi16. // vXi8 multiplications are always promoted to vXi16.
if (Opcode == Instruction::Mul && Ty->isVectorTy() && if (Opcode == Instruction::Mul && Ty->isVectorTy() &&
Ty->getScalarSizeInBits() == 8) { Ty->getScalarSizeInBits() == 8) {
@ -194,8 +191,7 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
getCastInstrCost(Instruction::Trunc, Ty, WideVecTy, getCastInstrCost(Instruction::Trunc, Ty, WideVecTy,
TargetTransformInfo::CastContextHint::None, TargetTransformInfo::CastContextHint::None,
CostKind) + CostKind) +
getArithmeticInstrCost(Opcode, WideVecTy, CostKind, Op1Kind, Op2Kind, getArithmeticInstrCost(Opcode, WideVecTy, CostKind, Op1Info, Op2Info);
Opd1PropInfo, Opd2PropInfo);
} }
// Legalize the type. // Legalize the type.
@ -236,9 +232,8 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
// Vector multiply by pow2 will be simplified to shifts. // Vector multiply by pow2 will be simplified to shifts.
if (ISD == ISD::MUL && Op2Info.isConstant() && Op2Info.isPowerOf2()) if (ISD == ISD::MUL && Op2Info.isConstant() && Op2Info.isPowerOf2())
return getArithmeticInstrCost(Instruction::Shl, Ty, CostKind, Op1Kind, return getArithmeticInstrCost(Instruction::Shl, Ty, CostKind,
Op2Kind, TargetTransformInfo::OP_None, Op1Info.getNoProps(), Op2Info.getNoProps());
TargetTransformInfo::OP_None);
// On X86, vector signed division by constants power-of-two are // On X86, vector signed division by constants power-of-two are
// normally expanded to the sequence SRA + SRL + ADD + SRA. // normally expanded to the sequence SRA + SRL + ADD + SRA.
@ -247,22 +242,19 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
if ((ISD == ISD::SDIV || ISD == ISD::SREM) && if ((ISD == ISD::SDIV || ISD == ISD::SREM) &&
Op2Info.isConstant() && Op2Info.isPowerOf2()) { Op2Info.isConstant() && Op2Info.isPowerOf2()) {
InstructionCost Cost = InstructionCost Cost =
2 * getArithmeticInstrCost(Instruction::AShr, Ty, CostKind, Op1Kind, 2 * getArithmeticInstrCost(Instruction::AShr, Ty, CostKind,
Op2Kind, TargetTransformInfo::OP_None, Op1Info.getNoProps(), Op2Info.getNoProps());
TargetTransformInfo::OP_None); Cost += getArithmeticInstrCost(Instruction::LShr, Ty, CostKind,
Cost += getArithmeticInstrCost(Instruction::LShr, Ty, CostKind, Op1Kind, Op1Info.getNoProps(), Op2Info.getNoProps());
Op2Kind, TargetTransformInfo::OP_None, Cost += getArithmeticInstrCost(Instruction::Add, Ty, CostKind,
TargetTransformInfo::OP_None); Op1Info.getNoProps(), Op2Info.getNoProps());
Cost += getArithmeticInstrCost(Instruction::Add, Ty, CostKind, Op1Kind,
Op2Kind, TargetTransformInfo::OP_None,
TargetTransformInfo::OP_None);
if (ISD == ISD::SREM) { if (ISD == ISD::SREM) {
// For SREM: (X % C) is the equivalent of (X - (X/C)*C) // For SREM: (X % C) is the equivalent of (X - (X/C)*C)
Cost += getArithmeticInstrCost(Instruction::Mul, Ty, CostKind, Op1Kind, Cost += getArithmeticInstrCost(Instruction::Mul, Ty, CostKind, Op1Info.getNoProps(),
Op2Kind); Op2Info.getNoProps());
Cost += getArithmeticInstrCost(Instruction::Sub, Ty, CostKind, Op1Kind, Cost += getArithmeticInstrCost(Instruction::Sub, Ty, CostKind, Op1Info.getNoProps(),
Op2Kind); Op2Info.getNoProps());
} }
return Cost; return Cost;
@ -272,13 +264,11 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
if ((ISD == ISD::UDIV || ISD == ISD::UREM) && if ((ISD == ISD::UDIV || ISD == ISD::UREM) &&
Op2Info.isConstant() && Op2Info.isPowerOf2()) { Op2Info.isConstant() && Op2Info.isPowerOf2()) {
if (ISD == ISD::UDIV) if (ISD == ISD::UDIV)
return getArithmeticInstrCost(Instruction::LShr, Ty, CostKind, Op1Kind, return getArithmeticInstrCost(Instruction::LShr, Ty, CostKind,
Op2Kind, TargetTransformInfo::OP_None, Op1Info.getNoProps(), Op2Info.getNoProps());
TargetTransformInfo::OP_None);
// UREM // UREM
return getArithmeticInstrCost(Instruction::And, Ty, CostKind, Op1Kind, return getArithmeticInstrCost(Instruction::And, Ty, CostKind,
Op2Kind, TargetTransformInfo::OP_None, Op1Info.getNoProps(), Op2Info.getNoProps());
TargetTransformInfo::OP_None);
} }
// TODO: Handle more cost kinds. // TODO: Handle more cost kinds.
@ -294,8 +284,8 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
} }
} }
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Kind, Op2Kind, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind,
Opd1PropInfo, Opd2PropInfo, Args, Op1Info, Op2Info, Args,
CxtI); CxtI);
} }
@ -702,9 +692,7 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
// On AVX512, a packed v32i16 shift left by a constant build_vector // On AVX512, a packed v32i16 shift left by a constant build_vector
// is lowered into a vector multiply (vpmullw). // is lowered into a vector multiply (vpmullw).
return getArithmeticInstrCost(Instruction::Mul, Ty, CostKind, return getArithmeticInstrCost(Instruction::Mul, Ty, CostKind,
Op1Kind, Op2Kind, Op1Info.getNoProps(), Op2Info.getNoProps());
TargetTransformInfo::OP_None,
TargetTransformInfo::OP_None);
} }
// Look for AVX2 lowering tricks (XOP is always better at v4i32 shifts). // Look for AVX2 lowering tricks (XOP is always better at v4i32 shifts).
@ -714,9 +702,7 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
// On AVX2, a packed v16i16 shift left by a constant build_vector // On AVX2, a packed v16i16 shift left by a constant build_vector
// is lowered into a vector multiply (vpmullw). // is lowered into a vector multiply (vpmullw).
return getArithmeticInstrCost(Instruction::Mul, Ty, CostKind, return getArithmeticInstrCost(Instruction::Mul, Ty, CostKind,
Op1Kind, Op2Kind, Op1Info.getNoProps(), Op2Info.getNoProps());
TargetTransformInfo::OP_None,
TargetTransformInfo::OP_None);
if (const auto *Entry = CostTableLookup(AVX2ShiftCostTable, ISD, LT.second)) if (const auto *Entry = CostTableLookup(AVX2ShiftCostTable, ISD, LT.second))
return LT.first * Entry->Cost; return LT.first * Entry->Cost;
@ -791,7 +777,7 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
} }
if (ISD == ISD::SHL && if (ISD == ISD::SHL &&
Op2Kind == TargetTransformInfo::OK_NonUniformConstantValue) { Op2Info.Kind == TargetTransformInfo::OK_NonUniformConstantValue) {
MVT VT = LT.second; MVT VT = LT.second;
// Vector shift left by non uniform constant can be lowered // Vector shift left by non uniform constant can be lowered
// into vector multiply. // into vector multiply.
@ -1059,14 +1045,14 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
if (LT.second.isVector() && (ISD == ISD::SDIV || ISD == ISD::SREM || if (LT.second.isVector() && (ISD == ISD::SDIV || ISD == ISD::SREM ||
ISD == ISD::UDIV || ISD == ISD::UREM)) { ISD == ISD::UDIV || ISD == ISD::UREM)) {
InstructionCost ScalarCost = getArithmeticInstrCost( InstructionCost ScalarCost = getArithmeticInstrCost(
Opcode, Ty->getScalarType(), CostKind, Op1Kind, Op2Kind, Opcode, Ty->getScalarType(), CostKind,
TargetTransformInfo::OP_None, TargetTransformInfo::OP_None); Op1Info.getNoProps(), Op2Info.getNoProps());
return 20 * LT.first * LT.second.getVectorNumElements() * ScalarCost; return 20 * LT.first * LT.second.getVectorNumElements() * ScalarCost;
} }
// Fallback to the default implementation. // Fallback to the default implementation.
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Kind, Op2Kind, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info,
Opd1PropInfo, Opd2PropInfo, Args, CxtI); Args, CxtI);
} }
InstructionCost X86TTIImpl::getShuffleCost(TTI::ShuffleKind Kind, InstructionCost X86TTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
@ -4529,9 +4515,8 @@ X86TTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *ValTy,
Type::getIntNTy(ValVTy->getContext(), Size), 128 / Size); Type::getIntNTy(ValVTy->getContext(), Size), 128 / Size);
ReductionCost += getArithmeticInstrCost( ReductionCost += getArithmeticInstrCost(
Instruction::LShr, ShiftTy, CostKind, Instruction::LShr, ShiftTy, CostKind,
TargetTransformInfo::OK_AnyValue, {TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None},
TargetTransformInfo::OK_UniformConstantValue, {TargetTransformInfo::OK_UniformConstantValue, TargetTransformInfo::OP_None});
TargetTransformInfo::OP_None, TargetTransformInfo::OP_None);
} }
// Add the arithmetic op for this level. // Add the arithmetic op for this level.
@ -4828,9 +4813,8 @@ X86TTIImpl::getMinMaxReductionCost(VectorType *ValTy, VectorType *CondTy,
Type::getIntNTy(ValTy->getContext(), Size), 128 / Size); Type::getIntNTy(ValTy->getContext(), Size), 128 / Size);
MinMaxCost += getArithmeticInstrCost( MinMaxCost += getArithmeticInstrCost(
Instruction::LShr, ShiftTy, TTI::TCK_RecipThroughput, Instruction::LShr, ShiftTy, TTI::TCK_RecipThroughput,
TargetTransformInfo::OK_AnyValue, {TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None},
TargetTransformInfo::OK_UniformConstantValue, {TargetTransformInfo::OK_UniformConstantValue, TargetTransformInfo::OP_None});
TargetTransformInfo::OP_None, TargetTransformInfo::OP_None);
} }
// Add the arithmetic op for this level. // Add the arithmetic op for this level.

View File

@ -128,10 +128,8 @@ public:
unsigned getMaxInterleaveFactor(unsigned VF); unsigned getMaxInterleaveFactor(unsigned VF);
InstructionCost getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
ArrayRef<const Value *> Args = ArrayRef<const Value *>(), ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
const Instruction *CxtI = nullptr); const Instruction *CxtI = nullptr);
InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *Tp, InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *Tp,