diff options
author | Sam Parker <sam.parker@arm.com> | 2020-04-28 14:11:27 +0100 |
---|---|---|
committer | Sam Parker <sam.parker@arm.com> | 2020-05-05 10:35:54 +0100 |
commit | 40574fefe9b2ad7d251da25c7461c313d965b809 (patch) | |
tree | c35b64a627be6377900be6e17eeec672bd42958c /llvm/lib/Analysis/ScalarEvolutionExpander.cpp | |
parent | 5578ec32f9c4fef46adce52a2e3d22bf409b3d2c (diff) | |
download | llvm-40574fefe9b2ad7d251da25c7461c313d965b809.zip llvm-40574fefe9b2ad7d251da25c7461c313d965b809.tar.gz llvm-40574fefe9b2ad7d251da25c7461c313d965b809.tar.bz2 |
[NFC][CostModel] Add TargetCostKind to relevant APIs
Make the kind of cost explicit throughout the cost model which,
apart from making the cost clear, will allow the generic parts to
calculate better costs. It will also allow some backends to
approximate and correlate the different costs if they wish. Another
benefit is that it will also help simplify the cost model around
immediate and intrinsic costs, where we currently have multiple APIs.
RFC thread:
http://lists.llvm.org/pipermail/llvm-dev/2020-April/141263.html
Differential Revision: https://reviews.llvm.org/D79002
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp index 5ffdb0b..22619d0f 100644 --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp @@ -2157,6 +2157,9 @@ bool SCEVExpander::isHighCostExpansionHelper( return false; // Assume to be zero-cost. } + TargetTransformInfo::TargetCostKind CostKind = + TargetTransformInfo::TCK_RecipThroughput; + if (auto *CastExpr = dyn_cast<SCEVCastExpr>(S)) { unsigned Opcode; switch (S->getSCEVType()) { @@ -2174,7 +2177,7 @@ bool SCEVExpander::isHighCostExpansionHelper( } const SCEV *Op = CastExpr->getOperand(); BudgetRemaining -= TTI.getCastInstrCost(Opcode, /*Dst=*/S->getType(), - /*Src=*/Op->getType()); + /*Src=*/Op->getType(), CostKind); Worklist.emplace_back(Op); return false; // Will answer upon next entry into this function. } @@ -2184,7 +2187,8 @@ bool SCEVExpander::isHighCostExpansionHelper( if (auto *SC = dyn_cast<SCEVConstant>(UDivExpr->getRHS())) { if (SC->getAPInt().isPowerOf2()) { BudgetRemaining -= - TTI.getArithmeticInstrCost(Instruction::LShr, S->getType()); + TTI.getArithmeticInstrCost(Instruction::LShr, S->getType(), + CostKind); // Note that we don't count the cost of RHS, because it is a constant, // and we consider those to be free. But if that changes, we would need // to log2() it first before calling isHighCostExpansionHelper(). @@ -2207,7 +2211,8 @@ bool SCEVExpander::isHighCostExpansionHelper( // Need to count the cost of this UDiv. BudgetRemaining -= - TTI.getArithmeticInstrCost(Instruction::UDiv, S->getType()); + TTI.getArithmeticInstrCost(Instruction::UDiv, S->getType(), + CostKind); Worklist.insert(Worklist.end(), {UDivExpr->getLHS(), UDivExpr->getRHS()}); return false; // Will answer upon next entry into this function. } @@ -2218,8 +2223,10 @@ bool SCEVExpander::isHighCostExpansionHelper( assert(NAry->getNumOperands() >= 2 && "Polynomial should be at least linear"); - int AddCost = TTI.getArithmeticInstrCost(Instruction::Add, OpType); - int MulCost = TTI.getArithmeticInstrCost(Instruction::Mul, OpType); + int AddCost = + TTI.getArithmeticInstrCost(Instruction::Add, OpType, CostKind); + int MulCost = + TTI.getArithmeticInstrCost(Instruction::Mul, OpType, CostKind); // In this polynominal, we may have some zero operands, and we shouldn't // really charge for those. So how many non-zero coeffients are there? @@ -2273,22 +2280,26 @@ bool SCEVExpander::isHighCostExpansionHelper( int PairCost; switch (S->getSCEVType()) { case scAddExpr: - PairCost = TTI.getArithmeticInstrCost(Instruction::Add, OpType); + PairCost = + TTI.getArithmeticInstrCost(Instruction::Add, OpType, CostKind); break; case scMulExpr: // TODO: this is a very pessimistic cost modelling for Mul, // because of Bin Pow algorithm actually used by the expander, // see SCEVExpander::visitMulExpr(), ExpandOpBinPowN(). - PairCost = TTI.getArithmeticInstrCost(Instruction::Mul, OpType); + PairCost = + TTI.getArithmeticInstrCost(Instruction::Mul, OpType, CostKind); break; case scSMaxExpr: case scUMaxExpr: case scSMinExpr: case scUMinExpr: PairCost = TTI.getCmpSelInstrCost(Instruction::ICmp, OpType, - CmpInst::makeCmpResultType(OpType)) + + CmpInst::makeCmpResultType(OpType), + CostKind) + TTI.getCmpSelInstrCost(Instruction::Select, OpType, - CmpInst::makeCmpResultType(OpType)); + CmpInst::makeCmpResultType(OpType), + CostKind); break; default: llvm_unreachable("There are no other variants here."); |