[llvm] [VPlan] Cost truncated widened inductions via ::computeCost. (PR #212786)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 29 08:38:37 PDT 2026
================
@@ -5672,26 +5675,23 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
auto TC = getSmallConstantTripCount(PSE.getSE(), OrigLoop);
bool IsFullyUnrolled = TC == VF && !Plan.hasTailFolded();
SmallPtrSet<const Value *, 4> WidenedIVs;
- bool HasTruncatedIV = false;
if (IsFullyUnrolled) {
addFullyUnrolledInstructionsToIgnore(OrigLoop, Legal->getInductionVars(),
CostCtx.SkipCostComputation);
} else {
// Inductions represented by a VPWidenIntOrFpInductionRecipe have their cost
// computed by the recipe, so collect their phis to skip the legacy
- // increment cost below. If any induction is truncated the VPlan-based cost
- // will diverge. Still fall back to the legacy cost model for now.
- VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
- for (VPRecipeBase &R : *LoopRegion->getEntryBasicBlock())
- if (auto *WideIV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&R)) {
- HasTruncatedIV |= WideIV->getTruncInst() != nullptr;
- if (PHINode *IVPhi = WideIV->getPHINode())
- WidenedIVs.insert(IVPhi);
- }
+ // increment cost below.
+ if (VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion())
+ for (VPRecipeBase &R : *LoopRegion->getEntryBasicBlock())
+ if (auto *WideIV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&R)) {
+ if (PHINode *IVPhi = WideIV->getPHINode())
+ WidenedIVs.insert(IVPhi);
+ }
}
for (const auto &[IV, IndDesc] : Legal->getInductionVars()) {
- if (!HasTruncatedIV && WidenedIVs.contains(IV))
+ if (!IsFullyUnrolled && WidenedIVs.contains(IV))
----------------
david-arm wrote:
Do we even need the `IsFullyUnrolled` variable anymore? The if check on line 5678 could be changed to
```
if (TC == VF && !Plan.hasTailFolded()) {
```
and the check here can just be
```
if (!WidenedIVs.empty() && WidenedIVs.contains(IV))
```
or perhaps just
```
if (WidenedIVs.contains(IV))
```
will suffice since I'd expect `contains` to bail out early for empty containers. `WidenedIVs` will only get populated for not-fully-unrolled case anyway.
https://github.com/llvm/llvm-project/pull/212786
More information about the llvm-commits
mailing list