llvm.org GIT mirror llvm / a908bba
Revert "[BPI] Use a safer constructor to calculate branch probabilities" This reverts commit r290016. It breaks this bot, even though the test passes locally: http://bb.pgr.jp/builders/ninja-x64-msvc-RA-centos6/builds/32956/ AnalysisTests: /home/bb/ninja-x64-msvc-RA-centos6/llvm-project/llvm/lib/Support/BranchProbability.cpp:52: static llvm::BranchProbability llvm::BranchProbability::getBranchProbability(uint64_t, uint64_t): Assertion `Numerator <= Denominator && "Probability cannot be bigger than 1!"' failed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290019 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 2 years ago
3 changed file(s) with 12 addition(s) and 101 deletion(s). Raw diff Collapse all Expand all
161161 return true;
162162 }
163163
164 auto UnreachableProb = BranchProbability::getBranchProbability(
165 UR_TAKEN_WEIGHT,
166 (UR_TAKEN_WEIGHT + UR_NONTAKEN_WEIGHT) * UnreachableEdges.size());
167 auto ReachableProb = BranchProbability::getBranchProbability(
168 UR_NONTAKEN_WEIGHT,
169 (UR_TAKEN_WEIGHT + UR_NONTAKEN_WEIGHT) * ReachableEdges.size());
164 BranchProbability UnreachableProb(UR_TAKEN_WEIGHT,
165 (UR_TAKEN_WEIGHT + UR_NONTAKEN_WEIGHT) *
166 UnreachableEdges.size());
167 BranchProbability ReachableProb(UR_NONTAKEN_WEIGHT,
168 (UR_TAKEN_WEIGHT + UR_NONTAKEN_WEIGHT) *
169 ReachableEdges.size());
170170
171171 for (unsigned SuccIdx : UnreachableEdges)
172172 setEdgeProbability(BB, SuccIdx, UnreachableProb);
299299 return true;
300300 }
301301
302 auto ColdProb = BranchProbability::getBranchProbability(
303 CC_TAKEN_WEIGHT,
304 (CC_TAKEN_WEIGHT + CC_NONTAKEN_WEIGHT) * ColdEdges.size());
305 auto NormalProb = BranchProbability::getBranchProbability(
306 CC_NONTAKEN_WEIGHT,
307 (CC_TAKEN_WEIGHT + CC_NONTAKEN_WEIGHT) * NormalEdges.size());
302 BranchProbability ColdProb(CC_TAKEN_WEIGHT,
303 (CC_TAKEN_WEIGHT + CC_NONTAKEN_WEIGHT) *
304 ColdEdges.size());
305 BranchProbability NormalProb(CC_NONTAKEN_WEIGHT,
306 (CC_TAKEN_WEIGHT + CC_NONTAKEN_WEIGHT) *
307 NormalEdges.size());
308308
309309 for (unsigned SuccIdx : ColdEdges)
310310 setEdgeProbability(BB, SuccIdx, ColdProb);
+0
-88
unittests/Analysis/BranchProbabilityInfoTest.cpp less more
None //===- BranchProbabilityInfoTest.cpp - BranchProbabilityInfo unit tests ---===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Analysis/BranchProbabilityInfo.h"
10 #include "llvm/Analysis/LoopInfo.h"
11 #include "llvm/AsmParser/Parser.h"
12 #include "llvm/IR/BasicBlock.h"
13 #include "llvm/IR/Constants.h"
14 #include "llvm/IR/Dominators.h"
15 #include "llvm/IR/Instructions.h"
16 #include "llvm/IR/Function.h"
17 #include "llvm/IR/LLVMContext.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/Support/DataTypes.h"
20 #include "llvm/Support/SourceMgr.h"
21 #include "llvm/Support/raw_ostream.h"
22 #include "gtest/gtest.h"
23
24 namespace llvm {
25 namespace {
26
27 struct BranchProbabilityInfoTest : public testing::Test {
28 std::unique_ptr BPI;
29 std::unique_ptr DT;
30 std::unique_ptr LI;
31 LLVMContext C;
32
33 BranchProbabilityInfo &buildBPI(Function &F) {
34 DT.reset(new DominatorTree(F));
35 LI.reset(new LoopInfo(*DT));
36 BPI.reset(new BranchProbabilityInfo(F, *LI));
37 return *BPI;
38 }
39
40 std::unique_ptr makeLLVMModule() {
41 const char *ModuleString = "define void @f() { exit: ret void }\n";
42 SMDiagnostic Err;
43 return parseAssemblyString(ModuleString, Err, C);
44 }
45 };
46
47 TEST_F(BranchProbabilityInfoTest, StressUnreachableHeuristic) {
48 auto M = makeLLVMModule();
49 Function *F = M->getFunction("f");
50
51 // define void @f() {
52 // entry:
53 // switch i32 undef, label %exit, [
54 // i32 0, label %preexit
55 // ... ;;< Add lots of cases to stress the heuristic.
56 // ]
57 // preexit:
58 // unreachable
59 // exit:
60 // ret void
61 // }
62
63 auto *ExitBB = &F->back();
64 auto *EntryBB = BasicBlock::Create(C, "entry", F, /*insertBefore=*/ExitBB);
65
66 auto *PreExitBB =
67 BasicBlock::Create(C, "preexit", F, /*insertBefore=*/ExitBB);
68 new UnreachableInst(C, PreExitBB);
69
70 unsigned NumCases = 4096;
71 auto *I32 = IntegerType::get(C, 32);
72 auto *Undef = UndefValue::get(I32);
73 auto *Switch = SwitchInst::Create(Undef, ExitBB, NumCases, EntryBB);
74 for (unsigned I = 0; I < NumCases; ++I)
75 Switch->addCase(ConstantInt::get(I32, I), PreExitBB);
76
77 BranchProbabilityInfo &BPI = buildBPI(*F);
78
79 // FIXME: This doesn't seem optimal. Since all of the cases handled by the
80 // switch have the *same* destination block ("preexit"), shouldn't it be the
81 // hot one? I'd expect the results to be reversed here...
82 EXPECT_FALSE(BPI.isEdgeHot(EntryBB, PreExitBB));
83 EXPECT_TRUE(BPI.isEdgeHot(EntryBB, ExitBB));
84 }
85
86 } // end anonymous namespace
87 } // end namespace llvm
77 add_llvm_unittest(AnalysisTests
88 AliasAnalysisTest.cpp
99 BlockFrequencyInfoTest.cpp
10 BranchProbabilityInfoTest.cpp
1110 CallGraphTest.cpp
1211 CFGTest.cpp
1312 CGSCCPassManagerTest.cpp