Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
19 changes: 16 additions & 3 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4372,11 +4372,24 @@ 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can fold this if into the else above, i.e.

  if (ScalableTC == MainLoopVF.isScalable())
    RemainingIterations =
        SE.getURemExpr(TC, SE.getElementCount(TCType, MainLoopVF * IC));
  else if (ScalableTC)
    RemainingIterations = SE.getURemExpr(
        KnownMinTC, SE.getElementCount(TCType, MainLoopVF * IC));
  else
    RemainingIterations = SE.getURemExpr(
        TC, SE.getElementCount(TCType, EstimatedRuntimeVF * IC));

RemainingIterations = SE.getURemExpr(
KnownMinTC, SE.getElementCount(TCType, MainLoopVF * IC));
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 to multiply KnownMinTC by CM.getVScaleForTuning() to get a more accurate estimate.

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

// No iterations left to process in the epilogue.
if (RemainingIterations->isZero())
if (!RemainingIterations || RemainingIterations->isZero())
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change needed? I think RemainingIterations should always be non-null because it's always set to the value returned by getURemExpr. The worst thing that can happen is that it returns a pointer to a SCEVUnknown object, but isZero will just return false.

return Result;

if (MainLoopVF.isFixed()) {
Expand Down
Loading
Loading