diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-09-25 19:59:57 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-09-25 19:59:57 +0000 |
commit | d706fa8a0c281b22df73c08c08b61b3f0a460e30 (patch) | |
tree | 2708e7ef36f0617d817e6948ffa814d3869b628b /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | df1635d3941600c1873d8eceb494edf7c32ee920 (diff) | |
download | bcm5719-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.cpp | 16 |
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) |