[llvm] [LV] Count cost of middle block if TC <= VF. (PR #168949)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 8 01:57:11 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:

Put up the follow up: https://github.com/llvm/llvm-project/pull/171102

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


More information about the llvm-commits mailing list