[CostModel] split handling of intrinsics from other calls

This should be close to NFC (no-functional-change), but I
can't completely rule out that some call on some target
travels down a different path. There's an especially large
amount of code spaghetti in this part of the cost model.

The goal is to clean up the intrinsic cost handling so
we can canonicalize to the new min/max intrinsics without
causing regressions.
This commit is contained in:
Sanjay Patel 2020-09-28 10:11:08 -04:00
parent f55a5186c6
commit 1121a583b8
1 changed files with 18 additions and 20 deletions
llvm/include/llvm/Analysis

View File

@ -20,7 +20,7 @@
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/Type.h"
@ -834,30 +834,17 @@ public:
int getUserCost(const User *U, ArrayRef<const Value *> Operands,
TTI::TargetCostKind CostKind) {
auto *TargetTTI = static_cast<T *>(this);
// FIXME: We shouldn't have to special-case intrinsics here.
if (CostKind == TTI::TCK_RecipThroughput) {
if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(U)) {
IntrinsicCostAttributes CostAttrs(*II);
return TargetTTI->getIntrinsicInstrCost(CostAttrs, CostKind);
}
}
// Handle non-intrinsic calls, invokes, and callbr.
// FIXME: Unlikely to be true for anything but CodeSize.
if (const auto *CB = dyn_cast<CallBase>(U)) {
const Function *F = CB->getCalledFunction();
if (F) {
FunctionType *FTy = F->getFunctionType();
if (Intrinsic::ID IID = F->getIntrinsicID()) {
IntrinsicCostAttributes Attrs(IID, *CB);
return TargetTTI->getIntrinsicInstrCost(Attrs, CostKind);
}
auto *CB = dyn_cast<CallBase>(U);
if (CB && !isa<IntrinsicInst>(U)) {
if (const Function *F = CB->getCalledFunction()) {
if (!TargetTTI->isLoweredToCall(F))
return TTI::TCC_Basic; // Give a basic cost if it will be lowered
return TTI::TCC_Basic * (FTy->getNumParams() + 1);
return TTI::TCC_Basic * (F->getFunctionType()->getNumParams() + 1);
}
// For indirect or other calls, scale cost by number of arguments.
return TTI::TCC_Basic * (CB->arg_size() + 1);
}
@ -869,6 +856,17 @@ public:
switch (Opcode) {
default:
break;
case Instruction::Call: {
assert(isa<IntrinsicInst>(U) && "Unexpected non-intrinsic call");
auto *Intrinsic = cast<IntrinsicInst>(U);
// FIXME: We shouldn't have this exception for RecipThroughput.
if (CostKind == TTI::TCK_RecipThroughput) {
IntrinsicCostAttributes CostAttrs(*Intrinsic);
return TargetTTI->getIntrinsicInstrCost(CostAttrs, CostKind);
}
IntrinsicCostAttributes CostAttrs(Intrinsic->getIntrinsicID(), *CB);
return TargetTTI->getIntrinsicInstrCost(CostAttrs, CostKind);
}
case Instruction::Br:
case Instruction::Ret:
case Instruction::PHI: