[llvm] [LV]: Improve accuracy of calculating remaining iterations of MainLoopVF (PR #156723)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 30 05:29:47 PDT 2025
================
@@ -4371,11 +4371,30 @@ VectorizationFactor LoopVectorizationPlanner::selectEpilogueVectorizationFactor(
const SCEV *TC =
vputils::getSCEVExprForVPValue(getPlanFor(MainLoopVF).getTripCount(), SE);
assert(!isa<SCEVCouldNotCompute>(TC) && "Trip count SCEV must be computable");
- RemainingIterations =
- SE.getURemExpr(TC, SE.getElementCount(TCType, MainLoopVF * IC));
+
+ // Calculate runtime estimated value for TC/MainLoopVF only when they are in
+ // different numerical space.
+ // TODO: This is a workaround until SCEV can evaluate vscale-based
+ // expressions.
+ if (match(TC, m_scev_Mul(m_SCEV(), m_SCEVVScale())) &&
+ MainLoopVF.isScalable()) {
----------------
david-arm wrote:
It might be a bit clearer if you handle all cases where the numerical space is the same here, i.e.
```
bool ScalableTC = match(TC, m_scev_Mul(m_SCEV(), m_SCEVVScale()));
if (ScalableTC == MainLoopVF.isScalable())
RemainingIterations =
SE.getURemExpr(TC, SE.getElementCount(TCType, MainLoopVF * IC));
else {
if (ScalableTC) {
...
```
https://github.com/llvm/llvm-project/pull/156723
More information about the llvm-commits
mailing list