summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-02-19 18:12:07 +0000
committerDan Gohman <gohman@apple.com>2010-02-19 18:12:07 +0000
commit6b1e2a829ddc65ff988e9e35c151b5d91305f959 (patch)
treecf1e0b4d224759a0c5c300facc23df0c580048ee /llvm/lib/Analysis
parenta3e1e99b05ed4f16a4574e0248a5741a1fb93949 (diff)
downloadbcm5719-llvm-6b1e2a829ddc65ff988e9e35c151b5d91305f959.tar.gz
bcm5719-llvm-6b1e2a829ddc65ff988e9e35c151b5d91305f959.zip
Teach ScalarEvolution how to compute a tripcount for a loop with
true or false as its exit condition. These are usually eliminated by SimplifyCFG, but the may be left around during a pass which wishes to preserve the CFG. llvm-svn: 96683
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index c2284a8ab9b..a0700ba4218 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -3703,6 +3703,19 @@ ScalarEvolution::ComputeBackedgeTakenCountFromExitCond(const Loop *L,
if (ICmpInst *ExitCondICmp = dyn_cast<ICmpInst>(ExitCond))
return ComputeBackedgeTakenCountFromExitCondICmp(L, ExitCondICmp, TBB, FBB);
+ // Check for a constant condition. These are normally stripped out by
+ // SimplifyCFG, but ScalarEvolution may be used by a pass which wishes to
+ // preserve the CFG and is temporarily leaving constant conditions
+ // in place.
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(ExitCond)) {
+ if (L->contains(FBB) == !CI->getZExtValue())
+ // The backedge is always taken.
+ return getCouldNotCompute();
+ else
+ // The backedge is never taken.
+ return getIntegerSCEV(0, CI->getType());
+ }
+
// If it's not an integer or pointer comparison then compute it the hard way.
return ComputeBackedgeTakenCountExhaustively(L, ExitCond, !L->contains(TBB));
}
OpenPOWER on IntegriCloud