Skip to content

Commit

Permalink
[CostModel][X86] Add CodeSize/SizeLatency handling for fadd/fsub/fmul…
Browse files Browse the repository at this point in the history
…/fsqrt ops

Eventually this will be part of the cost table lookup
  • Loading branch information
RKSimon committed Aug 21, 2022
1 parent d49a82f commit 15de7aa
Show file tree
Hide file tree
Showing 4 changed files with 532 additions and 263 deletions.
18 changes: 17 additions & 1 deletion llvm/lib/Target/X86/X86TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,22 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
}

// TODO: Handle more cost kinds.
if (CostKind != TTI::TCK_RecipThroughput)
if (CostKind != TTI::TCK_RecipThroughput) {
// Handle some basic single instruction code size cases.
if (CostKind == TTI::TCK_CodeSize || CostKind == TTI::TCK_SizeAndLatency) {
switch (ISD) {
case ISD::FADD:
case ISD::FSUB:
case ISD::FMUL:
return LT.first;
break;
}
}

return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info,
Opd1PropInfo, Opd2PropInfo, Args,
CxtI);
}

static const CostTblEntry GLMCostTable[] = {
{ ISD::FDIV, MVT::f32, 18 }, // divss
Expand Down Expand Up @@ -3427,6 +3439,10 @@ X86TTIImpl::getTypeBasedIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
return LT.first * Cost;
}

// FSQRT is a single instruction.
if (ISD == ISD::FSQRT && CostKind == TTI::TCK_CodeSize)
return LT.first;

auto adjustTableCost = [](const CostTblEntry &Entry,
InstructionCost LegalizationCost,
FastMathFlags FMF) {
Expand Down
Loading

0 comments on commit 15de7aa

Please sign in to comment.