[llvm] [LV] Optimise code created by createElementCount (PR #216981)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 02:32:48 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()));
----------------
paulwalker-arm wrote:

If we're being paranoid you could just change the assert into a runtime check and then generate either the shift or mul accordingly?

https://github.com/llvm/llvm-project/pull/216981


More information about the llvm-commits mailing list