From: Xinliang David Li Date: Wed, 15 Jun 2016 03:03:30 +0000 (+0000) Subject: [MBP] add comments and bug fix X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b2ccb9b91c3944580c4ef72038751958000aa439;p=llvm [MBP] add comments and bug fix Document the new parameter and threshod computation model. Also fix a bug when the threshold parameter is set to be different from the default. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272749 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/MachineBlockPlacement.cpp b/lib/CodeGen/MachineBlockPlacement.cpp index 7379a3099b1..332755d0ff4 100644 --- a/lib/CodeGen/MachineBlockPlacement.cpp +++ b/lib/CodeGen/MachineBlockPlacement.cpp @@ -530,9 +530,19 @@ static BranchProbability getLayoutSuccessorProbThreshold( if (BB->succ_size() == 2) { const MachineBasicBlock *Succ1 = *BB->succ_begin(); const MachineBasicBlock *Succ2 = *(BB->succ_begin() + 1); - if (Succ1->isSuccessor(Succ2) || Succ2->isSuccessor(Succ1)) - return BranchProbability( - 200 - 2 * ProfileLikelyProb, 200 - ProfileLikelyProb); + if (Succ1->isSuccessor(Succ2) || Succ2->isSuccessor(Succ1)) { + /* See case 1 below for the cost analysis. For BB->Succ to + * be taken with smaller cost, the following needs to hold: + * Prob(BB->Succ) > 2* Prob(BB->Pred) + * So the threshold T + * T = 2 * (1-Prob(BB->Pred). Since T + Prob(BB->Pred) == 1, + * We have T + T/2 = 1, i.e. T = 2/3. Also adding user specified + * branch bias, we have + * T = (2/3)*(ProfileLikelyProb/50) + * = (2*ProfileLikelyProb)/150) + */ + return BranchProbability(2 * ProfileLikelyProb, 150); + } } return BranchProbability(ProfileLikelyProb, 100); } diff --git a/lib/CodeGen/MachineBranchProbabilityInfo.cpp b/lib/CodeGen/MachineBranchProbabilityInfo.cpp index 9e14cb621dd..fe734061837 100644 --- a/lib/CodeGen/MachineBranchProbabilityInfo.cpp +++ b/lib/CodeGen/MachineBranchProbabilityInfo.cpp @@ -24,15 +24,16 @@ INITIALIZE_PASS_BEGIN(MachineBranchProbabilityInfo, "machine-branch-prob", INITIALIZE_PASS_END(MachineBranchProbabilityInfo, "machine-branch-prob", "Machine Branch Probability Analysis", false, true) -cl::opt StaticLikelyProb( - "static-likely-prob", - cl::desc("branch probability threshold to be considered very likely"), - cl::init(80), cl::Hidden); +cl::opt + StaticLikelyProb("static-likely-prob", + cl::desc("branch probability threshold in percentage" + "to be considered very likely"), + cl::init(80), cl::Hidden); cl::opt ProfileLikelyProb( "profile-likely-prob", - cl::desc("branch probability threshold to be considered very likely " - "when profile is available"), + cl::desc("branch probability threshold in percentage to be considered" + " very likely when profile is available"), cl::init(51), cl::Hidden); char MachineBranchProbabilityInfo::ID = 0;