[llvm] LV]: consider scalable VF during deciding dead epilogue. (PR #156724)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 4 05:10:40 PST 2025


================
@@ -4425,11 +4432,25 @@ VectorizationFactor LoopVectorizationPlanner::selectEpilogueVectorizationFactor(
 
     // If NextVF is greater than the number of remaining iterations, the
     // epilogue loop would be dead. Skip such factors.
-    if (RemainingIterations && !NextVF.Width.isScalable()) {
-      if (SE.isKnownPredicate(
-              CmpInst::ICMP_UGT,
-              SE.getConstant(TCType, NextVF.Width.getFixedValue()),
-              RemainingIterations))
+    if (ScalableRemIter == NextVF.Width.isScalable()) {
+      if (SE.isKnownPredicate(CmpInst::ICMP_UGT,
+                            SE.getElementCount(TCType, NextVF.Width),
+                            RemainingIterations))
+        continue;
+    }
+    // Handle the case where NextVF and RemainingIterations are in different
+    // numerical spaces.
+    else if (NextVF.Width.isScalable()) {
+      ElementCount EstimatedRuntimeNextVF = ElementCount::getFixed(
+          estimateElementCount(NextVF.Width, CM.getVScaleForTuning()));
+      if (SE.isKnownPredicate(CmpInst::ICMP_UGT,
+                              SE.getElementCount(TCType, EstimatedRuntimeNextVF),
+                              RemainingIterations))
+        continue;
+    } else {
+      if (SE.isKnownPredicate(CmpInst::ICMP_UGT,
----------------
david-arm wrote:

I think you can combine the if with the else, i.e.

```
  } else if (SE.isKnown...)
    continue;
```

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


More information about the llvm-commits mailing list