[llvm] [LV][NFC] Clean up tail-folding check for early-exit loops (PR #133931)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 3 06:00:35 PDT 2025


================
@@ -4049,7 +4033,9 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {
     return Rem->isZero();
   };
 
-  if (MaxPowerOf2RuntimeVF > 0u) {
+  bool HasSingleLatchExit =
----------------
david-arm wrote:

I understand what you're trying to do here, but I think we should remove the extra `HasSingleLatchExit` check and instead update `NoScalarEpilogueNeeded` for the case when a scalar epilogue is genuinely required. For loops with uncountable early exits we don't actually require a scalar epilogue at the moment, so we can still benefit from

1. If we have a power-of-2 runtime VF then there is no point tail-folding.
2. If we have a very low trip count we should fall back on a runtime power-of-2 fixed-width VF if possible.

In NoScalarEpilogueNeeded I think you can then add an extra check like this:

```
  auto NoScalarEpilogueNeeded = [this, &UserIC](unsigned MaxVF) {
    if (TheLoop->getExitingBlock() != TheLoop->getLoopLatch() &&
        !Legal->hasUncountableEarlyExit())
      return false;
```

What do you think?

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


More information about the llvm-commits mailing list