[llvm] 7629b2a - [LI] Add a cover function for checking if a loop is mustprogress [nfc]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 10 13:37:39 PDT 2021
Author: Philip Reames
Date: 2021-06-10T13:37:32-07:00
New Revision: 7629b2a09c169bfd7f7295deb3678f3fa7755eee
URL: https://github.com/llvm/llvm-project/commit/7629b2a09c169bfd7f7295deb3678f3fa7755eee
DIFF: https://github.com/llvm/llvm-project/commit/7629b2a09c169bfd7f7295deb3678f3fa7755eee.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/Analysis/LoopInfo.h
llvm/lib/Analysis/LoopInfo.cpp
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
llvm/lib/Transforms/Utils/LoopUtils.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/LoopInfo.h b/llvm/include/llvm/Analysis/LoopInfo.h
index 8a8ee060e65ea..6e149b5d14fa9 100644
--- a/llvm/include/llvm/Analysis/LoopInfo.h
+++ b/llvm/include/llvm/Analysis/LoopInfo.h
@@ -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
diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp
index 5a2b7ff46cbbb..f45cc12d46302 100644
--- a/llvm/lib/Analysis/LoopInfo.cpp
+++ b/llvm/lib/Analysis/LoopInfo.cpp
@@ -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();
}
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 06aa6cb49ae39..275fad4acb2b2 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -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) {
diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
index be95ac1844287..aed9994399d2e 100644
--- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -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;
}
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 761960f0da62b..95ae7dbb3ddc9 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -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
More information about the llvm-commits
mailing list