fix PR5698
authorChris Lattner <sabre@nondot.org>
Sun, 6 Dec 2009 17:17:23 +0000 (17:17 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 6 Dec 2009 17:17:23 +0000 (17:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90708 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/JumpThreading.cpp
test/Transforms/JumpThreading/crash.ll

index 1b93f3441e4131df87eabd549d96f8952c292c96..d58b9c9de012b64574050041987cea80fd013f77 100644 (file)
@@ -718,6 +718,11 @@ bool JumpThreading::ProcessSwitchOnDuplicateCond(BasicBlock *PredBB,
       if (PredSI->getSuccessor(PredCase) != DestBB &&
           DestSI->getSuccessor(i) != DestBB)
         continue;
+      
+      // Do not forward this if it already goes to this destination, this would
+      // be an infinite loop.
+      if (PredSI->getSuccessor(PredCase) == DestSucc)
+        continue;
 
       // Otherwise, we're safe to make the change.  Make sure that the edge from
       // DestSI to DestSucc is not critical and has no PHI nodes.
index b2b9d69e16d2fcfa0db6dc0df0f60ee7d6f9028d..361ec6cfb5a1367628d9c62e48ce83c837f6c56e 100644 (file)
@@ -212,3 +212,25 @@ bb13:
 bb61:                                            
   ret void
 }
+
+
+; PR5698
+define void @test7(i32 %x) {
+tailrecurse:
+  switch i32 %x, label %return [
+    i32 2, label %bb2
+    i32 3, label %bb
+  ]
+
+bb:         
+  switch i32 %x, label %return [
+    i32 2, label %bb2
+    i32 3, label %tailrecurse
+  ]
+
+bb2:        
+  ret void
+
+return:     
+  ret void
+}