aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-04-03 07:21:39 +0000
committerChris Lattner <sabre@nondot.org>2010-04-03 07:21:39 +0000
commitd52c072777b9c9a9df9041b8b6cd199df7e43394 (patch)
tree8613edc48bf93d4ed8e0cff21bbb2c3b528f8f5c /lib/Transforms
parent96fd76638b6be492c5e470c3b9d5ca12628be5a9 (diff)
require that the branch being controlled by the IV
exits the loop. With this information we can guarantee the iteration count of the loop is bounded by the compare. I think this xforms is finally safe now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100285 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/IndVarSimplify.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp
index d32082e5dc..6605666e45 100644
--- a/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -691,8 +691,15 @@ void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PN) {
BranchInst *TheBr = cast<BranchInst>(Compare->use_back());
- // FIXME: Need to verify that the branch actually controls the iteration count
- // of the loop. If not, the new IV can overflow and noone will notice.
+ // We need to verify that the branch actually controls the iteration count
+ // of the loop. If not, the new IV can overflow and no one will notice.
+ // The branch block must be in the loop and one of the successors must be out
+ // of the loop.
+ assert(TheBr->isConditional() && "Can't use fcmp if not conditional");
+ if (!L->contains(TheBr->getParent()) ||
+ (L->contains(TheBr->getSuccessor(0)) &&
+ L->contains(TheBr->getSuccessor(1))))
+ return;
// If it isn't a comparison with an integer-as-fp (the exit value), we can't