[llvm] [VPlan] Replace WideCanIV with CanIV when possible (PR #191276)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 9 14:06:57 PDT 2026


================
@@ -679,15 +679,17 @@ static void removeRedundantInductionCasts(VPlan &Plan) {
 static void removeRedundantCanonicalIVs(VPlan &Plan) {
   VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
   VPCanonicalIVPHIRecipe *CanonicalIV = LoopRegion->getCanonicalIV();
-  VPWidenCanonicalIVRecipe *WidenNewIV = nullptr;
-  for (VPUser *U : CanonicalIV->users()) {
-    WidenNewIV = dyn_cast<VPWidenCanonicalIVRecipe>(U);
-    if (WidenNewIV)
-      break;
-  }
+  auto *FoundWideIV =
+      find_if(CanonicalIV->users(), IsaPred<VPWidenCanonicalIVRecipe>);
+  if (FoundWideIV == CanonicalIV->user_end())
+    return;
+  auto *WidenNewIV = cast<VPWidenCanonicalIVRecipe>(*FoundWideIV);
 
-  if (!WidenNewIV)
+  if (Plan.hasScalarVFOnly() || vputils::onlyScalarValuesUsed(WidenNewIV)) {
+    WidenNewIV->replaceAllUsesWith(CanonicalIV);
----------------
artagnon wrote:

Ah yes, thanks for the guidance: will try :)

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


More information about the llvm-commits mailing list