Improve the successor list update in TailDuplication.cpp.
authorCong Hou <congh@google.com>
Tue, 15 Dec 2015 10:10:40 +0000 (10:10 +0000)
committerCong Hou <congh@google.com>
Tue, 15 Dec 2015 10:10:40 +0000 (10:10 +0000)
This patch improves a temporary fix in r255530 so that we can normalize
successor list without trigger assertion failures in tail duplication pass.

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

lib/CodeGen/TailDuplication.cpp
test/CodeGen/ARM/taildup-branch-weight.ll

index 1f5b54866ac627179045d51751a2e3417e3ddcc5..132c069d69efefb751e350044c9cbdc678e414e5 100644 (file)
@@ -745,12 +745,12 @@ TailDuplicatePass::duplicateSimpleBB(MachineBasicBlock *TailBB,
     if (PredTBB)
       TII->InsertBranch(*PredBB, PredTBB, PredFBB, PredCond, DebugLoc());
 
-    auto Prob = MBPI->getEdgeProbability(PredBB, TailBB);
-    PredBB->removeSuccessor(TailBB);
-    unsigned NumSuccessors = PredBB->succ_size();
-    assert(NumSuccessors <= 1);
-    if (NumSuccessors == 0 || *PredBB->succ_begin() != NewTarget)
-      PredBB->addSuccessor(NewTarget, Prob);
+    if (!PredBB->isSuccessor(NewTarget))
+      PredBB->replaceSuccessor(TailBB, NewTarget);
+    else {
+      PredBB->removeSuccessor(TailBB, 0);
+      assert(PredBB->succ_size() <= 1);
+    }
 
     TDBBs.push_back(PredBB);
   }
index 799ef62416e6aa507a5fedb8fb162a66067494ae..6f8d245e74a02bd23d668ff128725e156ba020b8 100644 (file)
@@ -30,7 +30,7 @@ B4:
 !0 = !{!"branch_weights", i32 4, i32 124}
 
 ; CHECK: Machine code for function test1:
-; CHECK: Successors according to CFG: BB#1({{[0-9a-fx/= ]+}}3.12%) BB#2({{[0-9a-fx/= ]+}}96.88%)
+; CHECK: Successors according to CFG: BB#2(0x7c000000 / 0x80000000 = 96.88%) BB#1(0x04000000 / 0x80000000 = 3.12%)
 
 @g0 = common global i32 0, align 4