PGO branch weight: keep halving the weights until they can fit into

uint32.

When folding branches to common destination, the updated branch weights
can exceed uint32 by more than factor of 2. We should keep halving the
weights until they can fit into uint32.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200262 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Manman Ren
2014-01-27 23:39:03 +00:00
parent 01df6842c1
commit aa6627016f
2 changed files with 44 additions and 13 deletions

View File

@@ -748,21 +748,22 @@ static void GetBranchWeights(TerminatorInst *TI,
}
}
/// Sees if any of the weights are too big for a uint32_t, and halves all the
/// weights if any are.
/// Keep halving the weights until all can fit in uint32_t.
static void FitWeights(MutableArrayRef<uint64_t> Weights) {
bool Halve = false;
for (unsigned i = 0; i < Weights.size(); ++i)
if (Weights[i] > UINT_MAX) {
Halve = true;
break;
}
while (true) {
bool Halve = false;
for (unsigned i = 0; i < Weights.size(); ++i)
if (Weights[i] > UINT_MAX) {
Halve = true;
break;
}
if (! Halve)
return;
if (! Halve)
return;
for (unsigned i = 0; i < Weights.size(); ++i)
Weights[i] /= 2;
for (unsigned i = 0; i < Weights.size(); ++i)
Weights[i] /= 2;
}
}
/// FoldValueComparisonIntoPredecessors - The specified terminator is a value