[llvm] [NFC][LLVM] Remove TypeSize::multiplyCoefficientBy(). (PR #221215)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 4 06:23:31 PDT 2026
https://github.com/paulwalker-arm updated https://github.com/llvm/llvm-project/pull/221215
>From 649f40dade876ea940626c6e6f91d8f1ae85132f Mon Sep 17 00:00:00 2001
From: Paul Walker <paul.walker at arm.com>
Date: Fri, 4 Sep 2026 12:06:02 +0000
Subject: [PATCH 1/2] [NFC][LLVM] Remove TypeSize::multiplyCoefficientBy().
TypeSize implements operator*() that does the same operation.
---
llvm/include/llvm/CodeGenTypes/LowLevelType.h | 3 +--
llvm/include/llvm/IR/DerivedTypes.h | 6 ++---
llvm/include/llvm/Support/TypeSize.h | 12 ++++------
llvm/lib/CodeGen/GlobalISel/CallLowering.cpp | 3 +--
llvm/lib/CodeGen/GlobalISel/Utils.cpp | 4 ++--
.../SelectionDAG/LegalizeVectorTypes.cpp | 20 ++++++++--------
.../GISel/AArch64PostLegalizerCombiner.cpp | 5 ++--
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 23 ++++++++-----------
.../lib/Transforms/Vectorize/VPlanRecipes.cpp | 3 +--
.../Transforms/Vectorize/VPlanTransforms.cpp | 7 +++---
llvm/unittests/Support/TypeSizeTest.cpp | 3 +--
11 files changed, 36 insertions(+), 53 deletions(-)
diff --git a/llvm/include/llvm/CodeGenTypes/LowLevelType.h b/llvm/include/llvm/CodeGenTypes/LowLevelType.h
index 3e1bb672081dd..440c73ac05070 100644
--- a/llvm/include/llvm/CodeGenTypes/LowLevelType.h
+++ b/llvm/include/llvm/CodeGenTypes/LowLevelType.h
@@ -483,8 +483,7 @@ class LLT {
/// \p Factor elements.
LLT multiplyElements(int Factor) const {
if (isVector()) {
- return scalarOrVector(getElementCount().multiplyCoefficientBy(Factor),
- getElementType());
+ return scalarOrVector(getElementCount() * Factor, getElementType());
}
return fixed_vector(Factor, *this);
diff --git a/llvm/include/llvm/IR/DerivedTypes.h b/llvm/include/llvm/IR/DerivedTypes.h
index 572d0d5e9e5e4..79439759d2a53 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -626,9 +626,9 @@ class VectorType : public Type {
if (!SizeTy->getPrimitiveSizeInBits().isKnownMultipleOf(EltSize))
return nullptr;
- ElementCount EC = SizeTy->getElementCount()
- .multiplyCoefficientBy(SizeTy->getScalarSizeInBits())
- .divideCoefficientBy(EltSize);
+ ElementCount EC =
+ (SizeTy->getElementCount() * SizeTy->getScalarSizeInBits())
+ .divideCoefficientBy(EltSize);
return VectorType::get(EltTy->getScalarType(), EC);
}
diff --git a/llvm/include/llvm/Support/TypeSize.h b/llvm/include/llvm/Support/TypeSize.h
index 9e99ec26aeb83..7eea5e2d795ec 100644
--- a/llvm/include/llvm/Support/TypeSize.h
+++ b/llvm/include/llvm/Support/TypeSize.h
@@ -253,26 +253,22 @@ template <typename LeafTy, typename ValueTy> class FixedOrScalableQuantity {
return LeafTy::get(getKnownMinValue() / RHS, isScalable());
}
- constexpr LeafTy multiplyCoefficientBy(ScalarTy RHS) const {
- return LeafTy::get(getKnownMinValue() * RHS, isScalable());
- }
-
constexpr LeafTy coefficientNextPowerOf2() const {
return LeafTy::get(
static_cast<ScalarTy>(llvm::NextPowerOf2(getKnownMinValue())),
isScalable());
}
- /// Returns true if there exists a value X where RHS.multiplyCoefficientBy(X)
- /// will result in a value whose quantity matches our own.
+ /// Returns true if there exists a value X where RHS*X will result in a value
+ /// whose quantity matches our own.
constexpr bool
hasKnownScalarFactor(const FixedOrScalableQuantity &RHS) const {
return isScalable() == RHS.isScalable() &&
getKnownMinValue() % RHS.getKnownMinValue() == 0;
}
- /// Returns a value X where RHS.multiplyCoefficientBy(X) will result in a
- /// value whose quantity matches our own.
+ /// Returns a value X where RHS*X will result in a value whose quantity
+ /// matches our own.
constexpr ScalarTy
getKnownScalarFactor(const FixedOrScalableQuantity &RHS) const {
assert(hasKnownScalarFactor(RHS) && "Expected RHS to be a known factor!");
diff --git a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
index 90a0791a04e06..4d97001eb7420 100644
--- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
@@ -659,8 +659,7 @@ void CallLowering::buildCopyToRegs(MachineIRBuilder &B,
LLT DstTy = MRI.getType(DstRegs[0]);
LLT CoverTy = getCoverTy(SrcTy, PartTy);
if (SrcTy.isVector() && DstRegs.size() > 1) {
- TypeSize FullCoverSize =
- DstTy.getSizeInBits().multiplyCoefficientBy(DstRegs.size());
+ TypeSize FullCoverSize = DstTy.getSizeInBits() * DstRegs.size();
LLT EltTy = SrcTy.getElementType();
TypeSize EltSize = EltTy.getSizeInBits();
diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index c9f5c6248d1f1..d0cc4a823d7f5 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -1160,8 +1160,8 @@ LLT llvm::getLCMType(LLT OrigTy, LLT TargetTy) {
int GCDMinElts = std::gcd(OrigTy.getElementCount().getKnownMinValue(),
TargetTy.getElementCount().getKnownMinValue());
// Prefer the original element type.
- ElementCount Mul = OrigTy.getElementCount().multiplyCoefficientBy(
- TargetTy.getElementCount().getKnownMinValue());
+ ElementCount Mul = OrigTy.getElementCount() *
+ TargetTy.getElementCount().getKnownMinValue();
return LLT::vector(Mul.divideCoefficientBy(GCDMinElts),
OrigTy.getElementType());
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
index b0480feeb6a6d..22fc5c4546d71 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
@@ -7442,8 +7442,8 @@ void DAGTypeLegalizer::WidenVecRes_VECTOR_INTERLEAVE(SDNode *N) {
SDValue Interleaved =
DAG.getNode(ISD::VECTOR_INTERLEAVE, DL, WidenVTs, WidenOps);
- EVT PackedWidenVT = EVT::getVectorVT(*DAG.getContext(), EltVT,
- WidenEC.multiplyCoefficientBy(Factor));
+ EVT PackedWidenVT =
+ EVT::getVectorVT(*DAG.getContext(), EltVT, WidenEC * Factor);
SmallVector<SDValue, 8> Slices(Factor);
for (unsigned Idx = 0; Idx != Factor; ++Idx)
Slices[Idx] = Interleaved.getValue(Idx);
@@ -7451,8 +7451,8 @@ void DAGTypeLegalizer::WidenVecRes_VECTOR_INTERLEAVE(SDNode *N) {
SDValue Packed = DAG.getNode(ISD::CONCAT_VECTORS, DL, PackedWidenVT, Slices);
for (unsigned Idx = 0U; Idx < Factor; ++Idx) {
- SDValue Narrow = DAG.getExtractSubvector(
- DL, VT, Packed, OrigEC.multiplyCoefficientBy(Idx).getKnownMinValue());
+ SDValue Narrow = DAG.getExtractSubvector(DL, VT, Packed,
+ OrigEC.getKnownMinValue() * Idx);
SDValue Wide =
DAG.getInsertSubvector(DL, DAG.getPOISON(WidenVT), Narrow, /*Idx=*/0U);
SetWidenedVector(SDValue(N, Idx), Wide);
@@ -7490,10 +7490,9 @@ void DAGTypeLegalizer::WidenVecRes_VECTOR_DEINTERLEAVE(SDNode *N) {
// not concat the widened operands but the original ones to effectively
// generate a "packed" concated and widened vector, before extracting new
// operand vectors with the widened type.
- EVT PackedWidenVT = EVT::getVectorVT(*DAG.getContext(), EltVT,
- WidenEC.multiplyCoefficientBy(Factor));
- EVT ConcatVT = EVT::getVectorVT(*DAG.getContext(), EltVT,
- OrigEC.multiplyCoefficientBy(Factor));
+ EVT PackedWidenVT =
+ EVT::getVectorVT(*DAG.getContext(), EltVT, WidenEC * Factor);
+ EVT ConcatVT = EVT::getVectorVT(*DAG.getContext(), EltVT, OrigEC * Factor);
SDValue ConcatOp = DAG.getNode(ISD::CONCAT_VECTORS, DL, ConcatVT, N->ops());
SDValue PackedWidenVec = DAG.getInsertSubvector(
DL, DAG.getUNDEF(PackedWidenVT), ConcatOp, /*Idx=*/0U);
@@ -7501,9 +7500,8 @@ void DAGTypeLegalizer::WidenVecRes_VECTOR_DEINTERLEAVE(SDNode *N) {
// Extract the new widened operand vectors.
SmallVector<SDValue, 8> NewOps(Factor, SDValue());
for (unsigned Idx = 0U; Idx < Factor; ++Idx) {
- NewOps[Idx] = DAG.getExtractSubvector(
- DL, WidenVT, PackedWidenVec,
- WidenEC.multiplyCoefficientBy(Idx).getKnownMinValue());
+ NewOps[Idx] = DAG.getExtractSubvector(DL, WidenVT, PackedWidenVec,
+ WidenEC.getKnownMinValue() * Idx);
}
SmallVector<EVT, 8> NewVTs(Factor, WidenVT);
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
index 5858e821ae07c..6ba25ac4ffa0a 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
@@ -459,9 +459,8 @@ void applyCombineMulCMLT(MachineInstr &MI, MachineRegisterInfo &MRI,
MachineIRBuilder &B, Register &SrcReg) {
Register DstReg = MI.getOperand(0).getReg();
LLT DstTy = MRI.getType(DstReg);
- LLT HalfTy =
- DstTy.changeElementCount(DstTy.getElementCount().multiplyCoefficientBy(2))
- .changeElementSize(DstTy.getScalarSizeInBits() / 2);
+ LLT HalfTy = DstTy.changeElementCount(DstTy.getElementCount() * 2)
+ .changeElementSize(DstTy.getScalarSizeInBits() / 2);
Register ZeroVec = B.buildConstant(HalfTy, 0).getReg(0);
Register CastReg =
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index b2f684952dd90..7173c2ad3e075 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -2003,7 +2003,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
continue;
ElementCount EC = VT.getVectorElementCount();
unsigned Scale = VT.getVectorElementType() == MVT::i64 ? 8 : 4;
- MVT ArgVT = MVT::getVectorVT(MVT::i8, EC.multiplyCoefficientBy(Scale));
+ MVT ArgVT = MVT::getVectorVT(MVT::i8, EC * Scale);
setPartialReduceMLAAction(MLAOps, VT, ArgVT, Custom);
}
}
@@ -5968,8 +5968,7 @@ static SDValue getWideningSpread(SDValue V, unsigned Factor, unsigned Index,
Result = DAG.getNode(ISD::SHL, DL, WideVT, Result,
DAG.getConstant(EltBits * Index, DL, WideVT));
// Make sure to use original element type
- MVT ResultVT = MVT::getVectorVT(VT.getVectorElementType(),
- EC.multiplyCoefficientBy(Factor));
+ MVT ResultVT = MVT::getVectorVT(VT.getVectorElementType(), EC * Factor);
return DAG.getBitcast(ResultVT, Result);
}
@@ -6053,13 +6052,12 @@ static SDValue getWideningInterleave(SDValue EvenV, SDValue OddV,
// Bitcast from <vscale x n * ty*2> to <vscale x 2*n x ty>
MVT ResultContainerVT = MVT::getVectorVT(
VecVT.getVectorElementType(), // Make sure to use original type
- VecContainerVT.getVectorElementCount().multiplyCoefficientBy(2));
+ VecContainerVT.getVectorElementCount() * 2);
Interleaved = DAG.getBitcast(ResultContainerVT, Interleaved);
// Convert back to a fixed vector if needed
- MVT ResultVT =
- MVT::getVectorVT(VecVT.getVectorElementType(),
- VecVT.getVectorElementCount().multiplyCoefficientBy(2));
+ MVT ResultVT = MVT::getVectorVT(VecVT.getVectorElementType(),
+ VecVT.getVectorElementCount() * 2);
if (ResultVT.isFixedLengthVector())
Interleaved =
convertFromScalableVector(ResultVT, Interleaved, DAG, Subtarget);
@@ -14453,8 +14451,7 @@ SDValue RISCVTargetLowering::lowerVECTOR_DEINTERLEAVE(SDValue Op,
// Concatenate the vectors as one vector to deinterleave
MVT ConcatVT =
MVT::getVectorVT(VecVT.getVectorElementType(),
- VecVT.getVectorElementCount().multiplyCoefficientBy(
- PowerOf2Ceil(Factor)));
+ VecVT.getVectorElementCount() * PowerOf2Ceil(Factor));
if (Ops.size() < PowerOf2Ceil(Factor))
Ops.append(PowerOf2Ceil(Factor) - Factor, DAG.getUNDEF(VecVT));
SDValue Concat = DAG.getNode(ISD::CONCAT_VECTORS, DL, ConcatVT, Ops);
@@ -14507,8 +14504,7 @@ SDValue RISCVTargetLowering::lowerVECTOR_DEINTERLEAVE(SDValue Op,
MachinePointerInfo PtrInfo;
if (IsFixedVector) {
// Calculating the stack size.
- ElementCount ActualConcatEC =
- VecVT.getVectorElementCount().multiplyCoefficientBy(Factor);
+ ElementCount ActualConcatEC = VecVT.getVectorElementCount() * Factor;
EVT ConcatEVT = EVT::getVectorVT(
*DAG.getContext(), VecVT.getVectorElementType(), ActualConcatEC);
StackPtr = DAG.CreateStackTemporary(ConcatEVT.getStoreSize(), Alignment);
@@ -14737,9 +14733,8 @@ SDValue RISCVTargetLowering::lowerVECTOR_INTERLEAVE(SDValue Op,
DAG, Subtarget);
} else {
// Otherwise, fallback to using vrgathere16.vv
- MVT ConcatVT =
- MVT::getVectorVT(VecVT.getVectorElementType(),
- VecVT.getVectorElementCount().multiplyCoefficientBy(2));
+ MVT ConcatVT = MVT::getVectorVT(VecVT.getVectorElementType(),
+ VecVT.getVectorElementCount() * 2);
SDValue Concat = DAG.getNode(ISD::CONCAT_VECTORS, DL, ConcatVT,
Op.getOperand(0), Op.getOperand(1));
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 6c61562fd9659..df4dff2f2af1e 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -811,8 +811,7 @@ Value *VPInstruction::generate(VPTransformState &State) {
return Builder.CreateCmp(CmpInst::Predicate::ICMP_ULT, VIVElem0, ScalarTC,
Name);
- ElementCount EC = State.VF.multiplyCoefficientBy(Multiplier);
- auto *PredTy = VectorType::get(Builder.getInt1Ty(), EC);
+ auto *PredTy = VectorType::get(Builder.getInt1Ty(), State.VF * Multiplier);
return Builder.CreateIntrinsic(Intrinsic::get_active_lane_mask,
{PredTy, ScalarTC->getType()},
{VIVElem0, ScalarTC}, nullptr, Name);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index b21c4eb13a67b..5e6bc5cbb3171 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -231,8 +231,7 @@ class SinkStoreInfo {
ElementCount MaxVF = *max_element(VFs, ElementCount::isKnownLT);
if (MaxVF.isScalable())
return false;
- return Distance->abs().uge(
- MaxVF.multiplyCoefficientBy(MaxStoreSize).getFixedValue());
+ return Distance->abs().uge(MaxVF.getFixedValue() * MaxStoreSize);
}
public:
@@ -2041,7 +2040,7 @@ static bool isConditionTrueViaVFAndUF(VPValue *Cond, VPlan &Plan,
assert(!isa<SCEVCouldNotCompute>(VectorTripCount) &&
"Trip count SCEV must be computable");
ScalarEvolution &SE = *PSE.getSE();
- ElementCount NumElements = BestVF.multiplyCoefficientBy(BestUF);
+ ElementCount NumElements = BestVF * BestUF;
const SCEV *C = SE.getElementCount(VectorTripCount->getType(), NumElements);
return SE.isKnownPredicate(CmpInst::ICMP_EQ, VectorTripCount, C);
}
@@ -2122,7 +2121,7 @@ static bool simplifyBranchConditionForVFAndUF(VPlan &Plan, ElementCount BestVF,
assert(!isa<SCEVCouldNotCompute>(VectorTripCount) &&
"Trip count SCEV must be computable");
ScalarEvolution &SE = *PSE.getSE();
- ElementCount NumElements = BestVF.multiplyCoefficientBy(BestUF);
+ ElementCount NumElements = BestVF * BestUF;
const SCEV *C = SE.getElementCount(VectorTripCount->getType(), NumElements);
if (!SE.isKnownPredicate(CmpInst::ICMP_ULE, VectorTripCount, C))
return false;
diff --git a/llvm/unittests/Support/TypeSizeTest.cpp b/llvm/unittests/Support/TypeSizeTest.cpp
index 018b2405d4005..cb34d9f47d3ac 100644
--- a/llvm/unittests/Support/TypeSizeTest.cpp
+++ b/llvm/unittests/Support/TypeSizeTest.cpp
@@ -55,8 +55,7 @@ static_assert(CEElementCountFixed3.coefficientNextPowerOf2() ==
CEElementCountFixed4);
static_assert(ElementCount::getFixed(8).divideCoefficientBy(2) ==
ElementCount::getFixed(4));
-static_assert(ElementCount::getFixed(8).multiplyCoefficientBy(3) ==
- ElementCount::getFixed(24));
+static_assert(ElementCount::getFixed(8) * 3 == ElementCount::getFixed(24));
static_assert(ElementCount::getFixed(8).isKnownMultipleOf(2));
static_assert(!ElementCount::getFixed(8).isKnownMultipleOf(0));
>From 0b81973028259454d8cf67403815d07916829e1a Mon Sep 17 00:00:00 2001
From: Paul Walker <paul.walker at arm.com>
Date: Fri, 4 Sep 2026 13:22:10 +0000
Subject: [PATCH 2/2] Add another operator*() variant to avoid ambiguity.
---
llvm/include/llvm/Support/TypeSize.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/llvm/include/llvm/Support/TypeSize.h b/llvm/include/llvm/Support/TypeSize.h
index 7eea5e2d795ec..62a5302d4ad28 100644
--- a/llvm/include/llvm/Support/TypeSize.h
+++ b/llvm/include/llvm/Support/TypeSize.h
@@ -385,6 +385,10 @@ class TypeSize : public details::FixedOrScalableQuantity<TypeSize, uint64_t> {
friend constexpr TypeSize operator*(const TypeSize &LHS, const unsigned RHS) {
return LHS * (ScalarTy)RHS;
}
+ friend constexpr TypeSize operator*(const TypeSize &LHS,
+ const unsigned long RHS) {
+ return LHS * (ScalarTy)RHS;
+ }
friend constexpr TypeSize operator*(const TypeSize &LHS, const int64_t RHS) {
return LHS * (ScalarTy)RHS;
}
More information about the llvm-commits
mailing list