[PATCH] D32124: [BPI] Move tail computation out of the loop. NFC
Serguei Katkov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 20 21:00:08 PDT 2017
skatkov updated this revision to Diff 96090.
https://reviews.llvm.org/D32124
Files:
lib/Analysis/BranchProbabilityInfo.cpp
Index: lib/Analysis/BranchProbabilityInfo.cpp
===================================================================
--- lib/Analysis/BranchProbabilityInfo.cpp
+++ lib/Analysis/BranchProbabilityInfo.cpp
@@ -301,6 +301,8 @@
WeightSum += Weights[i];
}
}
+ assert(WeightSum <= UINT32_MAX &&
+ "Expected weights to scale down to 32 bits");
if (WeightSum == 0 || ReachableIdxs.size() == 0) {
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
@@ -328,21 +330,18 @@
// the difference between reachable blocks.
if (ToDistribute > BranchProbability::getZero()) {
BranchProbability PerEdge = ToDistribute / ReachableIdxs.size();
- for (auto i : ReachableIdxs) {
+ for (auto i : ReachableIdxs)
BP[i] += PerEdge;
- ToDistribute -= PerEdge;
- }
// Tail goes to the first reachable edge.
- BP[ReachableIdxs[0]] += ToDistribute;
+ BranchProbability Tail = ToDistribute - (PerEdge * ReachableIdxs.size());
+ assert(Tail.getNumerator() < ReachableIdxs.size() && "Tail is too big!");
+ BP[ReachableIdxs[0]] += Tail;
}
}
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
setEdgeProbability(BB, i, BP[i]);
- assert(WeightSum <= UINT32_MAX &&
- "Expected weights to scale down to 32 bits");
-
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32124.96090.patch
Type: text/x-patch
Size: 1352 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170421/361d848d/attachment.bin>
More information about the llvm-commits
mailing list