diff options
author | Chris Lattner <sabre@nondot.org> | 2007-01-07 02:24:26 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-01-07 02:24:26 +0000 |
commit | 18954852aec6ab10ca3aacb27d4478a5542ec180 (patch) | |
tree | bdf1bf1ee9370feb56b7c4e31a739fbfda7d0a66 /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | a4c150b69e49587c292a6c160436e305ebc5e1de (diff) | |
download | bcm5719-llvm-18954852aec6ab10ca3aacb27d4478a5542ec180.tar.gz bcm5719-llvm-18954852aec6ab10ca3aacb27d4478a5542ec180.zip |
Fix PR1015 and Transforms/IndVarsSimplify/2007-01-06-TripCount.ll, a
miscompilation of Qt.
llvm-svn: 32974
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index e2a03c89241..cc483b8d137 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -1498,12 +1498,26 @@ SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) { BranchInst *ExitBr = dyn_cast<BranchInst>(ExitingBlock->getTerminator()); if (ExitBr == 0) return UnknownValue; assert(ExitBr->isConditional() && "If unconditional, it can't be in loop!"); + + // At this point, we know we have a conditional branch that determines whether + // the loop is exited. However, we don't know if the branch is executed each + // time through the loop. If not, then the execution count of the branch will + // not be equal to the trip count of the loop. + // + // Currently we check for this by checking to see if the Exit branch goes to + // the loop header. If so, we know it will always execute the same number of + // times as the loop. More extensive analysis could be done to handle more + // cases here. + if (ExitBr->getSuccessor(0) != L->getHeader() && + ExitBr->getSuccessor(1) != L->getHeader()) + return UnknownValue; + ICmpInst *ExitCond = dyn_cast<ICmpInst>(ExitBr->getCondition()); // If its not an integer comparison then compute it the hard way. // Note that ICmpInst deals with pointer comparisons too so we must check // the type of the operand. - if (ExitCond == 0 || !ExitCond->getOperand(0)->getType()->isIntegral()) + if (ExitCond == 0 || isa<PointerType>(ExitCond->getOperand(0)->getType())) return ComputeIterationCountExhaustively(L, ExitBr->getCondition(), ExitBr->getSuccessor(0) == ExitBlock); |