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

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 01:15:26 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()));
----------------
david-arm wrote:

I tried something like that for createNaryOp and it's messy because of all the subtly different variations of functions in the builder. Perhaps it's a bit easier for createOverflowingOp, but I imagine it still won't be that trivial. Also, currently you *must* always return a VPInstruction because many parts of vplan and the loop vectoriser expect a VPInstruction returned. However, in theory a fold could return a VPValue if for example you're multiplying a live-in by 1, etc. I think there is value in folding stuff at the time of creation, but I think it needs quite a bit of refactoring before it can properly work.

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


More information about the llvm-commits mailing list