[llvm] [LV]: Improve accuracy of calculating remaining iterations of MainLoopVF (PR #156723)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 21 02:09:57 PDT 2025
================
@@ -4372,8 +4372,21 @@ 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));
+ const SCEV *KnownMinTC;
+ bool ScalableTC = match(TC, m_scev_Mul(m_SCEV(KnownMinTC), m_SCEVVScale())) ||
+ match(TC, m_scev_Mul(m_SCEVVScale(), m_SCEV(KnownMinTC)));
+ // Use versions of TC and VF in which both are either scalable or fixed.
+ if (ScalableTC == MainLoopVF.isScalable())
+ RemainingIterations =
+ SE.getURemExpr(TC, SE.getElementCount(TCType, MainLoopVF * IC));
+ else if (ScalableTC) {
+ const SCEV *EstimatedTC = SE.getMulExpr(
+ KnownMinTC, SE.getConstant(TCType, CM.getVScaleForTuning().value()));
----------------
david-arm wrote:
Unfortunately not. The vscale_range attribute is not guaranteed to be present on functions using scalable vectors. If the attribute is missing then `getVScaleForTuning` will return std::nullopt (see `initializeVScaleForTuning`) and std::optional::value() will trigger an exception here.
https://github.com/llvm/llvm-project/pull/156723
More information about the llvm-commits
mailing list