summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2013-06-21 19:30:05 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2013-06-21 19:30:05 +0000
commit93702a3b0754052d926c75082abf7ca156b80c45 (patch)
tree10b032704125296644321d26cc84d3053da88dc7 /lib
parent65af4b5333f539b9e572ebb9c4d4e97a897e5130 (diff)
downloadllvm-93702a3b0754052d926c75082abf7ca156b80c45.tar.gz
llvm-93702a3b0754052d926c75082abf7ca156b80c45.tar.bz2
llvm-93702a3b0754052d926c75082abf7ca156b80c45.tar.xz
BlockFrequency: Saturate at 1 instead of 0 when multiplying a frequency with a branch probability.
Zero is used by BlockFrequencyInfo as a special "don't know" value. It also causes a sink for frequencies as you can't ever get off a zero frequency with more multiplies. This recovers a 10% regression on MultiSource/Benchmarks/7zip. A zero frequency was propagated into an inner loop causing excessive spilling. PR16402. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184584 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Support/BlockFrequency.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/Support/BlockFrequency.cpp b/lib/Support/BlockFrequency.cpp
index 84a993e3e5..53bbd8ad12 100644
--- a/lib/Support/BlockFrequency.cpp
+++ b/lib/Support/BlockFrequency.cpp
@@ -65,6 +65,9 @@ uint64_t div96bit(uint64_t W[2], uint32_t D) {
BlockFrequency &BlockFrequency::operator*=(const BranchProbability &Prob) {
+ if (Frequency == 0)
+ return *this;
+
uint32_t n = Prob.getNumerator();
uint32_t d = Prob.getDenominator();
@@ -84,10 +87,15 @@ BlockFrequency &BlockFrequency::operator*=(const BranchProbability &Prob) {
// 64-bit.
mult96bit(Frequency, n, W);
Frequency = div96bit(W, d);
- return *this;
+ } else {
+ // Fast case.
+ Frequency = mulRes / d;
}
- Frequency = mulRes / d;
+ // Limit the result to 1; 0 is a sentinel value. This keeps BlockFrequencyInfo
+ // from getting stuck at zero frequencies just because a value became too
+ // small to be represented as a BlockFrequency.
+ Frequency = (n == 0 || Frequency != 0) ? Frequency : 1;
return *this;
}