[llvm-commits] [llvm] r40915 - /llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp

Devang Patel dpatel at apple.com
Tue Aug 7 18:51:27 PDT 2007


Author: dpatel
Date: Tue Aug  7 20:51:27 2007
New Revision: 40915

URL: http://llvm.org/viewvc/llvm-project?rev=40915&view=rev
Log:
Embrace patch review feedback.

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp?rev=40915&r1=40914&r2=40915&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp Tue Aug  7 20:51:27 2007
@@ -217,13 +217,26 @@
   if (!safeExitBlock(ExitBlock)) 
     return false;
 
+  // Update CFG.
+
+  // As a first step to break this loop, remove Latch to Header edge.
   BasicBlock *Latch = L->getLoopLatch();
+  BasicBlock *LatchSucc = NULL;
+  BranchInst *BR = dyn_cast<BranchInst>(Latch->getTerminator());
+  if (!BR)
+    return false;
+  Header->removePredecessor(Latch);
+  for (succ_iterator SI = succ_begin(Latch), E = succ_end(Latch);
+       SI != E; ++SI) {
+    if (Header != *SI)
+      LatchSucc = *SI;
+  }
+  BR->setUnconditionalDest(LatchSucc);
+
   BasicBlock *Preheader = L->getLoopPreheader();
   Instruction *Terminator = Header->getTerminator();
   Value *StartValue = IndVar->getIncomingValueForBlock(Preheader);
 
-  // Update CFG.
-
   // Replace split condition in header.
   // Transform 
   //      SplitCondition : icmp eq i32 IndVar, SplitValue
@@ -238,22 +251,10 @@
   Instruction *C2 = new ICmpInst(SignedPredicate ? 
                                  ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
                                  SplitValue, ExitValue, "lisplit", Terminator);
-  Instruction *NSplitCond = BinaryOperator::create(Instruction::And,
-                                                   C1, C2, "lisplit", Terminator);
+  Instruction *NSplitCond = BinaryOperator::createAnd(C1, C2, "lisplit", Terminator);
   SplitCondition->replaceAllUsesWith(NSplitCond);
   SplitCondition->eraseFromParent();
 
-  // As a first step to break this loop, remove Latch to Header edge.
-  BasicBlock *LatchSucc = NULL;
-  Header->removePredecessor(Latch);
-  for (succ_iterator SI = succ_begin(Latch), E = succ_end(Latch);
-       SI != E; ++SI) {
-    if (Header != *SI)
-      LatchSucc = *SI;
-  }
-  BranchInst *BR = dyn_cast<BranchInst>(Latch->getTerminator());
-  BR->setUnconditionalDest(LatchSucc);
-  
   // Now, clear latch block. Remove instructions that are responsible
   // to increment induction variable. 
   Instruction *LTerminator = Latch->getTerminator();
@@ -281,15 +282,13 @@
       BI != BE; ++BI) {
     Instruction *I = BI;
 
-    // PHI Nodes are OK.
+    // PHI Nodes are OK. FIXME : Handle last value assignments.
     if (isa<PHINode>(I))
       continue;
 
     // SplitCondition itself is OK.
-    if (ICmpInst *CI = dyn_cast<ICmpInst>(I)) {
-      if (CI == SplitCondition)
-        continue;
-    }
+    if (I == SplitCondition)
+      continue;
 
     // Terminator is also harmless.
     if (I == Terminator)
@@ -307,12 +306,12 @@
 bool LoopIndexSplit::safeExitBlock(BasicBlock *ExitBlock) {
 
   Instruction *IndVarIncrement = NULL;
-      
+
   for (BasicBlock::iterator BI = ExitBlock->begin(), BE = ExitBlock->end();
        BI != BE; ++BI) {
     Instruction *I = BI;
 
-    // PHI Nodes are OK.
+    // PHI Nodes are OK. FIXME : Handle last value assignments.
     if (isa<PHINode>(I))
       continue;
 
@@ -338,6 +337,7 @@
       if (IndVarIncrement && PN == IndVar && CI->isOne())
         continue;
     }
+
     // I is an Exit condition if next instruction is block terminator.
     // Exit condition is OK if it compares loop invariant exit value,
     // which is checked below.
@@ -346,7 +346,7 @@
       Instruction *N = BI;
       if (N == ExitBlock->getTerminator()) {
         ExitCondition = EC;
-        break;
+        continue;
       }
     }
 





More information about the llvm-commits mailing list