Commit 7629b2a0 authored by Philip Reames's avatar Philip Reames
Browse files

[LI] Add a cover function for checking if a loop is mustprogress [nfc]

Essentially, the cover function simply combines the loop level check and the function level scope into one call.  This simplifies several callers and is (subjectively) less error prone.
parent 859c924c
......@@ -1311,8 +1311,14 @@ Optional<const MDOperand *> findStringMetadataForLoop(const Loop *TheLoop,
StringRef Name);
/// Look for the loop attribute that requires progress within the loop.
/// Note: Most consumers probably want "isMustProgress" which checks
/// the containing function attribute too.
bool hasMustProgress(const Loop *L);
/// Return true if this loop can be assumed to make progress. (i.e. can't
/// be infinite without side effects without also being undefined)
bool isMustProgress(const Loop *L);
/// Return whether an MDNode might represent an access group.
///
/// Access group metadata nodes have to be distinct and empty. Being
......
......@@ -1108,6 +1108,10 @@ bool llvm::hasMustProgress(const Loop *L) {
return getBooleanLoopAttribute(L, LLVMLoopMustProgress);
}
bool llvm::isMustProgress(const Loop *L) {
return L->getHeader()->getParent()->mustProgress() || hasMustProgress(L);
}
bool llvm::isValidAsAccessGroup(MDNode *Node) {
return Node->getNumOperands() == 0 && Node->isDistinct();
}
......
......@@ -6579,14 +6579,10 @@ ScalarEvolution::getLoopProperties(const Loop *L) {
}
 
bool ScalarEvolution::loopIsFiniteByAssumption(const Loop *L) {
if (!L->getHeader()->getParent()->mustProgress() &&
!hasMustProgress(L))
return false;
// A loop without side effects must be finite.
// A mustprogress loop without side effects must be finite.
// TODO: The check used here is very conservative. It's only *specific*
// side effects which are well defined in infinite loops.
return loopHasNoSideEffects(L);
return isMustProgress(L) && loopHasNoSideEffects(L);
}
 
const SCEV *ScalarEvolution::createSCEV(Value *V) {
......
......@@ -2535,8 +2535,7 @@ static bool detectShiftUntilZeroIdiom(Loop *CurLoop, ScalarEvolution *SE,
// right-shift, iff the sign bit was set, the value will never become zero,
// and the loop may never finish.
if (ValShifted->getOpcode() == Instruction::AShr &&
!CurLoop->getHeader()->getParent()->mustProgress() &&
!hasMustProgress(CurLoop) && !SE->isKnownNonNegative(SE->getSCEV(Val))) {
!isMustProgress(CurLoop) && !SE->isKnownNonNegative(SE->getSCEV(Val))) {
LLVM_DEBUG(dbgs() << DEBUG_TYPE " Can not prove the loop is finite.\n");
return false;
}
......
......@@ -1781,8 +1781,7 @@ Optional<IVConditionInfo> llvm::hasPartialIVCondition(Loop &L,
// We could also allow loops with known trip counts without mustprogress,
// but ScalarEvolution may not be available.
Info.PathIsNoop &=
L.getHeader()->getParent()->mustProgress() || hasMustProgress(&L);
Info.PathIsNoop &= isMustProgress(&L);
// If the path is considered a no-op so far, check if it reaches a
// single exit block without any phis. This ensures no values from the
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment