Skip to content

Commit

Permalink
[LV] Remove loop arg from CM::isCandidateForEpilogueVectorization (NFC)
Browse files Browse the repository at this point in the history
LVP operates on the loop it stores in TheLoop. Use it instead of the
argument, to be in line with other member functions.

Suggested as independent improvement in D143938.
  • Loading branch information
fhahn committed Apr 30, 2023
1 parent 6fa07a8 commit a431402
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Expand Up @@ -1844,10 +1844,9 @@ class LoopVectorizationCostModel {
Ops, [this, VF](Value *V) { return this->needsExtract(V, VF); }));
}

/// Determines if we have the infrastructure to vectorize loop \p L and its
/// Determines if we have the infrastructure to vectorize the loop and its
/// epilogue, assuming the main loop is vectorized by \p VF.
bool isCandidateForEpilogueVectorization(const Loop &L,
const ElementCount VF) const;
bool isCandidateForEpilogueVectorization(const ElementCount VF) const;

/// Returns true if epilogue vectorization is considered profitable, and
/// false otherwise.
Expand Down Expand Up @@ -5555,31 +5554,32 @@ VectorizationFactor LoopVectorizationCostModel::selectVectorizationFactor(
}

bool LoopVectorizationCostModel::isCandidateForEpilogueVectorization(
const Loop &L, ElementCount VF) const {
ElementCount VF) const {
// Cross iteration phis such as reductions need special handling and are
// currently unsupported.
if (any_of(L.getHeader()->phis(),
if (any_of(TheLoop->getHeader()->phis(),
[&](PHINode &Phi) { return Legal->isFixedOrderRecurrence(&Phi); }))
return false;

// Phis with uses outside of the loop require special handling and are
// currently unsupported.
for (const auto &Entry : Legal->getInductionVars()) {
// Look for uses of the value of the induction at the last iteration.
Value *PostInc = Entry.first->getIncomingValueForBlock(L.getLoopLatch());
Value *PostInc =
Entry.first->getIncomingValueForBlock(TheLoop->getLoopLatch());
for (User *U : PostInc->users())
if (!L.contains(cast<Instruction>(U)))
if (!TheLoop->contains(cast<Instruction>(U)))
return false;
// Look for uses of penultimate value of the induction.
for (User *U : Entry.first->users())
if (!L.contains(cast<Instruction>(U)))
if (!TheLoop->contains(cast<Instruction>(U)))
return false;
}

// Epilogue vectorization code has not been auditted to ensure it handles
// non-latch exits properly. It may be fine, but it needs auditted and
// tested.
if (L.getExitingBlock() != L.getLoopLatch())
if (TheLoop->getExitingBlock() != TheLoop->getLoopLatch())
return false;

return true;
Expand Down Expand Up @@ -5626,7 +5626,7 @@ LoopVectorizationCostModel::selectEpilogueVectorizationFactor(

// Not really a cost consideration, but check for unsupported cases here to
// simplify the logic.
if (!isCandidateForEpilogueVectorization(*TheLoop, MainLoopVF)) {
if (!isCandidateForEpilogueVectorization(MainLoopVF)) {
LLVM_DEBUG(dbgs() << "LEV: Unable to vectorize epilogue because the loop "
"is not a supported candidate.\n");
return Result;
Expand Down

0 comments on commit a431402

Please sign in to comment.