summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorSanjoy Das <sanjoy@playingwithpointers.com>2015-09-25 19:59:57 +0000
committerSanjoy Das <sanjoy@playingwithpointers.com>2015-09-25 19:59:57 +0000
commitd706fa8a0c281b22df73c08c08b61b3f0a460e30 (patch)
tree2708e7ef36f0617d817e6948ffa814d3869b628b /llvm/lib/Analysis/ScalarEvolution.cpp
parentdf1635d3941600c1873d8eceb494edf7c32ee920 (diff)
downloadbcm5719-llvm-d706fa8a0c281b22df73c08c08b61b3f0a460e30.tar.gz
bcm5719-llvm-d706fa8a0c281b22df73c08c08b61b3f0a460e30.zip
[SCEV] Teach isLoopBackedgeGuardedByCond to exploit trip counts.
Summary: If the trip count of a specific backedge is `N`, then we know that backedge is effectively guarded by the condition `{0,+,1} u< N`. This change teaches SCEV to use this condition to prove things in `isLoopBackedgeGuardedByCond`. Depends on D12948 Depends on D12949 Reviewers: atrick, reames, majnemer, hfinkel Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D12950 llvm-svn: 248608
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index f87a5596c86..32d3d36c739 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6994,6 +6994,22 @@ ScalarEvolution::isLoopBackedgeGuardedByCond(const Loop *L,
SaveAndRestore<bool> ClearOnExit(WalkingBEDominatingConds, true);
+ // See if we can exploit a trip count to prove the predicate.
+ const auto &BETakenInfo = getBackedgeTakenInfo(L);
+ const SCEV *LatchBECount = BETakenInfo.getExact(Latch, this);
+ if (LatchBECount != getCouldNotCompute()) {
+ // We know that Latch branches back to the loop header exactly
+ // LatchBECount times. This means the backdege condition at Latch is
+ // equivalent to "{0,+,1} u< LatchBECount".
+ Type *Ty = LatchBECount->getType();
+ auto NoWrapFlags = SCEV::NoWrapFlags(SCEV::FlagNUW | SCEV::FlagNW);
+ const SCEV *LoopCounter =
+ getAddRecExpr(getZero(Ty), getOne(Ty), L, NoWrapFlags);
+ if (isImpliedCond(Pred, LHS, RHS, ICmpInst::ICMP_ULT, LoopCounter,
+ LatchBECount))
+ return true;
+ }
+
// Check conditions due to any @llvm.assume intrinsics.
for (auto &AssumeVH : AC.assumptions()) {
if (!AssumeVH)
OpenPOWER on IntegriCloud