[llvm] [LV] Trim VFs that cause vector splitting when tail-folding with EVL (PR #222836)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 03:33:59 PDT 2026


================
@@ -653,3 +653,53 @@ void VPlanTransforms::convertEVLExitCond(VPlan &Plan) {
   LatchBr->setOperand(
       0, Builder.createICmp(CmpInst::ICMP_EQ, AVLNext, Plan.getZero(AVLTy)));
 }
+
+void VPlanTransforms::trimVFsCausingSplits(VPlan &Plan,
+                                           const TargetTransformInfo &TTI) {
+  if (!Plan.hasScalableVF())
+    return;
+
+  // Get the widest type in the vector region.
+  unsigned WidestType = 1;
+  for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+           vp_depth_first_deep(Plan.getEntry())))
+    for (VPRecipeBase &BaseR :
+         make_range(VPBB->getFirstNonPhi(), VPBB->end())) {
+      auto GetTypeSizeInBits = [&](Type *T) {
+        return isa<PointerType>(T) ? Plan.getDataLayout().getPointerSizeInBits(
+                                         T->getPointerAddressSpace())
+                                   : T->getScalarSizeInBits();
+      };
+      if (auto *Store = dyn_cast<VPWidenStoreEVLRecipe>(&BaseR)) {
+        WidestType = std::max(
+            WidestType,
+            GetTypeSizeInBits(Store->getStoredValue()->getScalarType()));
+        continue;
+      }
+      for (auto *V : BaseR.definedValues()) {
+        if (!vputils::onlyScalarValuesUsed(V)) {
+          // Skip the partial reduction since its VF is scaled down and can
+          // be calculated by its operands.
+          if (isa<VPExpressionRecipe>(V))
+            continue;
+          uint64_t Scale;
+          if (match(V, m_VPInstruction<VPInstruction::ReductionStartVector>(
+                           m_VPValue(), m_VPValue(), m_ConstantInt(Scale))) &&
+              Scale != 1)
+            continue;
+          WidestType =
+              std::max(WidestType, GetTypeSizeInBits(V->getScalarType()));
+        }
+      }
+    }
+
+  // Trim the VF that will generate vectors need to split.
+  SmallVector<ElementCount, 4> VFs = to_vector(Plan.vectorFactors());
+  for (auto VF : reverse(VFs)) {
+    if (TTI.getRegUsageForType(VectorType::get(
+            Type::getIntNTy(Plan.getContext(), WidestType), VF)) <= 8)
----------------
lukel97 wrote:

We're still hardcoding 8 here which is a RISC-V specific constant

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


More information about the llvm-commits mailing list