[llvm] [LV] Derive max trip count for remainder loops through LCSSA phis (PR #206887)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 01:21:58 PDT 2026


================
@@ -2943,6 +3045,21 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {
   LLVM_DEBUG(dbgs() << "LV: Found trip count: " << TC << '\n');
   if (TC != ElementCount::getFixed(MaxTC))
     LLVM_DEBUG(dbgs() << "LV: Found maximum trip count: " << MaxTC << '\n');
+
+  // If we derived a small max trip count (e.g. from a remainder-of-stride
----------------
david-arm wrote:

I haven't reviewed all the code here, but I think it would be good to split this into two PRs:

1. One PR that discovers `MaxTC` for more loops, making use of `getMaxTCForRemainderLoop`. Then `computeFeasibleMaxVF` should be able to use this `MaxTC` to restrict the VF to something appropriate. If you look at `getMaximizedVFForTarget` it already clamps the maximum VF by calling `clampVFByMaxTripCount`. It should be possible to write a test case that shows this clamping - we should have similar existing tests.
2. A follow-on PR that bails out for runtime checks on small loops. It's worth nothing that this may conflict with https://github.com/llvm/llvm-project/pull/197391, which is kind of doing the opposite.

Splitting it up this way makes it easier to review and reduces the risk of the first PR introducing a regression.

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


More information about the llvm-commits mailing list