Skip to content

Commit

Permalink
require that the branch being controlled by the IV
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lattner committed Apr 3, 2010
1 parent 96fd766 commit d52c072
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/Transforms/Scalar/IndVarSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d52c072

Please sign in to comment.