llvm.org GIT mirror llvm / 0a65c23
[BPI] Ignore remainder while distributing the remaining probability from unreachanble This is a follow up patch for https://reviews.llvm.org/rL300440 to address a comment. To make implementation to be consistent with other cases we just ignore the remainder after distribution of remaining probability between reachable edges. If we reduced the probability of some edges coming to unreachable blocks we should distribute the remaining part across other edges coming to reachable blocks to satisfy the condition that sum of all probabilities should be equal to one. If this remaining part is not divided by number of "reachable" edges then we get this remainder. This remainder probability should be pretty small. Other cases just ignore if the sum of probabilities is not equal to one so we do the same. Reviewers: chandlerc, sanjoy, vsk, junbuml, reames Reviewed By: reames Subscribers: reames, llvm-commits Differential Revision: https://reviews.llvm.org/D32124 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302883 91177308-0d34-0410-b5e6-96231b3b80d8 Serguei Katkov 3 years ago
2 changed file(s) with 6 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
300300 WeightSum += Weights[i];
301301 }
302302 }
303 assert(WeightSum <= UINT32_MAX &&
304 "Expected weights to scale down to 32 bits");
303305
304306 if (WeightSum == 0 || ReachableIdxs.size() == 0) {
305307 for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
327329 // the difference between reachable blocks.
328330 if (ToDistribute > BranchProbability::getZero()) {
329331 BranchProbability PerEdge = ToDistribute / ReachableIdxs.size();
330 for (auto i : ReachableIdxs) {
332 for (auto i : ReachableIdxs)
331333 BP[i] += PerEdge;
332 ToDistribute -= PerEdge;
333 }
334 // Tail goes to the first reachable edge.
335 BP[ReachableIdxs[0]] += ToDistribute;
336334 }
337335 }
338336
339337 for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
340338 setEdgeProbability(BB, i, BP[i]);
341
342 assert(WeightSum <= UINT32_MAX &&
343 "Expected weights to scale down to 32 bits");
344339
345340 return true;
346341 }
451451 i32 3, label %case_d
452452 i32 4, label %case_e ], !prof !8
453453 ; CHECK: edge entry -> case_a probability is 0x00000800 / 0x80000000 = 0.00%
454 ; CHECK: edge entry -> case_b probability is 0x07fffe01 / 0x80000000 = 6.25%
454 ; CHECK: edge entry -> case_b probability is 0x07fffdff / 0x80000000 = 6.25%
455455 ; CHECK: edge entry -> case_c probability is 0x67fffdff / 0x80000000 = 81.25% [HOT edge]
456456 ; CHECK: edge entry -> case_d probability is 0x07fffdff / 0x80000000 = 6.25%
457457 ; CHECK: edge entry -> case_e probability is 0x07fffdff / 0x80000000 = 6.25%
494494 i32 4, label %case_e ], !prof !9
495495 ; CHECK: edge entry -> case_a probability is 0x00000400 / 0x80000000 = 0.00%
496496 ; CHECK: edge entry -> case_b probability is 0x00000400 / 0x80000000 = 0.00%
497 ; CHECK: edge entry -> case_c probability is 0x6aaaa800 / 0x80000000 = 83.33% [HOT edge]
497 ; CHECK: edge entry -> case_c probability is 0x6aaaa7ff / 0x80000000 = 83.33% [HOT edge]
498498 ; CHECK: edge entry -> case_d probability is 0x0aaaa7ff / 0x80000000 = 8.33%
499499 ; CHECK: edge entry -> case_e probability is 0x0aaaa7ff / 0x80000000 = 8.33%
500500
534534 i32 4, label %case_e ], !prof !10
535535 ; CHECK: edge entry -> case_a probability is 0x00000000 / 0x80000000 = 0.00%
536536 ; CHECK: edge entry -> case_b probability is 0x00000400 / 0x80000000 = 0.00%
537 ; CHECK: edge entry -> case_c probability is 0x6e08fa2e / 0x80000000 = 85.96% [HOT edge]
537 ; CHECK: edge entry -> case_c probability is 0x6e08fa2d / 0x80000000 = 85.96% [HOT edge]
538538 ; CHECK: edge entry -> case_d probability is 0x08fb80e9 / 0x80000000 = 7.02%
539539 ; CHECK: edge entry -> case_e probability is 0x08fb80e9 / 0x80000000 = 7.02%
540540