aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/LoopUtils.cpp
diff options
context:
space:
mode:
authorDavid Green <david.green@arm.com>2018-08-11 06:57:28 +0000
committerDavid Green <david.green@arm.com>2018-08-11 06:57:28 +0000
commit395b80cd3cf41da895d0bf217dfc2a0918593a13 (patch)
tree46aa7b36e0c94dedf926f9e1944710ac2a7286c7 /llvm/lib/Transforms/Utils/LoopUtils.cpp
parentb3e3477649eb1f4377525d5fbbd6891ee776cacc (diff)
downloadllvm-395b80cd3cf41da895d0bf217dfc2a0918593a13.zip
llvm-395b80cd3cf41da895d0bf217dfc2a0918593a13.tar.gz
llvm-395b80cd3cf41da895d0bf217dfc2a0918593a13.tar.bz2
[UnJ] Create a hasInvariantIterationCount function. NFC
Pulled out a separate function for some code that calculates if an inner loop iteration count is invariant to it's outer loop. Differential Revision: https://reviews.llvm.org/D50063 llvm-svn: 339500
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/LoopUtils.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 8e9235b..e9db472 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -1521,6 +1521,28 @@ Optional<unsigned> llvm::getLoopEstimatedTripCount(Loop *L) {
return (FalseVal + (TrueVal / 2)) / TrueVal;
}
+bool llvm::hasInvariantIterationCount(Loop *InnerLoop,
+ ScalarEvolution &SE) {
+ Loop *OuterL = InnerLoop->getParentLoop();
+ if (!OuterL)
+ return true;
+
+ // Get the backedge taken count for the inner loop
+ BasicBlock *InnerLoopLatch = InnerLoop->getLoopLatch();
+ const SCEV *InnerLoopBECountSC = SE.getExitCount(InnerLoop, InnerLoopLatch);
+ if (isa<SCEVCouldNotCompute>(InnerLoopBECountSC) ||
+ !InnerLoopBECountSC->getType()->isIntegerTy())
+ return false;
+
+ // Get whether count is invariant to the outer loop
+ ScalarEvolution::LoopDisposition LD =
+ SE.getLoopDisposition(InnerLoopBECountSC, OuterL);
+ if (LD != ScalarEvolution::LoopInvariant)
+ return false;
+
+ return true;
+}
+
/// Adds a 'fast' flag to floating point operations.
static Value *addFastMathFlag(Value *V) {
if (isa<FPMathOperator>(V)) {