diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h index bd8d29cb22a12..f98b8bf7da2c9 100644 --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -776,6 +776,14 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase { TTI::TargetCostKind CostKind) { auto *TargetTTI = static_cast(this); + // FIXME: We shouldn't have to special-case intrinsics here. + if (CostKind == TTI::TCK_RecipThroughput) { + if (const IntrinsicInst *II = dyn_cast(U)) { + IntrinsicCostAttributes CostAttrs(*II); + return TargetTTI->getIntrinsicInstrCost(CostAttrs, CostKind); + } + } + // FIXME: Unlikely to be true for anything but CodeSize. if (const auto *CB = dyn_cast(U)) { const Function *F = CB->getCalledFunction(); diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp index a14199515faf5..9f319c40ae6a7 100644 --- a/llvm/lib/Analysis/TargetTransformInfo.cpp +++ b/llvm/lib/Analysis/TargetTransformInfo.cpp @@ -260,7 +260,8 @@ int TargetTransformInfo::getUserCost(const User *U, ArrayRef Operands, enum TargetCostKind CostKind) const { int Cost = TTIImpl->getUserCost(U, Operands, CostKind); - assert(Cost >= 0 && "TTI should not produce negative costs!"); + assert((CostKind == TTI::TCK_RecipThroughput || Cost >= 0) && + "TTI should not produce negative costs!"); return Cost; } @@ -1419,11 +1420,7 @@ int TargetTransformInfo::getInstructionThroughput(const Instruction *I) const { return TTIImpl->getShuffleCost(SK_PermuteTwoSrc, Ty, 0, nullptr); } case Instruction::Call: - if (const IntrinsicInst *II = dyn_cast(I)) { - IntrinsicCostAttributes CostAttrs(*II); - return getIntrinsicInstrCost(CostAttrs, CostKind); - } - return -1; + return getUserCost(I, CostKind); default: // We don't have any information on this instruction. return -1;