[llvm] [LV] Count cost of middle block if TC <= VF. (PR #168949)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 24 04:32:51 PST 2025
================
@@ -9283,6 +9283,14 @@ static bool isOutsideLoopWorkProfitable(GeneratedRTChecks &Checks,
// one exists.
TotalCost += calculateEarlyExitCost(CostCtx, Plan, VF.Width);
+ // If the expected trip count is less than the VF, the vector loop will only
+ // execute a single iteration. Then the middle block is executed the same
+ // number of times as the vector region.
+ // TODO: Extend logic to always account for the cost of the middle block.
+ auto ExpectedTC = getSmallBestKnownTC(PSE, L);
+ if (ExpectedTC && ElementCount::isKnownLE(*ExpectedTC, VF.Width))
----------------
fhahn wrote:
Yep, this is intentional in the initial patch (from the description: `Note that isOutsideLoopWorkProfitable already scales the cost of blocks outside the vector region, but the patch restricts accounting for the middle block to cases where VF <= ExpectedTC, to initially catch some worst cases and avoid regressions.`)
The TODO is to enable it unconditionally, but that potentially has much higher impact, which is why I'd prefer to do this as a separate commit, to make it slightly easier to narrow down regressions.
https://github.com/llvm/llvm-project/pull/168949
More information about the llvm-commits
mailing list