[llvm] [VPlan] Replace WideCanIV with CanIV when possible (PR #191276)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 9 13:48:31 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);
----------------
fhahn wrote:
I don't think this is correct in all cases; `CanonicalIV` only provides lane 0 across VF and UF, not all lanes. It also won't get handled during interleaving. I think changes in `llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll` show the issue
https://github.com/llvm/llvm-project/pull/191276
More information about the llvm-commits
mailing list