From 0f4012ca9d0e7a6dba7862201d8267681c0e43b0 Mon Sep 17 00:00:00 2001
From: Eli Friedman <eli.friedman@gmail.com>
Date: Thu, 21 May 2009 20:40:30 +0000
Subject: [PATCH] Fix some incorrect logic in DominanceFrontier::splitBlock. 
 Part of PR4238.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72223 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/VMCore/Dominators.cpp                                 | 8 +++-----
 .../2004-04-13-LoopSimplifyUpdateDomFrontier.ll           | 2 +-
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp
index 6f1de466043..735a70c5092 100644
--- a/lib/VMCore/Dominators.cpp
+++ b/lib/VMCore/Dominators.cpp
@@ -160,10 +160,7 @@ void DominanceFrontier::splitBlock(BasicBlock *NewBB) {
         break;
       }
     }
-    
-    if (!BlockDominatesAny)
-      continue;
-    
+
     // If NewBBSucc should not stay in our dominator frontier, remove it.
     // We remove it unless there is a predecessor of NewBBSucc that we
     // dominate, but we don't strictly dominate NewBBSucc.
@@ -181,7 +178,8 @@ void DominanceFrontier::splitBlock(BasicBlock *NewBB) {
     
     if (ShouldRemove)
       removeFromFrontier(DFI, NewBBSucc);
-    addToFrontier(DFI, NewBB);
+    if (BlockDominatesAny && (&*FI == NewBB || !DT.dominates(FI, NewBB)))
+      addToFrontier(DFI, NewBB);
   }
 }
 
diff --git a/test/Transforms/LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll b/test/Transforms/LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll
index 427631c07f2..bd0515c476e 100644
--- a/test/Transforms/LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll
+++ b/test/Transforms/LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll
@@ -1,4 +1,4 @@
-; RUN: llvm-as < %s | opt -scalarrepl -loopsimplify -licm -disable-output
+; RUN: llvm-as < %s | opt -scalarrepl -loopsimplify -licm -disable-output -verify-dom-info
 
 define void @inflate() {
 entry: