[llvm] [VPlan] Strip dead code in replaceSymbolicStrides (NFC) (PR #164296)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 20 11:22:14 PDT 2025


https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/164296

CanUseVersionedStride is checking that the value is modeled in VPlan, but we can use replaceAllUsesWith unconditionally for this.

>From d23d3eb1d2b5ed7cfb51372cf93e12b9ac7e2c77 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Mon, 20 Oct 2025 19:19:01 +0100
Subject: [PATCH] [VPlan] Strip dead code in replaceSymbolicStrides (NFC)

CanUseVersionedStride is checking that the value is modeled in VPlan,
but we can use replaceAllUsesWith unconditionally for this.
---
 llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index e060e7081042a..cafddcc77d15d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -2909,13 +2909,6 @@ void VPlanTransforms::canonicalizeEVLLoops(VPlan &Plan) {
 void VPlanTransforms::replaceSymbolicStrides(
     VPlan &Plan, PredicatedScalarEvolution &PSE,
     const DenseMap<Value *, const SCEV *> &StridesMap) {
-  // Replace VPValues for known constant strides guaranteed by predicate scalar
-  // evolution.
-  auto CanUseVersionedStride = [&Plan](VPUser &U, unsigned) {
-    auto *R = cast<VPRecipeBase>(&U);
-    return R->getRegion() ||
-           R->getParent() == Plan.getVectorLoopRegion()->getSinglePredecessor();
-  };
   ValueToSCEVMapTy RewriteMap;
   for (const SCEV *Stride : StridesMap.values()) {
     using namespace SCEVPatternMatch;
@@ -2928,7 +2921,7 @@ void VPlanTransforms::replaceSymbolicStrides(
     auto *CI =
         Plan.getOrAddLiveIn(ConstantInt::get(Stride->getType(), *StrideConst));
     if (VPValue *StrideVPV = Plan.getLiveIn(StrideV))
-      StrideVPV->replaceUsesWithIf(CI, CanUseVersionedStride);
+      StrideVPV->replaceAllUsesWith(CI);
 
     // The versioned value may not be used in the loop directly but through a
     // sext/zext. Add new live-ins in those cases.
@@ -2942,7 +2935,7 @@ void VPlanTransforms::replaceSymbolicStrides(
       APInt C =
           isa<SExtInst>(U) ? StrideConst->sext(BW) : StrideConst->zext(BW);
       VPValue *CI = Plan.getOrAddLiveIn(ConstantInt::get(U->getType(), C));
-      StrideVPV->replaceUsesWithIf(CI, CanUseVersionedStride);
+      StrideVPV->replaceAllUsesWith(CI);
     }
     RewriteMap[StrideV] = PSE.getSCEV(StrideV);
   }



More information about the llvm-commits mailing list