From: Cong Hou Date: Tue, 15 Dec 2015 10:10:40 +0000 (+0000) Subject: Improve the successor list update in TailDuplication.cpp. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=892628b503eba347a9415e126073c42ebeb63f35;p=oota-llvm.git Improve the successor list update in TailDuplication.cpp. 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 --- diff --git a/lib/CodeGen/TailDuplication.cpp b/lib/CodeGen/TailDuplication.cpp index 1f5b54866ac..132c069d69e 100644 --- a/lib/CodeGen/TailDuplication.cpp +++ b/lib/CodeGen/TailDuplication.cpp @@ -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); } diff --git a/test/CodeGen/ARM/taildup-branch-weight.ll b/test/CodeGen/ARM/taildup-branch-weight.ll index 799ef62416e..6f8d245e74a 100644 --- a/test/CodeGen/ARM/taildup-branch-weight.ll +++ b/test/CodeGen/ARM/taildup-branch-weight.ll @@ -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