[llvm] [VPlan] Run narrowInterleaveGroups during general VPlan optimizations. (PR #149706)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 11 08:27:38 PDT 2025


================
@@ -3954,30 +3966,38 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
     //  * recipes writing to memory except interleave groups
     // Only support plans with a canonical induction phi.
     if (R.isPhi())
-      return;
+      return nullptr;
 
     auto *InterleaveR = dyn_cast<VPInterleaveRecipe>(&R);
     if (R.mayWriteToMemory() && !InterleaveR)
-      return;
-
-    // Do not narrow interleave groups if there are VectorPointer recipes and
-    // the plan was unrolled. The recipe implicitly uses VF from
-    // VPTransformState.
-    // TODO: Remove restriction once the VF for the VectorPointer offset is
-    // modeled explicitly as operand.
-    if (isa<VPVectorPointerRecipe>(&R) && Plan.getUF() > 1)
-      return;
+      return nullptr;
 
     // All other ops are allowed, but we reject uses that cannot be converted
     // when checking all allowed consumers (store interleave groups) below.
     if (!InterleaveR)
       continue;
 
-    // Bail out on non-consecutive interleave groups.
-    if (!isConsecutiveInterleaveGroup(InterleaveR, VFMinVal, TypeInfo,
-                                      VectorRegWidth))
-      return;
-
+    // Try to find a single VF, where all interleave groups are consecutive and
+    // saturate the full vector width. If we already have a candidate VF, check
+    // if it is applicable for the current InterleaveR, otherwise look for a
+    // suitable VF across the Plans VFs.
+    //
+    if (VFToOptimize) {
+      if (!isConsecutiveInterleaveGroup(
+              InterleaveR, VFToOptimize->getKnownMinValue(), TypeInfo,
+              GetVectorWidthForVF(*VFToOptimize)))
+        return nullptr;
+    } else {
+      for (ElementCount VF : Plan.vectorFactors()) {
----------------
david-arm wrote:

Couldn't you just pass in the ElementCounts directly to `isConsecutiveInterleaveGroup`? It feels a bit cleaner because otherwise `isConsecutiveInterleaveGroup` is a bit fragile, since it doesn't know if the min value passed in for the VF is for a fixed-width or scalable VF and could lead to incorrect behaviour. If you pass in the original VFs then `isConsecutiveInterleaveGroup` can bail out or assert if `VF.isScalable() != RegWidth.isScalable()`.

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


More information about the llvm-commits mailing list