diff --git a/llvm/include/llvm/Support/TypeSize.h b/llvm/include/llvm/Support/TypeSize.h --- a/llvm/include/llvm/Support/TypeSize.h +++ b/llvm/include/llvm/Support/TypeSize.h @@ -229,6 +229,10 @@ TypeSize operator/(int64_t RHS) const { return { MinSize / RHS, IsScalable }; } + + TypeSize NextPowerOf2() const { + return TypeSize(llvm::NextPowerOf2(MinSize), IsScalable); + } }; /// Returns a TypeSize with a known minimum size that is the next integer diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp --- a/llvm/lib/CodeGen/TargetLoweringBase.cpp +++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp @@ -1474,14 +1474,14 @@ MVT DestVT = getRegisterType(Context, NewVT); RegisterVT = DestVT; - unsigned NewVTSize = NewVT.getSizeInBits(); - // Convert sizes such as i33 to i64. - if (!isPowerOf2_32(NewVTSize)) - NewVTSize = NextPowerOf2(NewVTSize); - - if (EVT(DestVT).bitsLT(NewVT)) // Value is expanded, e.g. i64 -> i16. + if (EVT(DestVT).bitsLT(NewVT)) { // Value is expanded, e.g. i64 -> i16. + TypeSize NewVTSize = NewVT.getSizeInBits(); + // Convert sizes such as i33 to i64. + if (!isPowerOf2_32(NewVTSize.getKnownMinSize())) + NewVTSize = NewVTSize.NextPowerOf2(); return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits()); + } // Otherwise, promotion or legal types use the same number of registers as // the vector decimated to the appropriate level.