Change SplitBlock to increment a BasicBlock::iterator, not an Instruction*. Apparent...
authorChris Lattner <sabre@nondot.org>
Thu, 16 Feb 2006 19:36:22 +0000 (19:36 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 16 Feb 2006 19:36:22 +0000 (19:36 +0000)
This fixes a testcase that nate reduced from spass.

Also included are a couple minor code changes that don't affect the generated
code at all.

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

lib/Transforms/Scalar/LoopUnswitch.cpp

index 2232ac754d56434737271f3daf03968f30567571..ecd5ae46e1d3440d046d189149bad951eda73672 100644 (file)
@@ -397,9 +397,10 @@ bool LoopUnswitch::UnswitchIfProfitable(Value *LoopCond, Constant *Val,Loop *L){
 /// the loop info is updated.
 ///
 BasicBlock *LoopUnswitch::SplitBlock(BasicBlock *Old, Instruction *SplitPt) {
-  while (isa<PHINode>(SplitPt))
-    ++SplitPt;
-  BasicBlock *New = Old->splitBasicBlock(SplitPt, Old->getName()+".split");
+  BasicBlock::iterator SplitIt = SplitPt;
+  while (isa<PHINode>(SplitIt))
+    ++SplitIt;
+  BasicBlock *New = Old->splitBasicBlock(SplitIt, Old->getName()+".split");
 
   // The new block lives in whichever loop the old one did.
   if (Loop *L = LI->getLoopFor(Old))
@@ -703,27 +704,30 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC,
   // Haha, this loop could be unswitched.  Get it? The unswitch pass could
   // unswitch itself. Amazing.
   for (unsigned i = 0, e = Users.size(); i != e; ++i)
-    if (Instruction *U = cast<Instruction>(Users[i]))
-      if (L->contains(U->getParent()))
-        if (IsEqual) {
-          U->replaceUsesOfWith(LIC, Val);
-        } else if (NotVal) {
-          U->replaceUsesOfWith(LIC, NotVal);
-        } else {
-          // If we know that LIC is not Val, use this info to simplify code.
-          if (SwitchInst *SI = dyn_cast<SwitchInst>(U)) {
-            for (unsigned i = 1, e = SI->getNumCases(); i != e; ++i) {
-              if (SI->getCaseValue(i) == Val) {
-                // Found a dead case value.  Don't remove PHI nodes in the 
-                // successor if they become single-entry, those PHI nodes may
-                // be in the Users list.
-                SI->getSuccessor(i)->removePredecessor(SI->getParent(), true);
-                SI->removeCase(i);
-                break;
-              }
+    if (Instruction *U = cast<Instruction>(Users[i])) {
+      if (!L->contains(U->getParent()))
+        continue;
+  
+      if (IsEqual) {
+        U->replaceUsesOfWith(LIC, Val);
+      } else if (NotVal) {
+        U->replaceUsesOfWith(LIC, NotVal);
+      } else {
+        // If we know that LIC is not Val, use this info to simplify code.
+        if (SwitchInst *SI = dyn_cast<SwitchInst>(U)) {
+          for (unsigned i = 1, e = SI->getNumCases(); i != e; ++i) {
+            if (SI->getCaseValue(i) == Val) {
+              // Found a dead case value.  Don't remove PHI nodes in the 
+              // successor if they become single-entry, those PHI nodes may
+              // be in the Users list.
+              SI->getSuccessor(i)->removePredecessor(SI->getParent(), true);
+              SI->removeCase(i);
+              break;
             }
           }
-
-          // TODO: We could simplify stuff like X == C.
         }
+
+        // TODO: We could simplify stuff like X == C.
+      }
+    }
 }