diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h --- a/llvm/include/llvm/Analysis/TargetTransformInfo.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h @@ -1092,15 +1092,17 @@ /// \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. @@ -1567,12 +1569,13 @@ 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) = 0; virtual int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, @@ -2031,13 +2034,15 @@ 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) override { diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -469,10 +469,10 @@ 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; @@ -507,8 +507,9 @@ 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 --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -739,10 +739,10 @@ 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; @@ -858,7 +858,7 @@ 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, @@ -867,8 +867,8 @@ // 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 Num = cast(DstVTy)->getNumElements(); + InstructionCost Cost = thisT()->getCastInstrCost( Opcode, Dst->getScalarType(), Src->getScalarType(), CCH, CostKind, I); // Return the cost of multiple scalar invocation plus the cost of @@ -889,8 +889,8 @@ 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(), @@ -1924,8 +1924,10 @@ // %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); @@ -2047,8 +2049,8 @@ 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 --- a/llvm/lib/Analysis/TargetTransformInfo.cpp +++ b/llvm/lib/Analysis/TargetTransformInfo.cpp @@ -763,21 +763,21 @@ 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.h b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h @@ -132,12 +132,13 @@ 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); diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -343,10 +343,11 @@ 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 @@ } // 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 @@ 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 @@ // 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/ARM/ARMTargetTransformInfo.h b/llvm/lib/Target/ARM/ARMTargetTransformInfo.h --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.h +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.h @@ -201,9 +201,10 @@ int getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind); - 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/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp @@ -391,15 +391,16 @@ return BaseT::getCFInstrCost(Opcode, CostKind); } -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/Hexagon/HexagonTargetTransformInfo.h b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h --- a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h +++ b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h @@ -147,10 +147,10 @@ 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/Hexagon/HexagonTargetTransformInfo.cpp b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp --- a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp +++ b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp @@ -278,10 +278,11 @@ 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/PowerPC/PPCTargetTransformInfo.h b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h --- a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h +++ b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h @@ -97,7 +97,8 @@ 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 @@ 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); int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, diff --git a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp --- a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp +++ b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp @@ -940,8 +940,9 @@ // 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 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 @@ // 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) { @@ -1007,13 +1009,15 @@ return CostKind == TTI::TCK_RecipThroughput ? 0 : 1; } -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) @@ -1030,7 +1034,7 @@ // 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) { @@ -1040,7 +1044,7 @@ 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). @@ -1055,7 +1059,7 @@ 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(); @@ -1072,7 +1076,7 @@ // 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. @@ -1117,7 +1121,7 @@ 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/SystemZ/SystemZTargetTransformInfo.h b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h --- a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h +++ b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h @@ -93,9 +93,10 @@ 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/SystemZ/SystemZTargetTransformInfo.cpp b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp --- a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp +++ b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp @@ -713,13 +713,14 @@ 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 @@ // 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/X86/X86TargetTransformInfo.h b/llvm/lib/Target/X86/X86TargetTransformInfo.h --- a/llvm/lib/Target/X86/X86TargetTransformInfo.h +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.h @@ -129,9 +129,10 @@ 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/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp --- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp @@ -1400,15 +1400,16 @@ 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 @@ 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/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7009,7 +7009,7 @@ /*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 @@ 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 =