[llvm] [VPlan] Use wide IV if scalar lanes > 0 are used with scalable vectors. (PR #169796)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 1 01:55:44 PST 2025


================
@@ -794,12 +794,17 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
         WideIV->getDebugLoc(), Builder);
 
     // Update scalar users of IV to use Step instead.
-    if (!HasOnlyVectorVFs)
+    if (!HasOnlyVectorVFs) {
       WideIV->replaceAllUsesWith(Steps);
-    else
-      WideIV->replaceUsesWithIf(Steps, [WideIV](VPUser &U, unsigned) {
-        return U.usesScalars(WideIV);
-      });
+    } else {
+      bool HasScalableVF = Plan.hasScalableVF();
+      WideIV->replaceUsesWithIf(Steps,
+                                [WideIV, HasScalableVF](VPUser &U, unsigned) {
+                                  if (HasScalableVF)
----------------
david-arm wrote:

Are plans containing scalable VFs always guaranteed to never include a fixed-width VF? I think that's probably true in practice, but this might give strange behaviour if not.

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


More information about the llvm-commits mailing list