Fix a bug in MachineBlockPlacement that may cause assertion failure during BranchProb...
authorCong Hou <congh@google.com>
Tue, 1 Dec 2015 00:55:42 +0000 (00:55 +0000)
committerCong Hou <congh@google.com>
Tue, 1 Dec 2015 00:55:42 +0000 (00:55 +0000)
The root cause is the rounding behavior in BranchProbability construction. We may consider to use truncation instead in the future.

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

lib/CodeGen/MachineBlockPlacement.cpp

index ddddd483e8013ea9bcdfdf4ec056423005057825..fcddf346cf680cf2221e730a86f3b047425161d7 100644 (file)
@@ -423,9 +423,13 @@ MachineBlockPlacement::selectBestSuccessor(MachineBasicBlock *BB,
 
   DEBUG(dbgs() << "Attempting merge from: " << getBlockName(BB) << "\n");
   for (MachineBasicBlock *Succ : Successors) {
-    BranchProbability SuccProb(
-        MBPI->getEdgeProbability(BB, Succ).getNumerator(),
-        AdjustedSumProb.getNumerator());
+    BranchProbability SuccProb;
+    uint32_t SuccProbN = MBPI->getEdgeProbability(BB, Succ).getNumerator();
+    uint32_t SuccProbD = AdjustedSumProb.getNumerator();
+    if (SuccProbN >= SuccProbD)
+      SuccProb = BranchProbability::getOne();
+    else
+      SuccProb = BranchProbability(SuccProbN, SuccProbD);
 
     // If we outline optional branches, look whether Succ is unavoidable, i.e.
     // dominates all terminators of the MachineFunction. If it does, other