[llvm] [LV] Optimise code created by createElementCount (PR #216981)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 19 00:57:09 PDT 2026
================
@@ -375,15 +375,16 @@ class VPBuilder {
VPValue *createElementCount(Type *Ty, ElementCount EC) {
VPlan &Plan = getPlan();
- VPValue *RuntimeEC = Plan.getConstantInt(Ty, EC.getKnownMinValue());
if (EC.isScalable()) {
VPValue *VScale = createVScale(Ty);
- RuntimeEC = EC.getKnownMinValue() == 1
- ? VScale
- : createOverflowingOp(Instruction::Mul,
- {VScale, RuntimeEC}, {true, false});
+ if (EC.getKnownMinValue() == 1)
+ return VScale;
+ assert(isPowerOf2_32(EC.getKnownMinValue()));
----------------
lukel97 wrote:
I guess in practice createElementCount is only ever passed the VF, but in theory an ElementCount can have a non power-of-2 min value and we would diverge from IRBuilder::createElementCount here.
Would a more general approach that's more similar to IRBuilder be to do a peephole fold in VPBuilder::createOverflowingOp that folds a power-of-2 mul to a shl? Not sure what the blast radius of that is.
https://github.com/llvm/llvm-project/pull/216981
More information about the llvm-commits
mailing list