Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Comment on lines +4376 to +4377
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool ScalableTC = match(TC, m_scev_Mul(m_SCEV(KnownMinTC), m_SCEVVScale())) ||
match(TC, m_scev_Mul(m_SCEVVScale(), m_SCEV(KnownMinTC)));
bool ScalableTC = match(TC, m_scev_c_Mul(m_SCEV(KnownMinTC), m_SCEVVScale()));

// 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()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need CM.getVScaleForTuning().value_or(1) here because the value is only available if the vscale_range attribute is present on the function.

RemainingIterations = SE.getURemExpr(
EstimatedTC, SE.getElementCount(TCType, MainLoopVF * IC));
} else
RemainingIterations =
SE.getURemExpr(TC, SE.getElementCount(TCType, EstimatedRuntimeVF * IC));

// No iterations left to process in the epilogue.
if (RemainingIterations->isZero())
Expand Down
Loading