summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/BranchProbabilityTest.cpp
diff options
context:
space:
mode:
authorCong Hou <congh@google.com>2015-10-14 23:14:17 +0000
committerCong Hou <congh@google.com>2015-10-14 23:14:17 +0000
commitb74d3b3b86c606ca72315efd252300fde0db3691 (patch)
tree6bc9d74ce52e91d77d3e27f09a7b32763b2b1b0a /llvm/unittests/Support/BranchProbabilityTest.cpp
parentaae328d6eb1012747c8672f74d99e4359f465055 (diff)
downloadbcm5719-llvm-b74d3b3b86c606ca72315efd252300fde0db3691.tar.gz
bcm5719-llvm-b74d3b3b86c606ca72315efd252300fde0db3691.zip
Update the branch weight metadata in JumpThreading pass.
Currently in JumpThreading pass, the branch weight metadata is not updated after CFG modification. Consider the jump threading on PredBB, BB, and SuccBB. After jump threading, the weight on BB->SuccBB should be adjusted as some of it is contributed by the edge PredBB->BB, which doesn't exist anymore. This patch tries to update the edge weight in metadata on BB->SuccBB by scaling it by 1 - Freq(PredBB->BB) / Freq(BB->SuccBB). This is the third attempt to submit this patch, while the first two led to failures in some FDO tests. After investigation, it is the edge weight normalization that caused those failures. In this patch the edge weight normalization is fixed so that there is no zero weight in the output and the sum of all weights can fit in 32-bit integer. Several unit tests are added. Differential revision: http://reviews.llvm.org/D10979 llvm-svn: 250345
Diffstat (limited to 'llvm/unittests/Support/BranchProbabilityTest.cpp')
-rw-r--r--llvm/unittests/Support/BranchProbabilityTest.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/llvm/unittests/Support/BranchProbabilityTest.cpp b/llvm/unittests/Support/BranchProbabilityTest.cpp
index 87a25091947..37a5c3f0dc8 100644
--- a/llvm/unittests/Support/BranchProbabilityTest.cpp
+++ b/llvm/unittests/Support/BranchProbabilityTest.cpp
@@ -287,4 +287,45 @@ TEST(BranchProbabilityTest, scaleBruteForce) {
}
}
+TEST(BranchProbabilityTest, NormalizeEdgeWeights) {
+ {
+ SmallVector<uint32_t, 2> Weights{0, 0};
+ BranchProbability::normalizeEdgeWeights(Weights.begin(), Weights.end());
+ EXPECT_EQ(1u, Weights[0]);
+ EXPECT_EQ(1u, Weights[1]);
+ }
+ {
+ SmallVector<uint32_t, 2> Weights{0, UINT32_MAX};
+ BranchProbability::normalizeEdgeWeights(Weights.begin(), Weights.end());
+ EXPECT_EQ(1u, Weights[0]);
+ EXPECT_EQ(UINT32_MAX - 1u, Weights[1]);
+ }
+ {
+ SmallVector<uint32_t, 2> Weights{1, UINT32_MAX};
+ BranchProbability::normalizeEdgeWeights(Weights.begin(), Weights.end());
+ EXPECT_EQ(1u, Weights[0]);
+ EXPECT_EQ(UINT32_MAX - 1u, Weights[1]);
+ }
+ {
+ SmallVector<uint32_t, 3> Weights{0, 0, UINT32_MAX};
+ BranchProbability::normalizeEdgeWeights(Weights.begin(), Weights.end());
+ EXPECT_EQ(1u, Weights[0]);
+ EXPECT_EQ(1u, Weights[1]);
+ EXPECT_EQ(UINT32_MAX / 2u, Weights[2]);
+ }
+ {
+ SmallVector<uint32_t, 2> Weights{UINT32_MAX, UINT32_MAX};
+ BranchProbability::normalizeEdgeWeights(Weights.begin(), Weights.end());
+ EXPECT_EQ(UINT32_MAX / 3u, Weights[0]);
+ EXPECT_EQ(UINT32_MAX / 3u, Weights[1]);
+ }
+ {
+ SmallVector<uint32_t, 3> Weights{UINT32_MAX, UINT32_MAX, UINT32_MAX};
+ BranchProbability::normalizeEdgeWeights(Weights.begin(), Weights.end());
+ EXPECT_EQ(UINT32_MAX / 4u, Weights[0]);
+ EXPECT_EQ(UINT32_MAX / 4u, Weights[1]);
+ EXPECT_EQ(UINT32_MAX / 4u, Weights[2]);
+ }
+}
+
}
OpenPOWER on IntegriCloud