X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=unittests%2FSupport%2FBranchProbabilityTest.cpp;fp=unittests%2FSupport%2FBranchProbabilityTest.cpp;h=37a5c3f0dc877a1b740aaeb3e3a7a22019dc488e;hp=87a250919475aad3b32c91e024d9fcddc5429b43;hb=0f34207b1d601aed2fe306baf199d5742ba0a80b;hpb=c4c3678da9e188349185525b7b242dddeb25db22 diff --git a/unittests/Support/BranchProbabilityTest.cpp b/unittests/Support/BranchProbabilityTest.cpp index 87a25091947..37a5c3f0dc8 100644 --- a/unittests/Support/BranchProbabilityTest.cpp +++ b/unittests/Support/BranchProbabilityTest.cpp @@ -287,4 +287,45 @@ TEST(BranchProbabilityTest, scaleBruteForce) { } } +TEST(BranchProbabilityTest, NormalizeEdgeWeights) { + { + SmallVector Weights{0, 0}; + BranchProbability::normalizeEdgeWeights(Weights.begin(), Weights.end()); + EXPECT_EQ(1u, Weights[0]); + EXPECT_EQ(1u, Weights[1]); + } + { + SmallVector Weights{0, UINT32_MAX}; + BranchProbability::normalizeEdgeWeights(Weights.begin(), Weights.end()); + EXPECT_EQ(1u, Weights[0]); + EXPECT_EQ(UINT32_MAX - 1u, Weights[1]); + } + { + SmallVector Weights{1, UINT32_MAX}; + BranchProbability::normalizeEdgeWeights(Weights.begin(), Weights.end()); + EXPECT_EQ(1u, Weights[0]); + EXPECT_EQ(UINT32_MAX - 1u, Weights[1]); + } + { + SmallVector 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 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 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]); + } +} + }