Index: llvm/include/llvm/Analysis/TargetTransformInfo.h =================================================================== --- llvm/include/llvm/Analysis/TargetTransformInfo.h +++ llvm/include/llvm/Analysis/TargetTransformInfo.h @@ -702,6 +702,9 @@ /// Return true if this type is legal. bool isTypeLegal(Type *Ty) const; + /// Returns the estimated number of registers required to represent \p Ty. + unsigned getRegUsageForType(Type *Ty) const; + /// Return true if switches should be turned into lookup tables for the /// target. bool shouldBuildLookupTables() const; @@ -1436,6 +1439,7 @@ virtual bool isProfitableToHoist(Instruction *I) = 0; virtual bool useAA() = 0; virtual bool isTypeLegal(Type *Ty) = 0; + virtual unsigned getRegUsageForType(Type *Ty) = 0; virtual bool shouldBuildLookupTables() = 0; virtual bool shouldBuildLookupTablesForConstant(Constant *C) = 0; virtual bool useColdCCForColdCall(Function &F) = 0; @@ -1792,6 +1796,9 @@ } bool useAA() override { return Impl.useAA(); } bool isTypeLegal(Type *Ty) override { return Impl.isTypeLegal(Ty); } + unsigned getRegUsageForType(Type *Ty) override { + return Impl.getRegUsageForType(Ty); + } bool shouldBuildLookupTables() override { return Impl.shouldBuildLookupTables(); } Index: llvm/include/llvm/Analysis/TargetTransformInfoImpl.h =================================================================== --- llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -257,6 +257,8 @@ bool isTypeLegal(Type *Ty) { return false; } + unsigned getRegUsageForType(Type *Ty) { return 0; } + bool shouldBuildLookupTables() { return true; } bool shouldBuildLookupTablesForConstant(Constant *C) { return true; } Index: llvm/include/llvm/CodeGen/BasicTTIImpl.h =================================================================== --- llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -293,6 +293,10 @@ return getTLI()->isTypeLegal(VT); } + unsigned getRegUsageForType(Type *Ty) { + return getTLI()->getTypeLegalizationCost(DL, Ty).first; + } + int getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef Operands) { return BaseT::getGEPCost(PointeeType, Ptr, Operands); Index: llvm/lib/Analysis/TargetTransformInfo.cpp =================================================================== --- llvm/lib/Analysis/TargetTransformInfo.cpp +++ llvm/lib/Analysis/TargetTransformInfo.cpp @@ -478,6 +478,10 @@ return TTIImpl->isTypeLegal(Ty); } +unsigned TargetTransformInfo::getRegUsageForType(Type *Ty) const { + return TTIImpl->getRegUsageForType(Ty); +} + bool TargetTransformInfo::shouldBuildLookupTables() const { return TTIImpl->shouldBuildLookupTables(); } Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -5776,8 +5776,6 @@ unsigned MaxSafeDepDist = -1U; if (Legal->getMaxSafeDepDistBytes() != -1U) MaxSafeDepDist = Legal->getMaxSafeDepDistBytes() * 8; - unsigned WidestRegister = - std::min(TTI.getRegisterBitWidth(true), MaxSafeDepDist); const DataLayout &DL = TheFunction->getParent()->getDataLayout(); SmallVector RUs(VFs.size()); @@ -5786,13 +5784,10 @@ LLVM_DEBUG(dbgs() << "LV(REG): Calculating max register usage:\n"); // A lambda that gets the register usage for the given type and VF. - auto GetRegUsage = [&DL, WidestRegister](Type *Ty, ElementCount VF) { + auto GetRegUsage = [&DL, &TTI=TTI](Type *Ty, ElementCount VF) { if (Ty->isTokenTy()) return 0U; - unsigned TypeSize = DL.getTypeSizeInBits(Ty->getScalarType()); - assert(!VF.isScalable() && "scalable vectors not yet supported."); - return std::max(1, VF.getKnownMinValue() * TypeSize / - WidestRegister); + return TTI.getRegUsageForType(VectorType::get(Ty, VF)); }; for (unsigned int i = 0, s = IdxToInstr.size(); i < s; ++i) {