Eliminate getCanonicalInductionVariableIncrement's last user and
authorDan Gohman <gohman@apple.com>
Fri, 23 Jul 2010 21:34:51 +0000 (21:34 +0000)
committerDan Gohman <gohman@apple.com>
Fri, 23 Jul 2010 21:34:51 +0000 (21:34 +0000)
eliminate it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109270 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/LoopInfo.h
lib/Analysis/LoopInfo.cpp

index 5dfdc25dd88d9b0d65a62dbb261ef47b68cc1a9a..2e90a9631fb77efb962b908d01fe58e54d8595ca 100644 (file)
@@ -562,12 +562,6 @@ public:
   ///
   PHINode *getCanonicalInductionVariable() const;
 
   ///
   PHINode *getCanonicalInductionVariable() const;
 
-  /// getCanonicalInductionVariableIncrement - Return the LLVM value that holds
-  /// the canonical induction variable value for the "next" iteration of the
-  /// loop.  This always succeeds if getCanonicalInductionVariable succeeds.
-  ///
-  Instruction *getCanonicalInductionVariableIncrement() const;
-
   /// getTripCount - Return a loop-invariant LLVM value indicating the number of
   /// times the loop will be executed.  Note that this means that the backedge
   /// of the loop executes N-1 times.  If the trip-count cannot be determined,
   /// getTripCount - Return a loop-invariant LLVM value indicating the number of
   /// times the loop will be executed.  Note that this means that the backedge
   /// of the loop executes N-1 times.  If the trip-count cannot be determined,
index b4333147a0c1fe262b9df3464b857bc1e3f2e5f8..46219d1b6f55cc810313f7a8083c7aca35c12b92 100644 (file)
@@ -155,18 +155,6 @@ PHINode *Loop::getCanonicalInductionVariable() const {
   return 0;
 }
 
   return 0;
 }
 
-/// getCanonicalInductionVariableIncrement - Return the LLVM value that holds
-/// the canonical induction variable value for the "next" iteration of the
-/// loop.  This always succeeds if getCanonicalInductionVariable succeeds.
-///
-Instruction *Loop::getCanonicalInductionVariableIncrement() const {
-  if (PHINode *PN = getCanonicalInductionVariable()) {
-    bool P1InLoop = contains(PN->getIncomingBlock(1));
-    return cast<Instruction>(PN->getIncomingValue(P1InLoop));
-  }
-  return 0;
-}
-
 /// getTripCount - Return a loop-invariant LLVM value indicating the number of
 /// times the loop will be executed.  Note that this means that the backedge
 /// of the loop executes N-1 times.  If the trip-count cannot be determined,
 /// getTripCount - Return a loop-invariant LLVM value indicating the number of
 /// times the loop will be executed.  Note that this means that the backedge
 /// of the loop executes N-1 times.  If the trip-count cannot be determined,
@@ -178,12 +166,12 @@ Instruction *Loop::getCanonicalInductionVariableIncrement() const {
 Value *Loop::getTripCount() const {
   // Canonical loops will end with a 'cmp ne I, V', where I is the incremented
   // canonical induction variable and V is the trip count of the loop.
 Value *Loop::getTripCount() const {
   // Canonical loops will end with a 'cmp ne I, V', where I is the incremented
   // canonical induction variable and V is the trip count of the loop.
-  Instruction *Inc = getCanonicalInductionVariableIncrement();
-  if (Inc == 0) return 0;
-  PHINode *IV = cast<PHINode>(Inc->getOperand(0));
+  PHINode *IV = getCanonicalInductionVariable();
+  if (IV == 0 || IV->getNumIncomingValues() != 2) return 0;
 
 
-  BasicBlock *BackedgeBlock =
-    IV->getIncomingBlock(contains(IV->getIncomingBlock(1)));
+  bool P0InLoop = contains(IV->getIncomingBlock(0));
+  Value *Inc = IV->getIncomingValue(!P0InLoop);
+  BasicBlock *BackedgeBlock = IV->getIncomingBlock(!P0InLoop);
 
   if (BranchInst *BI = dyn_cast<BranchInst>(BackedgeBlock->getTerminator()))
     if (BI->isConditional()) {
 
   if (BranchInst *BI = dyn_cast<BranchInst>(BackedgeBlock->getTerminator()))
     if (BI->isConditional()) {