Rewrite previous patch to follow Chris' stylistic
preference; no functional change.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78391 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp
index d25152b..1ab3df2 100644
--- a/lib/CodeGen/BranchFolding.cpp
+++ b/lib/CodeGen/BranchFolding.cpp
@@ -850,6 +850,27 @@
   return CanFallThrough(CurBB, CurUnAnalyzable, TBB, FBB, Cond);
 }
 
+/// RemoveDuplicateSuccessor - make sure block Pred has at most one
+/// successor edge leading to Succ.  This is only called in one place,
+/// but Chris prefers that it be a separate function.
+static void RemoveDuplicateSuccessor(MachineBasicBlock *Pred,
+                                     MachineBasicBlock *Succ) {
+  MachineBasicBlock::succ_iterator SI = Pred->succ_begin();
+  bool found = false;
+  while (SI != Pred->succ_end()) {
+    if (*SI == Succ) {
+      if (!found) {
+        found = true;
+        ++SI;
+      } else {
+        SI = Pred->removeSuccessor(SI);
+      }
+    } else {
+      ++SI;
+    }
+  }
+}
+
 /// IsBetterFallthrough - Return true if it would be clearly better to
 /// fall-through to MBB1 than to fall through into MBB2.  This has to return
 /// a strict ordering, returning true for both (MBB1,MBB2) and (MBB2,MBB1) will
@@ -896,20 +917,7 @@
         // If this resulted in a predecessor with true and false edges
         // both going to the fallthrough block, clean up; 
         // BranchFolding doesn't like this.
-        MachineBasicBlock::succ_iterator SI = Pred->succ_begin();
-        bool found = false;
-        while (SI != Pred->succ_end()) {
-          if (*SI == FallThrough) {
-            if (!found) {
-              found = true;
-              ++SI;
-            } else {
-              SI = Pred->removeSuccessor(SI);
-            }
-          } else {
-            ++SI;
-          }
-        }
+        RemoveDuplicateSuccessor(Pred, FallThrough);
       }
       // If MBB was the target of a jump table, update jump tables to go to the
       // fallthrough instead.