From 92d8421f49047c7e67d101bc0355dc25d66f2a16 Mon Sep 17 00:00:00 2001 From: Sander de Smalen Date: Thu, 21 Jan 2021 13:40:22 +0000 Subject: [PATCH] [TTI] NFC: Change getCastInstrCost and getExtractWithExtendCost to return InstructionCost This patch migrates the TTI cost interfaces to return an InstructionCost. See this patch for the introduction of the type: https://reviews.llvm.org/D91174 See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2020-November/146408.html Reviewed By: dmgreen Differential Revision: https://reviews.llvm.org/D100199 --- llvm/include/llvm/Analysis/TargetTransformInfo.h | 39 ++++++++++++---------- .../llvm/Analysis/TargetTransformInfoImpl.h | 13 ++++---- llvm/include/llvm/CodeGen/BasicTTIImpl.h | 26 ++++++++------- llvm/lib/Analysis/TargetTransformInfo.cpp | 18 +++++----- .../Target/AArch64/AArch64TargetTransformInfo.cpp | 21 +++++++----- .../Target/AArch64/AArch64TargetTransformInfo.h | 11 +++--- llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp | 11 +++--- llvm/lib/Target/ARM/ARMTargetTransformInfo.h | 7 ++-- .../Target/Hexagon/HexagonTargetTransformInfo.cpp | 9 ++--- .../Target/Hexagon/HexagonTargetTransformInfo.h | 8 ++--- llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp | 34 ++++++++++--------- llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h | 10 +++--- .../Target/SystemZ/SystemZTargetTransformInfo.cpp | 15 +++++---- .../Target/SystemZ/SystemZTargetTransformInfo.h | 7 ++-- llvm/lib/Target/X86/X86TargetTransformInfo.cpp | 18 +++++----- llvm/lib/Target/X86/X86TargetTransformInfo.h | 7 ++-- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 4 +-- 17 files changed, 142 insertions(+), 116 deletions(-) diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h index e966433..cacf224 100644 --- a/llvm/include/llvm/Analysis/TargetTransformInfo.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h @@ -1095,15 +1095,17 @@ public: /// \return The expected cost of cast instructions, such as bitcast, trunc, /// zext, etc. If there is an existing instruction that holds Opcode, it /// may be passed in the 'I' parameter. - int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, - TTI::TargetCostKind CostKind = TTI::TCK_SizeAndLatency, - const Instruction *I = nullptr) const; + InstructionCost + getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind = TTI::TCK_SizeAndLatency, + const Instruction *I = nullptr) const; /// \return The expected cost of a sign- or zero-extended vector extract. Use /// -1 to indicate that there is no information about the index value. - int getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy, - unsigned Index = -1) const; + InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst, + VectorType *VecTy, + unsigned Index = -1) const; /// \return The expected cost of control-flow related instructions such as /// Phi, Ret, Br, Switch. @@ -1572,12 +1574,13 @@ public: virtual int getShuffleCost(ShuffleKind Kind, VectorType *Tp, ArrayRef Mask, int Index, VectorType *SubTp) = 0; - virtual int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - CastContextHint CCH, - TTI::TargetCostKind CostKind, - const Instruction *I) = 0; - virtual int getExtractWithExtendCost(unsigned Opcode, Type *Dst, - VectorType *VecTy, unsigned Index) = 0; + virtual InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, + Type *Src, CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I) = 0; + virtual InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst, + VectorType *VecTy, + unsigned Index) = 0; virtual int getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I = nullptr) = 0; virtual int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, @@ -2039,13 +2042,15 @@ public: int Index, VectorType *SubTp) override { return Impl.getShuffleCost(Kind, Tp, Mask, Index, SubTp); } - int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - CastContextHint CCH, TTI::TargetCostKind CostKind, - const Instruction *I) override { + InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, + CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I) override { return Impl.getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I); } - int getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy, - unsigned Index) override { + InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst, + VectorType *VecTy, + unsigned Index) override { return Impl.getExtractWithExtendCost(Opcode, Dst, VecTy, Index); } int getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h index af8cab3..98ffaa3 100644 --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -472,10 +472,10 @@ public: return 1; } - unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, - TTI::TargetCostKind CostKind, - const Instruction *I) const { + InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I) const { switch (Opcode) { default: break; @@ -510,8 +510,9 @@ public: return 1; } - unsigned getExtractWithExtendCost(unsigned Opcode, Type *Dst, - VectorType *VecTy, unsigned Index) const { + InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst, + VectorType *VecTy, + unsigned Index) const { return 1; } diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h index 9244cf9..84dbc73 100644 --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -765,10 +765,10 @@ public: llvm_unreachable("Unknown TTI::ShuffleKind"); } - unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, - TTI::TargetCostKind CostKind, - const Instruction *I = nullptr) { + InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I = nullptr) { if (BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I) == 0) return 0; @@ -884,7 +884,7 @@ public: Type *SplitSrcTy = VectorType::getHalfElementsVectorType(SrcVTy); T *TTI = static_cast(this); // If both types need to be split then the split is free. - unsigned SplitCost = + InstructionCost SplitCost = (!SplitSrc || !SplitDst) ? TTI->getVectorSplitCost() : 0; return SplitCost + (2 * TTI->getCastInstrCost(Opcode, SplitDstTy, SplitSrcTy, CCH, @@ -894,7 +894,7 @@ public: // In other cases where the source or destination are illegal, assume // the operation will get scalarized. unsigned Num = cast(DstVTy)->getNumElements(); - unsigned Cost = thisT()->getCastInstrCost( + InstructionCost Cost = thisT()->getCastInstrCost( Opcode, Dst->getScalarType(), Src->getScalarType(), CCH, CostKind, I); // Return the cost of multiple scalar invocation plus the cost of @@ -915,8 +915,8 @@ public: llvm_unreachable("Unhandled cast"); } - unsigned getExtractWithExtendCost(unsigned Opcode, Type *Dst, - VectorType *VecTy, unsigned Index) { + InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst, + VectorType *VecTy, unsigned Index) { return thisT()->getVectorInstrCost(Instruction::ExtractElement, VecTy, Index) + thisT()->getCastInstrCost(Opcode, Dst, VecTy->getElementType(), @@ -1951,8 +1951,10 @@ public: // %val = bitcast to iReduxWidth // %res = cmp eq iReduxWidth %val, 11111 Type *ValTy = IntegerType::get(Ty->getContext(), NumVecElts); - return thisT()->getCastInstrCost(Instruction::BitCast, ValTy, Ty, - TTI::CastContextHint::None, CostKind) + + return *thisT() + ->getCastInstrCost(Instruction::BitCast, ValTy, Ty, + TTI::CastContextHint::None, CostKind) + .getValue() + thisT()->getCmpSelInstrCost(Instruction::ICmp, ValTy, CmpInst::makeCmpResultType(ValTy), CmpInst::BAD_ICMP_PREDICATE, CostKind); @@ -2074,8 +2076,8 @@ public: VectorType *ExtTy = VectorType::get(ResTy, Ty); unsigned RedCost = thisT()->getArithmeticReductionCost( Instruction::Add, ExtTy, false, CostKind); - unsigned MulCost = 0; - unsigned ExtCost = thisT()->getCastInstrCost( + InstructionCost MulCost = 0; + InstructionCost ExtCost = thisT()->getCastInstrCost( IsUnsigned ? Instruction::ZExt : Instruction::SExt, ExtTy, Ty, TTI::CastContextHint::None, CostKind); if (IsMLA) { diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp index 74c0a38..7d71d8b 100644 --- a/llvm/lib/Analysis/TargetTransformInfo.cpp +++ b/llvm/lib/Analysis/TargetTransformInfo.cpp @@ -768,21 +768,21 @@ TargetTransformInfo::getCastContextHint(const Instruction *I) { return TTI::CastContextHint::None; } -int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - CastContextHint CCH, - TTI::TargetCostKind CostKind, - const Instruction *I) const { +InstructionCost TargetTransformInfo::getCastInstrCost( + unsigned Opcode, Type *Dst, Type *Src, CastContextHint CCH, + TTI::TargetCostKind CostKind, const Instruction *I) const { assert((I == nullptr || I->getOpcode() == Opcode) && "Opcode should reflect passed instruction."); - int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I); + InstructionCost Cost = + TTIImpl->getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I); assert(Cost >= 0 && "TTI should not produce negative costs!"); return Cost; } -int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst, - VectorType *VecTy, - unsigned Index) const { - int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index); +InstructionCost TargetTransformInfo::getExtractWithExtendCost( + unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index) const { + InstructionCost Cost = + TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index); assert(Cost >= 0 && "TTI should not produce negative costs!"); return Cost; } diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp index 148239b..aaa86ad 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -343,10 +343,11 @@ bool AArch64TTIImpl::isWideningInstruction(Type *DstTy, unsigned Opcode, return NumDstEls == NumSrcEls && 2 * SrcElTySize == DstElTySize; } -int AArch64TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, - TTI::TargetCostKind CostKind, - const Instruction *I) { +InstructionCost AArch64TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, + Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I) { int ISD = TLI->InstructionOpcodeToISD(Opcode); assert(ISD && "Invalid opcode"); @@ -371,7 +372,7 @@ int AArch64TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, } // TODO: Allow non-throughput costs that aren't binary. - auto AdjustCost = [&CostKind](int Cost) { + auto AdjustCost = [&CostKind](InstructionCost Cost) -> InstructionCost { if (CostKind != TTI::TCK_RecipThroughput) return Cost == 0 ? 0 : 1; return Cost; @@ -593,9 +594,10 @@ int AArch64TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I)); } -int AArch64TTIImpl::getExtractWithExtendCost(unsigned Opcode, Type *Dst, - VectorType *VecTy, - unsigned Index) { +InstructionCost AArch64TTIImpl::getExtractWithExtendCost(unsigned Opcode, + Type *Dst, + VectorType *VecTy, + unsigned Index) { // Make sure we were given a valid extend opcode. assert((Opcode == Instruction::SExt || Opcode == Instruction::ZExt) && @@ -610,7 +612,8 @@ int AArch64TTIImpl::getExtractWithExtendCost(unsigned Opcode, Type *Dst, // Get the cost for the extract. We compute the cost (if any) for the extend // below. - auto Cost = getVectorInstrCost(Instruction::ExtractElement, VecTy, Index); + InstructionCost Cost = + getVectorInstrCost(Instruction::ExtractElement, VecTy, Index); // Legalize the types. auto VecLT = TLI->getTypeLegalizationCost(DL, VecTy); diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h index 7a6cfd3..44168183 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h @@ -132,12 +132,13 @@ public: Align Alignment, TTI::TargetCostKind CostKind, const Instruction *I = nullptr); - int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, - const Instruction *I = nullptr); + InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I = nullptr); - int getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy, - unsigned Index); + InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst, + VectorType *VecTy, unsigned Index); unsigned getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I = nullptr); diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp index 7a8ae94..6b1056f 100644 --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp @@ -392,15 +392,16 @@ int ARMTTIImpl::getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, return BaseT::getCFInstrCost(Opcode, CostKind, I); } -int ARMTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, - TTI::TargetCostKind CostKind, - const Instruction *I) { +InstructionCost ARMTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, + Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I) { int ISD = TLI->InstructionOpcodeToISD(Opcode); assert(ISD && "Invalid opcode"); // TODO: Allow non-throughput costs that aren't binary. - auto AdjustCost = [&CostKind](int Cost) { + auto AdjustCost = [&CostKind](InstructionCost Cost) -> InstructionCost { if (CostKind != TTI::TCK_RecipThroughput) return Cost == 0 ? 0 : 1; return Cost; diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.h b/llvm/lib/Target/ARM/ARMTargetTransformInfo.h index dda1b6d..86c35a2 100644 --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.h +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.h @@ -201,9 +201,10 @@ public: int getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I = nullptr); - int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, - const Instruction *I = nullptr); + InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I = nullptr); int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, diff --git a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp index 14762db..4c60af3 100644 --- a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp +++ b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp @@ -278,10 +278,11 @@ unsigned HexagonTTIImpl::getArithmeticInstrCost( Opd1PropInfo, Opd2PropInfo, Args, CxtI); } -unsigned HexagonTTIImpl::getCastInstrCost(unsigned Opcode, Type *DstTy, - Type *SrcTy, TTI::CastContextHint CCH, - TTI::TargetCostKind CostKind, - const Instruction *I) { +InstructionCost HexagonTTIImpl::getCastInstrCost(unsigned Opcode, Type *DstTy, + Type *SrcTy, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I) { if (SrcTy->isFPOrFPVectorTy() || DstTy->isFPOrFPVectorTy()) { unsigned SrcN = SrcTy->isFPOrFPVectorTy() ? getTypeNumElements(SrcTy) : 0; unsigned DstN = DstTy->isFPOrFPVectorTy() ? getTypeNumElements(DstTy) : 0; diff --git a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h index e4c1fac..4d341f8 100644 --- a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h +++ b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h @@ -147,10 +147,10 @@ public: TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None, ArrayRef Args = ArrayRef(), const Instruction *CxtI = nullptr); - unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, - TTI::TargetCostKind CostKind, - const Instruction *I = nullptr); + InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I = nullptr); unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index); unsigned getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, diff --git a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp index 8be9117..2cdfd02 100644 --- a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp +++ b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp @@ -940,8 +940,9 @@ unsigned PPCTTIImpl::getMaxInterleaveFactor(unsigned VF) { // Adjust the cost of vector instructions on targets which there is overlap // between the vector and scalar units, thereby reducing the overall throughput // of vector code wrt. scalar code. -int PPCTTIImpl::vectorCostAdjustment(int Cost, unsigned Opcode, Type *Ty1, - Type *Ty2) { +InstructionCost PPCTTIImpl::vectorCostAdjustment(InstructionCost Cost, + unsigned Opcode, Type *Ty1, + Type *Ty2) { if (!ST->vectorsUseTwoUnits() || !Ty1->isVectorTy()) return Cost; @@ -983,7 +984,7 @@ int PPCTTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty, int Cost = BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info, Opd1PropInfo, Opd2PropInfo); - return vectorCostAdjustment(Cost, Opcode, Ty, nullptr); + return *vectorCostAdjustment(Cost, Opcode, Ty, nullptr).getValue(); } int PPCTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, @@ -996,8 +997,9 @@ int PPCTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, // instruction). We need one such shuffle instruction for each actual // register (this is not true for arbitrary shuffles, but is true for the // structured types of shuffles covered by TTI::ShuffleKind). - return vectorCostAdjustment(LT.first, Instruction::ShuffleVector, Tp, - nullptr); + return *vectorCostAdjustment(LT.first, Instruction::ShuffleVector, Tp, + nullptr) + .getValue(); } int PPCTTIImpl::getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, @@ -1008,13 +1010,15 @@ int PPCTTIImpl::getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, return 0; } -int PPCTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, - TTI::TargetCostKind CostKind, - const Instruction *I) { +InstructionCost PPCTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, + Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I) { assert(TLI->InstructionOpcodeToISD(Opcode) && "Invalid opcode"); - int Cost = BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I); + InstructionCost Cost = + BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I); Cost = vectorCostAdjustment(Cost, Opcode, Dst, Src); // TODO: Allow non-throughput costs that aren't binary. if (CostKind != TTI::TCK_RecipThroughput) @@ -1031,7 +1035,7 @@ int PPCTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, // TODO: Handle other cost kinds. if (CostKind != TTI::TCK_RecipThroughput) return Cost; - return vectorCostAdjustment(Cost, Opcode, ValTy, nullptr); + return *vectorCostAdjustment(Cost, Opcode, ValTy, nullptr).getValue(); } int PPCTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) { @@ -1041,7 +1045,7 @@ int PPCTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) { assert(ISD && "Invalid opcode"); int Cost = BaseT::getVectorInstrCost(Opcode, Val, Index); - Cost = vectorCostAdjustment(Cost, Opcode, Val, nullptr); + Cost = *vectorCostAdjustment(Cost, Opcode, Val, nullptr).getValue(); if (ST->hasVSX() && Val->getScalarType()->isDoubleTy()) { // Double-precision scalars are already located in index #0 (or #1 if LE). @@ -1056,7 +1060,7 @@ int PPCTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) { if (ISD == ISD::INSERT_VECTOR_ELT) // A move-to VSR and a permute/insert. Assume vector operation cost // for both (cost will be 2x on P9). - return vectorCostAdjustment(2, Opcode, Val, nullptr); + return *vectorCostAdjustment(2, Opcode, Val, nullptr).getValue(); // It's an extract. Maybe we can do a cheap move-from VSR. unsigned EltSize = Val->getScalarSizeInBits(); @@ -1073,7 +1077,7 @@ int PPCTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) { // We need a vector extract (or mfvsrld). Assume vector operation cost. // The cost of the load constant for a vector extract is disregarded // (invariant, easily schedulable). - return vectorCostAdjustment(1, Opcode, Val, nullptr); + return *vectorCostAdjustment(1, Opcode, Val, nullptr).getValue(); } else if (ST->hasDirectMove()) // Assume permute has standard cost. @@ -1118,7 +1122,7 @@ int PPCTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src, if (CostKind != TTI::TCK_RecipThroughput) return Cost; - Cost = vectorCostAdjustment(Cost, Opcode, Src, nullptr); + Cost = *vectorCostAdjustment(Cost, Opcode, Src, nullptr).getValue(); bool IsAltivecType = ST->hasAltivec() && (LT.second == MVT::v16i8 || LT.second == MVT::v8i16 || diff --git a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h index acd453f..74ea7ec 100644 --- a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h +++ b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h @@ -97,7 +97,8 @@ public: unsigned getCacheLineSize() const override; unsigned getPrefetchDistance() const override; unsigned getMaxInterleaveFactor(unsigned VF); - int vectorCostAdjustment(int Cost, unsigned Opcode, Type *Ty1, Type *Ty2); + InstructionCost vectorCostAdjustment(InstructionCost Cost, unsigned Opcode, + Type *Ty1, Type *Ty2); int getArithmeticInstrCost( unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, @@ -109,9 +110,10 @@ public: const Instruction *CxtI = nullptr); int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, ArrayRef Mask, int Index, Type *SubTp); - int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, - const Instruction *I = nullptr); + InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I = nullptr); int getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I = nullptr); int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, diff --git a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp index 4339893..826faf6 100644 --- a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp +++ b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp @@ -713,13 +713,14 @@ getBoolVecToIntConversionCost(unsigned Opcode, Type *Dst, return Cost; } -int SystemZTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, - TTI::TargetCostKind CostKind, - const Instruction *I) { +InstructionCost SystemZTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, + Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I) { // FIXME: Can the logic below also be used for these cost kinds? if (CostKind == TTI::TCK_CodeSize || CostKind == TTI::TCK_SizeAndLatency) { - int BaseCost = BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I); + auto BaseCost = BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I); return BaseCost == 0 ? BaseCost : 1; } @@ -807,9 +808,9 @@ int SystemZTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, // Return the cost of multiple scalar invocation plus the cost of // inserting and extracting the values. Base implementation does not // realize float->int gets scalarized. - unsigned ScalarCost = getCastInstrCost( + InstructionCost ScalarCost = getCastInstrCost( Opcode, Dst->getScalarType(), Src->getScalarType(), CCH, CostKind); - unsigned TotCost = VF * ScalarCost; + InstructionCost TotCost = VF * ScalarCost; bool NeedsInserts = true, NeedsExtracts = true; // FP128 registers do not get inserted or extracted. if (DstScalarBits == 128 && diff --git a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h index a23fb7766..7439703 100644 --- a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h +++ b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h @@ -93,9 +93,10 @@ public: unsigned getVectorBitmaskConversionCost(Type *SrcTy, Type *DstTy); unsigned getBoolVecToIntConversionCost(unsigned Opcode, Type *Dst, const Instruction *I); - int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, - const Instruction *I = nullptr); + InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I = nullptr); int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp index 9b3ad45..e9abfbb 100644 --- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp @@ -1400,15 +1400,16 @@ int X86TTIImpl::getShuffleCost(TTI::ShuffleKind Kind, VectorType *BaseTp, return BaseT::getShuffleCost(Kind, BaseTp, Mask, Index, SubTp); } -int X86TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, - TTI::TargetCostKind CostKind, - const Instruction *I) { +InstructionCost X86TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, + Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I) { int ISD = TLI->InstructionOpcodeToISD(Opcode); assert(ISD && "Invalid opcode"); // TODO: Allow non-throughput costs that aren't binary. - auto AdjustCost = [&CostKind](int Cost) { + auto AdjustCost = [&CostKind](InstructionCost Cost) -> InstructionCost { if (CostKind != TTI::TCK_RecipThroughput) return Cost == 0 ? 0 : 1; return Cost; @@ -3412,9 +3413,10 @@ int X86TTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *ValTy, if (ISD == ISD::MUL && MTy.getScalarType() == MVT::i8) { auto *WideSclTy = IntegerType::get(ValVTy->getContext(), 16); auto *WideVecTy = FixedVectorType::get(WideSclTy, ValVTy->getNumElements()); - return getCastInstrCost(Instruction::ZExt, WideVecTy, ValTy, - TargetTransformInfo::CastContextHint::None, - CostKind) + + return *getCastInstrCost(Instruction::ZExt, WideVecTy, ValTy, + TargetTransformInfo::CastContextHint::None, + CostKind) + .getValue() + getArithmeticReductionCost(Opcode, WideVecTy, IsPairwise, CostKind); } diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.h b/llvm/lib/Target/X86/X86TargetTransformInfo.h index 3fba7fe..8c37138 100644 --- a/llvm/lib/Target/X86/X86TargetTransformInfo.h +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.h @@ -129,9 +129,10 @@ public: const Instruction *CxtI = nullptr); int getShuffleCost(TTI::ShuffleKind Kind, VectorType *Tp, ArrayRef Mask, int Index, VectorType *SubTp); - int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, - TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, - const Instruction *I = nullptr); + InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, + TTI::CastContextHint CCH, + TTI::TargetCostKind CostKind, + const Instruction *I = nullptr); int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index d708330..02ccbfc 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7009,7 +7009,7 @@ InstructionCost LoopVectorizationCostModel::getReductionPatternCost( /*IsMLA=*/false, IsUnsigned, RdxDesc.getRecurrenceType(), ExtType, CostKind); - unsigned ExtCost = + InstructionCost ExtCost = TTI.getCastInstrCost(RedOp->getOpcode(), VectorTy, ExtType, TTI::CastContextHint::None, CostKind, RedOp); if (RedCost.isValid() && RedCost < BaseCost + ExtCost) @@ -7025,7 +7025,7 @@ InstructionCost LoopVectorizationCostModel::getReductionPatternCost( bool IsUnsigned = isa(Op0); auto *ExtType = VectorType::get(Op0->getOperand(0)->getType(), VectorTy); // reduce(mul(ext, ext)) - unsigned ExtCost = + InstructionCost ExtCost = TTI.getCastInstrCost(Op0->getOpcode(), VectorTy, ExtType, TTI::CastContextHint::None, CostKind, Op0); InstructionCost MulCost = -- 2.7.4