[SLPVectorizer] NFC: Migrate getVectorCallCosts to use InstructionCost.

This change also changes getReductionCost to return InstructionCost,
and it simplifies two expressions by removing a redundant 'isValid' check.
This commit is contained in:
Sander de Smalen 2021-01-20 09:10:24 +00:00
parent 1b780cf32e
commit 171d12489f
1 changed files with 9 additions and 8 deletions

View File

@ -3411,21 +3411,21 @@ bool BoUpSLP::areAllUsersVectorized(Instruction *I) const {
}); });
} }
static std::pair<unsigned, unsigned> static std::pair<InstructionCost, InstructionCost>
getVectorCallCosts(CallInst *CI, FixedVectorType *VecTy, getVectorCallCosts(CallInst *CI, FixedVectorType *VecTy,
TargetTransformInfo *TTI, TargetLibraryInfo *TLI) { TargetTransformInfo *TTI, TargetLibraryInfo *TLI) {
Intrinsic::ID ID = getVectorIntrinsicIDForCall(CI, TLI); Intrinsic::ID ID = getVectorIntrinsicIDForCall(CI, TLI);
// Calculate the cost of the scalar and vector calls. // Calculate the cost of the scalar and vector calls.
IntrinsicCostAttributes CostAttrs(ID, *CI, VecTy->getElementCount()); IntrinsicCostAttributes CostAttrs(ID, *CI, VecTy->getElementCount());
int IntrinsicCost = auto IntrinsicCost =
TTI->getIntrinsicInstrCost(CostAttrs, TTI::TCK_RecipThroughput); TTI->getIntrinsicInstrCost(CostAttrs, TTI::TCK_RecipThroughput);
auto Shape = VFShape::get(*CI, ElementCount::getFixed(static_cast<unsigned>( auto Shape = VFShape::get(*CI, ElementCount::getFixed(static_cast<unsigned>(
VecTy->getNumElements())), VecTy->getNumElements())),
false /*HasGlobalPred*/); false /*HasGlobalPred*/);
Function *VecFunc = VFDatabase(*CI).getVectorizedFunction(Shape); Function *VecFunc = VFDatabase(*CI).getVectorizedFunction(Shape);
int LibCost = IntrinsicCost; auto LibCost = IntrinsicCost;
if (!CI->isNoBuiltin() && VecFunc) { if (!CI->isNoBuiltin() && VecFunc) {
// Calculate the cost of the vector library call. // Calculate the cost of the vector library call.
SmallVector<Type *, 4> VecTys; SmallVector<Type *, 4> VecTys;
@ -5994,7 +5994,7 @@ bool SLPVectorizerPass::vectorizeStoreChain(ArrayRef<Value *> Chain, BoUpSLP &R,
InstructionCost Cost = R.getTreeCost(); InstructionCost Cost = R.getTreeCost();
LLVM_DEBUG(dbgs() << "SLP: Found cost = " << Cost << " for VF =" << VF << "\n"); LLVM_DEBUG(dbgs() << "SLP: Found cost = " << Cost << " for VF =" << VF << "\n");
if (Cost.isValid() && Cost < -SLPCostThreshold) { if (Cost < -SLPCostThreshold) {
LLVM_DEBUG(dbgs() << "SLP: Decided to vectorize cost = " << Cost << "\n"); LLVM_DEBUG(dbgs() << "SLP: Decided to vectorize cost = " << Cost << "\n");
using namespace ore; using namespace ore;
@ -6295,7 +6295,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
MinCost = std::min(MinCost, Cost); MinCost = std::min(MinCost, Cost);
if (Cost.isValid() && Cost < -SLPCostThreshold) { if (Cost < -SLPCostThreshold) {
LLVM_DEBUG(dbgs() << "SLP: Vectorizing list at cost:" << Cost << ".\n"); LLVM_DEBUG(dbgs() << "SLP: Vectorizing list at cost:" << Cost << ".\n");
R.getORE()->emit(OptimizationRemark(SV_NAME, "VectorizedList", R.getORE()->emit(OptimizationRemark(SV_NAME, "VectorizedList",
cast<Instruction>(Ops[0])) cast<Instruction>(Ops[0]))
@ -7007,11 +7007,12 @@ public:
private: private:
/// Calculate the cost of a reduction. /// Calculate the cost of a reduction.
int getReductionCost(TargetTransformInfo *TTI, Value *FirstReducedVal, InstructionCost getReductionCost(TargetTransformInfo *TTI,
Value *FirstReducedVal,
unsigned ReduxWidth) { unsigned ReduxWidth) {
Type *ScalarTy = FirstReducedVal->getType(); Type *ScalarTy = FirstReducedVal->getType();
FixedVectorType *VectorTy = FixedVectorType::get(ScalarTy, ReduxWidth); FixedVectorType *VectorTy = FixedVectorType::get(ScalarTy, ReduxWidth);
int VectorCost, ScalarCost; InstructionCost VectorCost, ScalarCost;
switch (RdxKind) { switch (RdxKind) {
case RecurKind::Add: case RecurKind::Add:
case RecurKind::Mul: case RecurKind::Mul: