Index: include/llvm/Support/BranchProbability.h =================================================================== --- include/llvm/Support/BranchProbability.h +++ include/llvm/Support/BranchProbability.h @@ -15,36 +15,44 @@ #define LLVM_SUPPORT_BRANCHPROBABILITY_H #include "llvm/Support/DataTypes.h" -#include namespace llvm { class raw_ostream; -// This class represents Branch Probability as a non-negative fraction. +// This class represents Branch Probability as a non-negative fraction that is +// no greater than 1. It uses a fixed-point-like implementation, in which the +// denominator is always a constant value (here we use UINT32_MAX for maximum +// precision). class BranchProbability { // Numerator uint32_t N; - // Denominator - uint32_t D; + // Denominator, which is a constant value. + static const uint32_t D = UINT32_MAX; + + // Construct a BranchProbability with only numerator assuming the denominator + // is UINT32_MAX. For internal use only. + explicit BranchProbability(uint32_t n) : N(n) {} public: - BranchProbability(uint32_t n, uint32_t d) : N(n), D(d) { - assert(d > 0 && "Denominator cannot be 0!"); - assert(n <= d && "Probability cannot be bigger than 1!"); - } + BranchProbability() : N(0) {} + BranchProbability(uint32_t n, uint32_t d); + + bool isZero() const { return N == 0; } - static BranchProbability getZero() { return BranchProbability(0, 1); } - static BranchProbability getOne() { return BranchProbability(1, 1); } + static BranchProbability getZero() { return BranchProbability(0); } + static BranchProbability getOne() { return BranchProbability(D); } + + // Normalize given probabilties so that the sum of them becomes one. + template + static void normalizeProbabilities(ProbabilityList &Probs); uint32_t getNumerator() const { return N; } - uint32_t getDenominator() const { return D; } + static uint32_t getDenominator() { return D; } // Return (1 - Probability). - BranchProbability getCompl() const { - return BranchProbability(D - N, D); - } + BranchProbability getCompl() const { return BranchProbability(D - N); } raw_ostream &print(raw_ostream &OS) const; @@ -66,24 +74,67 @@ /// \return \c Num divided by \c this. uint64_t scaleByInverse(uint64_t Num) const; - bool operator==(BranchProbability RHS) const { - return (uint64_t)N * RHS.D == (uint64_t)D * RHS.N; + BranchProbability &operator+=(BranchProbability RHS); + BranchProbability &operator-=(BranchProbability RHS); + BranchProbability &operator*=(BranchProbability RHS) { + N = static_cast(N) * RHS.N / D; + return *this; } - bool operator!=(BranchProbability RHS) const { - return !(*this == RHS); + + BranchProbability operator+(BranchProbability RHS) const { + BranchProbability Prob(*this); + return Prob += RHS; } - bool operator<(BranchProbability RHS) const { - return (uint64_t)N * RHS.D < (uint64_t)D * RHS.N; + + BranchProbability operator-(BranchProbability RHS) const { + BranchProbability Prob(*this); + return Prob -= RHS; } + + BranchProbability operator*(BranchProbability RHS) const { + BranchProbability Prob(*this); + return Prob *= RHS; + } + + bool operator==(BranchProbability RHS) const { return N == RHS.N; } + bool operator!=(BranchProbability RHS) const { return !(*this == RHS); } + bool operator<(BranchProbability RHS) const { return N < RHS.N; } bool operator>(BranchProbability RHS) const { return RHS < *this; } bool operator<=(BranchProbability RHS) const { return !(RHS < *this); } bool operator>=(BranchProbability RHS) const { return !(*this < RHS); } + + friend BranchProbability operator*(BranchProbability LHS, uint32_t RHS); + friend BranchProbability operator/(BranchProbability LHS, uint32_t RHS); }; -inline raw_ostream &operator<<(raw_ostream &OS, const BranchProbability &Prob) { +inline raw_ostream &operator<<(raw_ostream &OS, BranchProbability Prob) { return Prob.print(OS); } +inline BranchProbability operator*(BranchProbability LHS, uint32_t RHS) { + LHS.N *= RHS; + return LHS; +} + +inline BranchProbability operator/(BranchProbability LHS, uint32_t RHS) { + LHS.N /= RHS; + return LHS; +} + +inline BranchProbability operator*(uint32_t LHS, BranchProbability RHS) { + return RHS * LHS; +} + +template +void BranchProbability::normalizeProbabilities(ProbabilityList &Probs) { + uint64_t Sum = 0; + for (auto Prob : Probs) + Sum += Prob.N; + if (Sum > 0) + for (auto &Prob : Probs) + Prob.N = Prob.N * uint64_t(D) / Sum; +} + } #endif Index: lib/Support/BranchProbability.cpp =================================================================== --- lib/Support/BranchProbability.cpp +++ lib/Support/BranchProbability.cpp @@ -15,16 +15,42 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" +#include using namespace llvm; raw_ostream &BranchProbability::print(raw_ostream &OS) const { - return OS << N << " / " << D << " = " - << format("%g%%", ((double)N / D) * 100.0); + return OS << format("%d%%", + static_cast(std::round(((double)N / D) * 100.0))); } void BranchProbability::dump() const { print(dbgs()) << '\n'; } +BranchProbability::BranchProbability(uint32_t n, uint32_t d) { + assert(d > 0 && "Denominator cannot be 0!"); + assert(n <= d && "Probability cannot be bigger than 1!"); + if (d == D) + N = n; + else { + uint64_t Prob64 = n * static_cast(D) / d; + N = static_cast(Prob64); + } +} + +BranchProbability &BranchProbability::operator+=(BranchProbability RHS) { + assert(N <= D - RHS.N && + "The sum of branch probabilities should not exceed one!"); + N += RHS.N; + return *this; +} + +BranchProbability &BranchProbability::operator-=(BranchProbability RHS) { + assert(N >= RHS.N && + "Can only subtract a smaller probability from a larger one!"); + N -= RHS.N; + return *this; +} + static uint64_t scale(uint64_t Num, uint32_t N, uint32_t D) { assert(D && "divide by 0"); Index: test/Analysis/BlockFrequencyInfo/bad_input.ll =================================================================== --- test/Analysis/BlockFrequencyInfo/bad_input.ll +++ test/Analysis/BlockFrequencyInfo/bad_input.ll @@ -10,7 +10,7 @@ br label %for.body ; Check that we get 1,4 instead of 0,3. -; CHECK-NEXT: for.body: float = 4.0, +; CHECK-NEXT: for.body: float = 3.99 for.body: %i = phi i32 [ 0, %entry ], [ %inc, %for.body ] call void @g(i32 %i) @@ -43,7 +43,7 @@ ; Check that the exit weight is half of entry, since half is lost in the ; infinite loop above. -; CHECK-NEXT: for.end: float = 0.5, +; CHECK-NEXT: for.end: float = 0.49 for.end: ret void } Index: test/Analysis/BlockFrequencyInfo/basic.ll =================================================================== --- test/Analysis/BlockFrequencyInfo/basic.ll +++ test/Analysis/BlockFrequencyInfo/basic.ll @@ -8,7 +8,7 @@ br label %body ; Loop backedges are weighted and thus their bodies have a greater frequency. -; CHECK-NEXT: body: float = 32.0, +; CHECK-NEXT: body: float = 31.99 body: %iv = phi i32 [ 0, %entry ], [ %next, %body ] %base = phi i32 [ 0, %entry ], [ %sum, %body ] @@ -59,24 +59,24 @@ i32 3, label %case_d i32 4, label %case_e ], !prof !1 -; CHECK-NEXT: case_a: float = 0.05, +; CHECK-NEXT: case_a: float = 0.05 case_a: br label %exit -; CHECK-NEXT: case_b: float = 0.05, +; CHECK-NEXT: case_b: float = 0.05 case_b: br label %exit ; The 'case_c' branch is predicted more likely via branch weight metadata. -; CHECK-NEXT: case_c: float = 0.8, +; CHECK-NEXT: case_c: float = 0.8 case_c: br label %exit -; CHECK-NEXT: case_d: float = 0.05, +; CHECK-NEXT: case_d: float = 0.049 case_d: br label %exit -; CHECK-NEXT: case_e: float = 0.05, +; CHECK-NEXT: case_e: float = 0.049 case_e: br label %exit @@ -99,18 +99,18 @@ entry: br label %for.cond1.preheader -; CHECK-NEXT: for.cond1.preheader: float = 4001.0, +; CHECK-NEXT: for.cond1.preheader: float = 4000.99 for.cond1.preheader: %x.024 = phi i32 [ 0, %entry ], [ %inc12, %for.inc11 ] br label %for.cond4.preheader -; CHECK-NEXT: for.cond4.preheader: float = 16008001.0, +; CHECK-NEXT: for.cond4.preheader: float = 160079{{[0-9]+}} for.cond4.preheader: %y.023 = phi i32 [ 0, %for.cond1.preheader ], [ %inc9, %for.inc8 ] %add = add i32 %y.023, %x.024 br label %for.body6 -; CHECK-NEXT: for.body6: float = 64048012001.0, +; CHECK-NEXT: for.body6: float = 640479{{[0-9]+}} for.body6: %z.022 = phi i32 [ 0, %for.cond4.preheader ], [ %inc, %for.body6 ] %add7 = add i32 %add, %z.022 @@ -119,13 +119,13 @@ %cmp5 = icmp ugt i32 %inc, %a br i1 %cmp5, label %for.inc8, label %for.body6, !prof !2 -; CHECK-NEXT: for.inc8: float = 16008001.0, +; CHECK-NEXT: for.inc8: float = 160079{{[0-9]+}} for.inc8: %inc9 = add i32 %y.023, 1 %cmp2 = icmp ugt i32 %inc9, %a br i1 %cmp2, label %for.inc11, label %for.cond4.preheader, !prof !2 -; CHECK-NEXT: for.inc11: float = 4001.0, +; CHECK-NEXT: for.inc11: float = 4000.99 for.inc11: %inc12 = add i32 %x.024, 1 %cmp = icmp ugt i32 %inc12, %a Index: test/Analysis/BlockFrequencyInfo/double_backedge.ll =================================================================== --- test/Analysis/BlockFrequencyInfo/double_backedge.ll +++ test/Analysis/BlockFrequencyInfo/double_backedge.ll @@ -8,15 +8,15 @@ br label %loop loop: -; CHECK-NEXT: loop: float = 10.0, +; CHECK-NEXT: loop: float = 9.99 br i1 %x, label %exit, label %loop.1, !prof !0 loop.1: -; CHECK-NEXT: loop.1: float = 9.0, +; CHECK-NEXT: loop.1: float = 8.99 br i1 %x, label %loop, label %loop.2, !prof !1 loop.2: -; CHECK-NEXT: loop.2: float = 5.0, +; CHECK-NEXT: loop.2: float = 4.99 br label %loop exit: Index: test/Analysis/BlockFrequencyInfo/double_exit.ll =================================================================== --- test/Analysis/BlockFrequencyInfo/double_exit.ll +++ test/Analysis/BlockFrequencyInfo/double_exit.ll @@ -28,7 +28,7 @@ ; Pseudo-edges = outer.inc @ 1/5, exit @ 1/5 ; Pseudo-mass = 2/3 ; Frequency = 3/2*1*5/2*2/3 = 5/2 -; CHECK-NEXT: inner: float = 2.5, +; CHECK-NEXT: inner: float = 2.49 inner: %Return.1 = phi i32 [ %Return.0, %outer ], [ %call4, %inner.inc ] %J.0 = phi i32 [ %I.0, %outer ], [ %inc, %inner.inc ] @@ -53,7 +53,7 @@ ; Mass = 1/3 ; Frequency = 3/2*1/3 = 1/2 -; CHECK-NEXT: outer.inc: float = 0.5, +; CHECK-NEXT: outer.inc: float = 0.49 outer.inc: %inc6 = add nsw i32 %I.0, 1 br label %outer @@ -101,7 +101,7 @@ ; Pseudo-edges = outer.inc ; Pseudo-mass = 1/2 ; Frequency = 2*1*3/2*1/2 = 3/2 -; CHECK-NEXT: middle: float = 1.5, +; CHECK-NEXT: middle: float = 1.5 middle: %J.0 = phi i32 [ %I.0, %outer ], [ %inc9, %middle.inc ] %Return.1 = phi i32 [ %Return.0, %outer ], [ %Return.2, %middle.inc ] @@ -114,7 +114,7 @@ ; Pseudo-edges = middle.inc @ 1/5, outer.inc @ 1/5 ; Pseudo-mass = 2/3 ; Frequency = 3/2*1*5/2*2/3 = 5/2 -; CHECK-NEXT: inner: float = 2.5, +; CHECK-NEXT: inner: float = 2.5 inner: %Return.2 = phi i32 [ %Return.1, %middle ], [ %call7, %inner.inc ] %K.0 = phi i32 [ %J.0, %middle ], [ %inc, %inner.inc ] @@ -139,7 +139,7 @@ ; Mass = 1/3 ; Frequency = 3/2*1/3 = 1/2 -; CHECK-NEXT: middle.inc: float = 0.5, +; CHECK-NEXT: middle.inc: float = 0.5 middle.inc: %inc9 = add nsw i32 %J.0, 1 br label %middle Index: test/Analysis/BlockFrequencyInfo/irreducible.ll =================================================================== --- test/Analysis/BlockFrequencyInfo/irreducible.ll +++ test/Analysis/BlockFrequencyInfo/irreducible.ll @@ -10,19 +10,19 @@ entry: br label %loop.1 -; CHECK-NEXT: loop.1: float = 2.0, +; CHECK-NEXT: loop.1: float = 1.99 loop.1: br i1 %x, label %exit.1, label %loop.2, !prof !0 -; CHECK-NEXT: loop.2: float = 1.75, +; CHECK-NEXT: loop.2: float = 1.749 loop.2: br i1 %x, label %exit.2, label %loop.1, !prof !1 -; CHECK-NEXT: exit.1: float = 0.25, +; CHECK-NEXT: exit.1: float = 0.25 exit.1: br label %return -; CHECK-NEXT: exit.2: float = 0.75, +; CHECK-NEXT: exit.2: float = 0.749 exit.2: br label %return @@ -98,7 +98,7 @@ br i1 %x, label %c1, label %c2, !prof !2 c1: -; CHECK-NEXT: c1: float = 2.0, +; CHECK-NEXT: c1: float = 1.99 ; The "correct" answer is: float = 2.142857{{[0-9]*}}, br i1 %x, label %c2, label %exit, !prof !2 @@ -139,12 +139,12 @@ i2 2, label %c2 ], !prof !3 c1: -; CHECK-NEXT: c1: float = 1.0, +; CHECK-NEXT: c1: float = 0.99 switch i2 %x, label %exit [ i2 1, label %c1 i2 2, label %c2 ], !prof !3 c2: -; CHECK-NEXT: c2: float = 1.0, +; CHECK-NEXT: c2: float = 0.99 switch i2 %x, label %exit [ i2 1, label %c1 i2 2, label %c2 ], !prof !3 @@ -164,19 +164,19 @@ br label %loop loop: -; CHECK-NEXT: loop: float = 4.0, int = [[HEAD:[0-9]+]] +; CHECK-NEXT: loop: float = 3.{{9+}}, int = [[HEAD:[0-9]+]] br i1 %x, label %left, label %right, !prof !4 left: -; CHECK-NEXT: left: float = 8.0, +; CHECK-NEXT: left: float = 7.{{9}} br i1 %x, label %right, label %loop.end, !prof !5 right: -; CHECK-NEXT: right: float = 8.0, +; CHECK-NEXT: right: float = 7.{{9+}} br i1 %x, label %left, label %loop.end, !prof !5 loop.end: -; CHECK-NEXT: loop.end: float = 4.0, int = [[HEAD]] +; CHECK-NEXT: loop.end: float = 3.9{{[0-9]+}}, int = [[HEAD]] br i1 %x, label %loop, label %exit, !prof !5 exit: @@ -195,7 +195,7 @@ br i1 %x, label %a, label %b, !prof !6 a: -; CHECK-NEXT: a: float = 0.75, +; CHECK-NEXT: a: float = 0.75 br i1 %x, label %a.left, label %a.right, !prof !7 a.left: @@ -207,15 +207,15 @@ br i1 %x, label %a.left, label %exit, !prof !6 b: -; CHECK-NEXT: b: float = 0.25, +; CHECK-NEXT: b: float = 0.249 br i1 %x, label %b.left, label %b.right, !prof !7 b.left: -; CHECK-NEXT: b.left: float = 0.625, +; CHECK-NEXT: b.left: float = 0.6249 br i1 %x, label %b.right, label %exit, !prof !8 b.right: -; CHECK-NEXT: b.right: float = 0.625, +; CHECK-NEXT: b.right: float = 0.6249 br i1 %x, label %b.left, label %exit, !prof !8 exit: @@ -235,7 +235,7 @@ br i1 %x, label %left, label %right, !prof !9 left: -; CHECK-NEXT: left: float = 2.0, +; CHECK-NEXT: left: float = 1.99 br i1 %x, label %right, label %exit, !prof !10 right: @@ -275,19 +275,19 @@ br label %loop.end irreducible.entry: -; CHECK-NEXT: irreducible.entry: float = 0.5, int = [[IRREDUCIBLE:[0-9]+]] +; CHECK-NEXT: irreducible.entry: float = 0.{{49[0-9]+|5}}, int = [[IRREDUCIBLE:[0-9]+]] br i1 %x, label %left, label %right, !prof !13 left: -; CHECK-NEXT: left: float = 1.0, +; CHECK-NEXT: left: float = 0.99 br i1 %x, label %right, label %irreducible.exit, !prof !12 right: -; CHECK-NEXT: right: float = 1.0, +; CHECK-NEXT: right: float = 0.99 br i1 %x, label %left, label %irreducible.exit, !prof !12 irreducible.exit: -; CHECK-NEXT: irreducible.exit: float = 0.5, int = [[IRREDUCIBLE]] +; CHECK-NEXT: irreducible.exit: float = 0.{{49[0-9]+|5}}, int = [[IRREDUCIBLE]] br label %loop.end loop.end: @@ -322,7 +322,7 @@ br i1 %x, label %left, label %right, !prof !15 left: -; CHECK-NEXT: left: float = 2.0, +; CHECK-NEXT: left: float = 1.99 br i1 %x, label %right, label %loop.end, !prof !16 right: @@ -359,7 +359,7 @@ br i1 %x, label %left, label %right, !prof !18 left: -; CHECK-NEXT: left: float = 1.0, +; CHECK-NEXT: left: float = 0.99 br i1 %x, label %bottom, label %exit, !prof !19 right: @@ -367,7 +367,7 @@ br i1 %x, label %bottom, label %exit, !prof !20 bottom: -; CHECK-NEXT: bottom: float = 1.0, +; CHECK-NEXT: bottom: float = 0.99 br i1 %x, label %left, label %right, !prof !18 exit: @@ -406,7 +406,7 @@ i2 2, label %bottom ], !prof !23 bottom: -; CHECK-NEXT: bottom: float = 4.5, +; CHECK-NEXT: bottom: float = 4.5 br label %top exit: Index: test/Analysis/BlockFrequencyInfo/loop_with_branch.ll =================================================================== --- test/Analysis/BlockFrequencyInfo/loop_with_branch.ll +++ test/Analysis/BlockFrequencyInfo/loop_with_branch.ll @@ -8,11 +8,11 @@ %skip_loop = call i1 @foo0(i32 %a) br i1 %skip_loop, label %skip, label %header, !prof !0 -; CHECK-NEXT: skip: float = 0.25, +; CHECK-NEXT: skip: float = 0.25 skip: br label %exit -; CHECK-NEXT: header: float = 4.5, +; CHECK-NEXT: header: float = 4.49 header: %i = phi i32 [ 0, %entry ], [ %i.next, %back ] %i.next = add i32 %i, 1 @@ -24,11 +24,11 @@ left: br label %back -; CHECK-NEXT: right: float = 2.25, +; CHECK-NEXT: right: float = 2.249 right: br label %back -; CHECK-NEXT: back: float = 3.75, +; CHECK-NEXT: back: float = 3.749 back: br label %header Index: test/Analysis/BlockFrequencyInfo/loops_with_profile_info.ll =================================================================== --- test/Analysis/BlockFrequencyInfo/loops_with_profile_info.ll +++ test/Analysis/BlockFrequencyInfo/loops_with_profile_info.ll @@ -93,7 +93,7 @@ %cmp5 = icmp slt i32 %2, 100 br i1 %cmp5, label %for.body6, label %for.end, !prof !3 -; CHECK: - for.body6: float = 500000.5, int = 4000003 +; CHECK: - for.body6: float = 500000.5{{[0-9]*}}, int = 400000{{[0-9]}} for.body6: ; preds = %for.cond4 call void @bar() br label %for.inc @@ -143,7 +143,7 @@ %cmp17 = icmp slt i32 %8, 10000 br i1 %cmp17, label %for.body18, label %for.end21, !prof !4 -; CHECK: - for.body18: float = 500000.5, int = 4000003 +; CHECK: - for.body18: float = 50000{{0|1}}.{{[0-9]+}}, int = 400000{{[0-9]}} for.body18: ; preds = %for.cond16 call void @bar() br label %for.inc19 @@ -175,7 +175,7 @@ %cmp27 = icmp slt i32 %12, 1000000 br i1 %cmp27, label %for.body28, label %for.end31, !prof !5 -; CHECK: - for.body28: float = 500000.5, int = 4000003 +; CHECK: - for.body28: float = 5000{{[0-9.]{7},}} int = 4000{{[0-9]{3}$}} for.body28: ; preds = %for.cond26 call void @bar() br label %for.inc29 Index: test/Analysis/BlockFrequencyInfo/nested_loop_with_branches.ll =================================================================== --- test/Analysis/BlockFrequencyInfo/nested_loop_with_branches.ll +++ test/Analysis/BlockFrequencyInfo/nested_loop_with_branches.ll @@ -8,7 +8,7 @@ %v0 = call i1 @foo0(i32 %a) br i1 %v0, label %exit, label %outer, !prof !0 -; CHECK-NEXT: outer: float = 12.0, +; CHECK-NEXT: outer: float = 11.99 outer: %i = phi i32 [ 0, %entry ], [ %i.next, %inner.end ], [ %i.next, %no_inner ] %i.next = add i32 %i, 1 @@ -21,7 +21,7 @@ %side = call i1 @foo3(i32 %j) br i1 %side, label %left, label %right, !prof !0 -; CHECK-NEXT: left: float = 9.0, +; CHECK-NEXT: left: float = 9.0 left: %v4 = call i1 @foo4(i32 %j) br label %inner.end @@ -37,7 +37,7 @@ %j.next = add i32 %j, 1 br i1 %stay_inner, label %inner, label %outer, !prof !1 -; CHECK-NEXT: no_inner: float = 3.0, +; CHECK-NEXT: no_inner: float = 2.99 no_inner: %continue = call i1 @foo6(i32 %i) br i1 %continue, label %outer, label %exit, !prof !1 Index: test/Analysis/BranchProbabilityInfo/basic.ll =================================================================== --- test/Analysis/BranchProbabilityInfo/basic.ll +++ test/Analysis/BranchProbabilityInfo/basic.ll @@ -4,7 +4,7 @@ ; CHECK: Printing analysis {{.*}} for function 'test1' entry: br label %body -; CHECK: edge entry -> body probability is 16 / 16 = 100% +; CHECK: edge entry -> body probability is 100% body: %iv = phi i32 [ 0, %entry ], [ %next, %body ] @@ -15,8 +15,8 @@ %next = add i32 %iv, 1 %exitcond = icmp eq i32 %next, %i br i1 %exitcond, label %exit, label %body -; CHECK: edge body -> exit probability is 4 / 128 -; CHECK: edge body -> body probability is 124 / 128 +; CHECK: edge body -> exit probability is 3% +; CHECK: edge body -> body probability is 97% exit: ret i32 %sum @@ -27,16 +27,16 @@ entry: %cond = icmp ult i32 %i, 42 br i1 %cond, label %then, label %else, !prof !0 -; CHECK: edge entry -> then probability is 64 / 68 -; CHECK: edge entry -> else probability is 4 / 68 +; CHECK: edge entry -> then probability is 94% +; CHECK: edge entry -> else probability is 6% then: br label %exit -; CHECK: edge then -> exit probability is 16 / 16 = 100% +; CHECK: edge then -> exit probability is 100% else: br label %exit -; CHECK: edge else -> exit probability is 16 / 16 = 100% +; CHECK: edge else -> exit probability is 100% exit: %result = phi i32 [ %a, %then ], [ %b, %else ] @@ -52,31 +52,31 @@ i32 2, label %case_c i32 3, label %case_d i32 4, label %case_e ], !prof !1 -; CHECK: edge entry -> case_a probability is 4 / 80 -; CHECK: edge entry -> case_b probability is 4 / 80 -; CHECK: edge entry -> case_c probability is 64 / 80 -; CHECK: edge entry -> case_d probability is 4 / 80 -; CHECK: edge entry -> case_e probability is 4 / 80 +; CHECK: edge entry -> case_a probability is 5% +; CHECK: edge entry -> case_b probability is 5% +; CHECK: edge entry -> case_c probability is 80% +; CHECK: edge entry -> case_d probability is 5% +; CHECK: edge entry -> case_e probability is 5% case_a: br label %exit -; CHECK: edge case_a -> exit probability is 16 / 16 = 100% +; CHECK: edge case_a -> exit probability is 100% case_b: br label %exit -; CHECK: edge case_b -> exit probability is 16 / 16 = 100% +; CHECK: edge case_b -> exit probability is 100% case_c: br label %exit -; CHECK: edge case_c -> exit probability is 16 / 16 = 100% +; CHECK: edge case_c -> exit probability is 100% case_d: br label %exit -; CHECK: edge case_d -> exit probability is 16 / 16 = 100% +; CHECK: edge case_d -> exit probability is 100% case_e: br label %exit -; CHECK: edge case_e -> exit probability is 16 / 16 = 100% +; CHECK: edge case_e -> exit probability is 100% exit: %result = phi i32 [ %a, %case_a ], @@ -99,9 +99,9 @@ i64 2, label %sw.bb i64 5, label %sw.bb1 ], !prof !2 -; CHECK: edge entry -> return probability is 7 / 85 -; CHECK: edge entry -> sw.bb probability is 14 / 85 -; CHECK: edge entry -> sw.bb1 probability is 64 / 85 +; CHECK: edge entry -> return probability is 8% +; CHECK: edge entry -> sw.bb probability is 16% +; CHECK: edge entry -> sw.bb1 probability is 75% sw.bb: br label %return @@ -122,17 +122,17 @@ ; CHECK: Printing analysis {{.*}} for function 'test5' entry: br i1 %flag, label %then, label %else -; CHECK: edge entry -> then probability is 4 / 68 -; CHECK: edge entry -> else probability is 64 / 68 +; CHECK: edge entry -> then probability is 6% +; CHECK: edge entry -> else probability is 94% then: call void @coldfunc() br label %exit -; CHECK: edge then -> exit probability is 16 / 16 = 100% +; CHECK: edge then -> exit probability is 100% else: br label %exit -; CHECK: edge else -> exit probability is 16 / 16 = 100% +; CHECK: edge else -> exit probability is 100% exit: %result = phi i32 [ %a, %then ], [ %b, %else ] @@ -149,8 +149,8 @@ ; after that is fixed. ; CHECK: Printing analysis {{.*}} for function 'test_cold_call_sites' -; CHECK: edge entry -> then probability is 4 / 68 = 5.88235% -; CHECK: edge entry -> else probability is 64 / 68 = 94.1176% [HOT edge] +; CHECK: edge entry -> then probability is 6% +; CHECK: edge entry -> else probability is 94% entry: %gep1 = getelementptr i32, i32* %a, i32 1 @@ -179,8 +179,8 @@ entry: %cond = icmp eq i32 %i, 0 br i1 %cond, label %then, label %else -; CHECK: edge entry -> then probability is 12 / 32 -; CHECK: edge entry -> else probability is 20 / 32 +; CHECK: edge entry -> then probability is 37% +; CHECK: edge entry -> else probability is 62% then: br label %exit @@ -198,8 +198,8 @@ entry: %cond = icmp ne i32 %i, -1 br i1 %cond, label %then, label %else -; CHECK: edge entry -> then probability is 20 / 32 -; CHECK: edge entry -> else probability is 12 / 32 +; CHECK: edge entry -> then probability is 62% +; CHECK: edge entry -> else probability is 37% then: br label %exit @@ -220,8 +220,8 @@ %and = and i32 %i, 2 %tobool = icmp eq i32 %and, 0 br i1 %tobool, label %then, label %else -; CHECK: edge entry -> then probability is 16 / 32 -; CHECK: edge entry -> else probability is 16 / 32 +; CHECK: edge entry -> then probability is 50% +; CHECK: edge entry -> else probability is 50% then: ; AND'ing with other bitmask might be something else, so we still assume the @@ -229,8 +229,8 @@ %and2 = and i32 %i, 5 %tobool2 = icmp eq i32 %and2, 0 br i1 %tobool2, label %else, label %exit -; CHECK: edge then -> else probability is 12 / 32 -; CHECK: edge then -> exit probability is 20 / 32 +; CHECK: edge then -> else probability is 37% +; CHECK: edge then -> exit probability is 62% else: br label %exit Index: test/Analysis/BranchProbabilityInfo/loop.ll =================================================================== --- test/Analysis/BranchProbabilityInfo/loop.ll +++ test/Analysis/BranchProbabilityInfo/loop.ll @@ -9,13 +9,13 @@ define void @test1(i32 %a, i32 %b) { entry: br label %do.body -; CHECK: edge entry -> do.body probability is 16 / 16 = 100% +; CHECK: edge entry -> do.body probability is 100% do.body: %i.0 = phi i32 [ 0, %entry ], [ %inc3, %do.end ] call void @g1() br label %do.body1 -; CHECK: edge do.body -> do.body1 probability is 16 / 16 = 100% +; CHECK: edge do.body -> do.body1 probability is 100% do.body1: %j.0 = phi i32 [ 0, %do.body ], [ %inc, %do.body1 ] @@ -23,16 +23,16 @@ %inc = add nsw i32 %j.0, 1 %cmp = icmp slt i32 %inc, %b br i1 %cmp, label %do.body1, label %do.end -; CHECK: edge do.body1 -> do.body1 probability is 124 / 128 -; CHECK: edge do.body1 -> do.end probability is 4 / 128 +; CHECK: edge do.body1 -> do.body1 probability is 97% +; CHECK: edge do.body1 -> do.end probability is 3% do.end: call void @g3() %inc3 = add nsw i32 %i.0, 1 %cmp4 = icmp slt i32 %inc3, %a br i1 %cmp4, label %do.body, label %do.end5 -; CHECK: edge do.end -> do.body probability is 124 / 128 -; CHECK: edge do.end -> do.end5 probability is 4 / 128 +; CHECK: edge do.end -> do.body probability is 97% +; CHECK: edge do.end -> do.end5 probability is 3% do.end5: call void @g4() @@ -43,20 +43,20 @@ entry: %cmp9 = icmp sgt i32 %a, 0 br i1 %cmp9, label %for.body.lr.ph, label %for.end6 -; CHECK: edge entry -> for.body.lr.ph probability is 20 / 32 -; CHECK: edge entry -> for.end6 probability is 12 / 32 +; CHECK: edge entry -> for.body.lr.ph probability is 62% +; CHECK: edge entry -> for.end6 probability is 37% for.body.lr.ph: %cmp27 = icmp sgt i32 %b, 0 br label %for.body -; CHECK: edge for.body.lr.ph -> for.body probability is 16 / 16 = 100% +; CHECK: edge for.body.lr.ph -> for.body probability is 100% for.body: %i.010 = phi i32 [ 0, %for.body.lr.ph ], [ %inc5, %for.end ] call void @g1() br i1 %cmp27, label %for.body3, label %for.end -; CHECK: edge for.body -> for.body3 probability is 20 / 32 = 62.5% -; CHECK: edge for.body -> for.end probability is 12 / 32 = 37.5% +; CHECK: edge for.body -> for.body3 probability is 62% +; CHECK: edge for.body -> for.end probability is 37% for.body3: %j.08 = phi i32 [ %inc, %for.body3 ], [ 0, %for.body ] @@ -64,16 +64,16 @@ %inc = add nsw i32 %j.08, 1 %exitcond = icmp eq i32 %inc, %b br i1 %exitcond, label %for.end, label %for.body3 -; CHECK: edge for.body3 -> for.end probability is 4 / 128 -; CHECK: edge for.body3 -> for.body3 probability is 124 / 128 +; CHECK: edge for.body3 -> for.end probability is 3% +; CHECK: edge for.body3 -> for.body3 probability is 97% for.end: call void @g3() %inc5 = add nsw i32 %i.010, 1 %exitcond11 = icmp eq i32 %inc5, %a br i1 %exitcond11, label %for.end6, label %for.body -; CHECK: edge for.end -> for.end6 probability is 4 / 128 -; CHECK: edge for.end -> for.body probability is 124 / 128 +; CHECK: edge for.end -> for.end6 probability is 3% +; CHECK: edge for.end -> for.body probability is 97% for.end6: call void @g4() @@ -83,7 +83,7 @@ define void @test3(i32 %a, i32 %b, i32* %c) { entry: br label %do.body -; CHECK: edge entry -> do.body probability is 16 / 16 = 100% +; CHECK: edge entry -> do.body probability is 100% do.body: %i.0 = phi i32 [ 0, %entry ], [ %inc4, %if.end ] @@ -91,8 +91,8 @@ %0 = load i32, i32* %c, align 4 %cmp = icmp slt i32 %0, 42 br i1 %cmp, label %do.body1, label %if.end -; CHECK: edge do.body -> do.body1 probability is 16 / 32 = 50% -; CHECK: edge do.body -> if.end probability is 16 / 32 = 50% +; CHECK: edge do.body -> do.body1 probability is 50% +; CHECK: edge do.body -> if.end probability is 50% do.body1: %j.0 = phi i32 [ %inc, %do.body1 ], [ 0, %do.body ] @@ -100,16 +100,16 @@ %inc = add nsw i32 %j.0, 1 %cmp2 = icmp slt i32 %inc, %b br i1 %cmp2, label %do.body1, label %if.end -; CHECK: edge do.body1 -> do.body1 probability is 124 / 128 -; CHECK: edge do.body1 -> if.end probability is 4 / 128 +; CHECK: edge do.body1 -> do.body1 probability is 97% +; CHECK: edge do.body1 -> if.end probability is 3% if.end: call void @g3() %inc4 = add nsw i32 %i.0, 1 %cmp5 = icmp slt i32 %inc4, %a br i1 %cmp5, label %do.body, label %do.end6 -; CHECK: edge if.end -> do.body probability is 124 / 128 -; CHECK: edge if.end -> do.end6 probability is 4 / 128 +; CHECK: edge if.end -> do.body probability is 97% +; CHECK: edge if.end -> do.end6 probability is 3% do.end6: call void @g4() @@ -119,7 +119,7 @@ define void @test4(i32 %a, i32 %b, i32* %c) { entry: br label %do.body -; CHECK: edge entry -> do.body probability is 16 / 16 = 100% +; CHECK: edge entry -> do.body probability is 100% do.body: %i.0 = phi i32 [ 0, %entry ], [ %inc4, %do.end ] @@ -127,8 +127,8 @@ %0 = load i32, i32* %c, align 4 %cmp = icmp slt i32 %0, 42 br i1 %cmp, label %return, label %do.body1 -; CHECK: edge do.body -> return probability is 4 / 128 -; CHECK: edge do.body -> do.body1 probability is 124 / 128 +; CHECK: edge do.body -> return probability is 3% +; CHECK: edge do.body -> do.body1 probability is 97% do.body1: %j.0 = phi i32 [ %inc, %do.body1 ], [ 0, %do.body ] @@ -136,21 +136,21 @@ %inc = add nsw i32 %j.0, 1 %cmp2 = icmp slt i32 %inc, %b br i1 %cmp2, label %do.body1, label %do.end -; CHECK: edge do.body1 -> do.body1 probability is 124 / 128 -; CHECK: edge do.body1 -> do.end probability is 4 / 128 +; CHECK: edge do.body1 -> do.body1 probability is 97% +; CHECK: edge do.body1 -> do.end probability is 3% do.end: call void @g3() %inc4 = add nsw i32 %i.0, 1 %cmp5 = icmp slt i32 %inc4, %a br i1 %cmp5, label %do.body, label %do.end6 -; CHECK: edge do.end -> do.body probability is 124 / 128 -; CHECK: edge do.end -> do.end6 probability is 4 / 128 +; CHECK: edge do.end -> do.body probability is 97% +; CHECK: edge do.end -> do.end6 probability is 3% do.end6: call void @g4() br label %return -; CHECK: edge do.end6 -> return probability is 16 / 16 = 100% +; CHECK: edge do.end6 -> return probability is 100% return: ret void @@ -159,42 +159,42 @@ define void @test5(i32 %a, i32 %b, i32* %c) { entry: br label %do.body -; CHECK: edge entry -> do.body probability is 16 / 16 = 100% +; CHECK: edge entry -> do.body probability is 100% do.body: %i.0 = phi i32 [ 0, %entry ], [ %inc4, %do.end ] call void @g1() br label %do.body1 -; CHECK: edge do.body -> do.body1 probability is 16 / 16 = 100% +; CHECK: edge do.body -> do.body1 probability is 100% do.body1: %j.0 = phi i32 [ 0, %do.body ], [ %inc, %if.end ] %0 = load i32, i32* %c, align 4 %cmp = icmp slt i32 %0, 42 br i1 %cmp, label %return, label %if.end -; CHECK: edge do.body1 -> return probability is 4 / 128 -; CHECK: edge do.body1 -> if.end probability is 124 / 128 +; CHECK: edge do.body1 -> return probability is 3% +; CHECK: edge do.body1 -> if.end probability is 97% if.end: call void @g2() %inc = add nsw i32 %j.0, 1 %cmp2 = icmp slt i32 %inc, %b br i1 %cmp2, label %do.body1, label %do.end -; CHECK: edge if.end -> do.body1 probability is 124 / 128 -; CHECK: edge if.end -> do.end probability is 4 / 128 +; CHECK: edge if.end -> do.body1 probability is 97% +; CHECK: edge if.end -> do.end probability is 3% do.end: call void @g3() %inc4 = add nsw i32 %i.0, 1 %cmp5 = icmp slt i32 %inc4, %a br i1 %cmp5, label %do.body, label %do.end6 -; CHECK: edge do.end -> do.body probability is 124 / 128 -; CHECK: edge do.end -> do.end6 probability is 4 / 128 +; CHECK: edge do.end -> do.body probability is 97% +; CHECK: edge do.end -> do.end6 probability is 3% do.end6: call void @g4() br label %return -; CHECK: edge do.end6 -> return probability is 16 / 16 = 100% +; CHECK: edge do.end6 -> return probability is 100% return: ret void @@ -203,13 +203,13 @@ define void @test6(i32 %a, i32 %b, i32* %c) { entry: br label %do.body -; CHECK: edge entry -> do.body probability is 16 / 16 = 100% +; CHECK: edge entry -> do.body probability is 100% do.body: %i.0 = phi i32 [ 0, %entry ], [ %inc4, %do.end ] call void @g1() br label %do.body1 -; CHECK: edge do.body -> do.body1 probability is 16 / 16 = 100% +; CHECK: edge do.body -> do.body1 probability is 100% do.body1: %j.0 = phi i32 [ 0, %do.body ], [ %inc, %do.cond ] @@ -217,28 +217,28 @@ %0 = load i32, i32* %c, align 4 %cmp = icmp slt i32 %0, 42 br i1 %cmp, label %return, label %do.cond -; CHECK: edge do.body1 -> return probability is 4 / 128 -; CHECK: edge do.body1 -> do.cond probability is 124 / 128 +; CHECK: edge do.body1 -> return probability is 3% +; CHECK: edge do.body1 -> do.cond probability is 97% do.cond: %inc = add nsw i32 %j.0, 1 %cmp2 = icmp slt i32 %inc, %b br i1 %cmp2, label %do.body1, label %do.end -; CHECK: edge do.cond -> do.body1 probability is 124 / 128 -; CHECK: edge do.cond -> do.end probability is 4 / 128 +; CHECK: edge do.cond -> do.body1 probability is 97% +; CHECK: edge do.cond -> do.end probability is 3% do.end: call void @g3() %inc4 = add nsw i32 %i.0, 1 %cmp5 = icmp slt i32 %inc4, %a br i1 %cmp5, label %do.body, label %do.end6 -; CHECK: edge do.end -> do.body probability is 124 / 128 -; CHECK: edge do.end -> do.end6 probability is 4 / 128 +; CHECK: edge do.end -> do.body probability is 97% +; CHECK: edge do.end -> do.end6 probability is 3% do.end6: call void @g4() br label %return -; CHECK: edge do.end6 -> return probability is 16 / 16 = 100% +; CHECK: edge do.end6 -> return probability is 100% return: ret void @@ -248,27 +248,27 @@ entry: %cmp10 = icmp sgt i32 %a, 0 br i1 %cmp10, label %for.body.lr.ph, label %for.end7 -; CHECK: edge entry -> for.body.lr.ph probability is 20 / 32 -; CHECK: edge entry -> for.end7 probability is 12 / 32 +; CHECK: edge entry -> for.body.lr.ph probability is 62% +; CHECK: edge entry -> for.end7 probability is 37% for.body.lr.ph: %cmp38 = icmp sgt i32 %b, 0 br label %for.body -; CHECK: edge for.body.lr.ph -> for.body probability is 16 / 16 = 100% +; CHECK: edge for.body.lr.ph -> for.body probability is 100% for.body: %i.011 = phi i32 [ 0, %for.body.lr.ph ], [ %inc6, %for.inc5 ] %0 = load i32, i32* %c, align 4 %cmp1 = icmp eq i32 %0, %i.011 br i1 %cmp1, label %for.inc5, label %if.end -; CHECK: edge for.body -> for.inc5 probability is 16 / 32 = 50% -; CHECK: edge for.body -> if.end probability is 16 / 32 = 50% +; CHECK: edge for.body -> for.inc5 probability is 50% +; CHECK: edge for.body -> if.end probability is 50% if.end: call void @g1() br i1 %cmp38, label %for.body4, label %for.end -; CHECK: edge if.end -> for.body4 probability is 20 / 32 = 62.5% -; CHECK: edge if.end -> for.end probability is 12 / 32 = 37.5% +; CHECK: edge if.end -> for.body4 probability is 62% +; CHECK: edge if.end -> for.end probability is 37% for.body4: %j.09 = phi i32 [ %inc, %for.body4 ], [ 0, %if.end ] @@ -276,20 +276,20 @@ %inc = add nsw i32 %j.09, 1 %exitcond = icmp eq i32 %inc, %b br i1 %exitcond, label %for.end, label %for.body4 -; CHECK: edge for.body4 -> for.end probability is 4 / 128 -; CHECK: edge for.body4 -> for.body4 probability is 124 / 128 +; CHECK: edge for.body4 -> for.end probability is 3% +; CHECK: edge for.body4 -> for.body4 probability is 97% for.end: call void @g3() br label %for.inc5 -; CHECK: edge for.end -> for.inc5 probability is 16 / 16 = 100% +; CHECK: edge for.end -> for.inc5 probability is 100% for.inc5: %inc6 = add nsw i32 %i.011, 1 %exitcond12 = icmp eq i32 %inc6, %a br i1 %exitcond12, label %for.end7, label %for.body -; CHECK: edge for.inc5 -> for.end7 probability is 4 / 128 -; CHECK: edge for.inc5 -> for.body probability is 124 / 128 +; CHECK: edge for.inc5 -> for.end7 probability is 3% +; CHECK: edge for.inc5 -> for.body probability is 97% for.end7: call void @g4() @@ -300,64 +300,64 @@ entry: %cmp18 = icmp sgt i32 %a, 0 br i1 %cmp18, label %for.body.lr.ph, label %for.end15 -; CHECK: edge entry -> for.body.lr.ph probability is 20 / 32 -; CHECK: edge entry -> for.end15 probability is 12 / 32 +; CHECK: edge entry -> for.body.lr.ph probability is 62% +; CHECK: edge entry -> for.end15 probability is 37% for.body.lr.ph: %cmp216 = icmp sgt i32 %b, 0 %arrayidx5 = getelementptr inbounds i32, i32* %c, i64 1 %arrayidx9 = getelementptr inbounds i32, i32* %c, i64 2 br label %for.body -; CHECK: edge for.body.lr.ph -> for.body probability is 16 / 16 = 100% +; CHECK: edge for.body.lr.ph -> for.body probability is 100% for.body: %i.019 = phi i32 [ 0, %for.body.lr.ph ], [ %inc14, %for.end ] call void @g1() br i1 %cmp216, label %for.body3, label %for.end -; CHECK: edge for.body -> for.body3 probability is 20 / 32 = 62.5% -; CHECK: edge for.body -> for.end probability is 12 / 32 = 37.5% +; CHECK: edge for.body -> for.body3 probability is 62% +; CHECK: edge for.body -> for.end probability is 37% for.body3: %j.017 = phi i32 [ 0, %for.body ], [ %inc, %for.inc ] %0 = load i32, i32* %c, align 4 %cmp4 = icmp eq i32 %0, %j.017 br i1 %cmp4, label %for.inc, label %if.end -; CHECK: edge for.body3 -> for.inc probability is 16 / 32 = 50% -; CHECK: edge for.body3 -> if.end probability is 16 / 32 = 50% +; CHECK: edge for.body3 -> for.inc probability is 50% +; CHECK: edge for.body3 -> if.end probability is 50% if.end: %1 = load i32, i32* %arrayidx5, align 4 %cmp6 = icmp eq i32 %1, %j.017 br i1 %cmp6, label %for.inc, label %if.end8 -; CHECK: edge if.end -> for.inc probability is 16 / 32 = 50% -; CHECK: edge if.end -> if.end8 probability is 16 / 32 = 50% +; CHECK: edge if.end -> for.inc probability is 50% +; CHECK: edge if.end -> if.end8 probability is 50% if.end8: %2 = load i32, i32* %arrayidx9, align 4 %cmp10 = icmp eq i32 %2, %j.017 br i1 %cmp10, label %for.inc, label %if.end12 -; CHECK: edge if.end8 -> for.inc probability is 16 / 32 = 50% -; CHECK: edge if.end8 -> if.end12 probability is 16 / 32 = 50% +; CHECK: edge if.end8 -> for.inc probability is 50% +; CHECK: edge if.end8 -> if.end12 probability is 50% if.end12: call void @g2() br label %for.inc -; CHECK: edge if.end12 -> for.inc probability is 16 / 16 = 100% +; CHECK: edge if.end12 -> for.inc probability is 100% for.inc: %inc = add nsw i32 %j.017, 1 %exitcond = icmp eq i32 %inc, %b br i1 %exitcond, label %for.end, label %for.body3 -; CHECK: edge for.inc -> for.end probability is 4 / 128 -; CHECK: edge for.inc -> for.body3 probability is 124 / 128 +; CHECK: edge for.inc -> for.end probability is 3% +; CHECK: edge for.inc -> for.body3 probability is 97% for.end: call void @g3() %inc14 = add nsw i32 %i.019, 1 %exitcond20 = icmp eq i32 %inc14, %a br i1 %exitcond20, label %for.end15, label %for.body -; CHECK: edge for.end -> for.end15 probability is 4 / 128 -; CHECK: edge for.end -> for.body probability is 124 / 128 +; CHECK: edge for.end -> for.end15 probability is 3% +; CHECK: edge for.end -> for.body probability is 97% for.end15: call void @g4() Index: test/Analysis/BranchProbabilityInfo/noreturn.ll =================================================================== --- test/Analysis/BranchProbabilityInfo/noreturn.ll +++ test/Analysis/BranchProbabilityInfo/noreturn.ll @@ -8,8 +8,8 @@ entry: %cond = icmp eq i32 %a, 42 br i1 %cond, label %exit, label %abort -; CHECK: edge entry -> exit probability is 1048575 / 1048576 -; CHECK: edge entry -> abort probability is 1 / 1048576 +; CHECK: edge entry -> exit probability is 100% +; CHECK: edge entry -> abort probability is 0% abort: call void @abort() noreturn @@ -26,11 +26,11 @@ i32 2, label %case_b i32 3, label %case_c i32 4, label %case_d] -; CHECK: edge entry -> exit probability is 1048575 / 1048579 -; CHECK: edge entry -> case_a probability is 1 / 1048579 -; CHECK: edge entry -> case_b probability is 1 / 1048579 -; CHECK: edge entry -> case_c probability is 1 / 1048579 -; CHECK: edge entry -> case_d probability is 1 / 1048579 +; CHECK: edge entry -> exit probability is 100% +; CHECK: edge entry -> case_a probability is 0% +; CHECK: edge entry -> case_b probability is 0% +; CHECK: edge entry -> case_c probability is 0% +; CHECK: edge entry -> case_d probability is 0% case_a: br label %case_b @@ -55,14 +55,14 @@ entry: %cond1 = icmp eq i32 %a, 42 br i1 %cond1, label %exit, label %dom -; CHECK: edge entry -> exit probability is 1048575 / 1048576 -; CHECK: edge entry -> dom probability is 1 / 1048576 +; CHECK: edge entry -> exit probability is 100% +; CHECK: edge entry -> dom probability is 0% dom: %cond2 = icmp ult i32 %a, 42 br i1 %cond2, label %idom1, label %idom2 -; CHECK: edge dom -> idom1 probability is 1 / 2 -; CHECK: edge dom -> idom2 probability is 1 / 2 +; CHECK: edge dom -> idom1 probability is 50% +; CHECK: edge dom -> idom2 probability is 50% idom1: br label %abort Index: test/Analysis/BranchProbabilityInfo/pr18705.ll =================================================================== --- test/Analysis/BranchProbabilityInfo/pr18705.ll +++ test/Analysis/BranchProbabilityInfo/pr18705.ll @@ -4,8 +4,8 @@ ; calcLoopBranchHeuristics should return early without setting the weights. ; calcFloatingPointHeuristics, which is run later, sets the weights. ; -; CHECK: edge while.body -> if.then probability is 20 / 32 = 62.5% -; CHECK: edge while.body -> if.else probability is 12 / 32 = 37.5% +; CHECK: edge while.body -> if.then probability is 62% +; CHECK: edge while.body -> if.else probability is 37% define void @foo1(i32 %n, i32* nocapture %b, i32* nocapture %c, i32* nocapture %d, float* nocapture readonly %f0, float* nocapture readonly %f1) { entry: Index: test/Analysis/BranchProbabilityInfo/pr22718.ll =================================================================== --- test/Analysis/BranchProbabilityInfo/pr22718.ll +++ test/Analysis/BranchProbabilityInfo/pr22718.ll @@ -4,8 +4,8 @@ ; reflected in the probability computation because the weight is larger than ; the branch weight cap (about 2 billion). ; -; CHECK: edge for.body -> if.then probability is 216661881 / 2166666667 = 9.9 -; CHECK: edge for.body -> if.else probability is 1950004786 / 2166666667 = 90.0 +; CHECK: edge for.body -> if.then probability is 10% +; CHECK: edge for.body -> if.else probability is 90% @y = common global i64 0, align 8 @x = common global i64 0, align 8 Index: test/CodeGen/AArch64/aarch64-deferred-spilling.ll =================================================================== --- test/CodeGen/AArch64/aarch64-deferred-spilling.ll +++ test/CodeGen/AArch64/aarch64-deferred-spilling.ll @@ -7,9 +7,9 @@ ; ; CHECK: // %if.then.120 ; -; REGULAR: str w22, [sp, #[[OFFSET:[0-9]+]]] // 4-byte Folded Spill -; Check that w22 wouldn't need to be spilled since it is never reused. -; REGULAR-NOT: {{[wx]}}22{{,?}} +; REGULAR: str w21, [sp, #[[OFFSET:[0-9]+]]] // 4-byte Folded Spill +; Check that w21 wouldn't need to be spilled since it is never reused. +; REGULAR-NOT: {{[wx]}}21{{,?}} ; ; Check that w22 is used to carry a value through the call. ; DEFERRED-NOT: str {{[wx]}}22, @@ -22,8 +22,8 @@ ; DEFERRED: mov {{[wx][0-9]+}}, {{[wx]}}22 ; DEFERRED-NOT: ldr {{[wx]}}22, ; -; REGULAR-NOT: {{[wx]}}22{{,?}} -; REGUAL: ldr w22, [sp, #[[OFFSET]]] // 4-byte Folded Reload +; REGULAR-NOT: {{[wx]}}21{{,?}} +; REGUAL: ldr w21, [sp, #[[OFFSET]]] // 4-byte Folded Reload ; ; End of the basic block we are interested in. ; CHECK: b Index: test/Transforms/SampleProfile/branch.ll =================================================================== --- test/Transforms/SampleProfile/branch.ll +++ test/Transforms/SampleProfile/branch.ll @@ -36,8 +36,8 @@ tail call void @llvm.dbg.value(metadata i8** %argv, i64 0, metadata !14, metadata !DIExpression()), !dbg !27 %cmp = icmp slt i32 %argc, 2, !dbg !28 br i1 %cmp, label %return, label %if.end, !dbg !28 -; CHECK: edge entry -> return probability is 0 / 1 = 0% -; CHECK: edge entry -> if.end probability is 1 / 1 = 100% +; CHECK: edge entry -> return probability is 0% +; CHECK: edge entry -> if.end probability is 100% if.end: ; preds = %entry %arrayidx = getelementptr inbounds i8*, i8** %argv, i64 1, !dbg !30 @@ -46,8 +46,8 @@ tail call void @llvm.dbg.value(metadata i32 %call, i64 0, metadata !17, metadata !DIExpression()), !dbg !30 %cmp1 = icmp sgt i32 %call, 100, !dbg !35 br i1 %cmp1, label %for.body, label %if.end6, !dbg !35 -; CHECK: edge if.end -> for.body probability is 0 / 1 = 0% -; CHECK: edge if.end -> if.end6 probability is 1 / 1 = 100% +; CHECK: edge if.end -> for.body probability is 0% +; CHECK: edge if.end -> if.end6 probability is 100% for.body: ; preds = %if.end, %for.body %u.016 = phi i32 [ %inc, %for.body ], [ 0, %if.end ] @@ -65,14 +65,14 @@ tail call void @llvm.dbg.value(metadata i32 %inc, i64 0, metadata !21, metadata !DIExpression()), !dbg !38 %exitcond = icmp eq i32 %inc, %call, !dbg !38 br i1 %exitcond, label %if.end6, label %for.body, !dbg !38 -; CHECK: edge for.body -> if.end6 probability is 0 / 10226 = 0% -; CHECK: edge for.body -> for.body probability is 10226 / 10226 = 100% [HOT edge] +; CHECK: edge for.body -> if.end6 probability is 0% +; CHECK: edge for.body -> for.body probability is 100% if.end6: ; preds = %for.body, %if.end %result.0 = phi double [ 0.000000e+00, %if.end ], [ %sub, %for.body ] %call7 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %result.0), !dbg !39 br label %return, !dbg !40 -; CHECK: edge if.end6 -> return probability is 16 / 16 = 100% [HOT edge] +; CHECK: edge if.end6 -> return probability is 100% return: ; preds = %entry, %if.end6 %retval.0 = phi i32 [ 0, %if.end6 ], [ 1, %entry ] Index: test/Transforms/SampleProfile/calls.ll =================================================================== --- test/Transforms/SampleProfile/calls.ll +++ test/Transforms/SampleProfile/calls.ll @@ -52,8 +52,8 @@ store i32 %inc, i32* %i, align 4, !dbg !14 %cmp = icmp slt i32 %0, 400000000, !dbg !14 br i1 %cmp, label %while.body, label %while.end, !dbg !14 -; CHECK: edge while.cond -> while.body probability is 5391 / 5391 = 100% [HOT edge] -; CHECK: edge while.cond -> while.end probability is 0 / 5391 = 0% +; CHECK: edge while.cond -> while.body probability is 100% +; CHECK: edge while.cond -> while.end probability is 0% while.body: ; preds = %while.cond %1 = load i32, i32* %i, align 4, !dbg !16 @@ -63,8 +63,8 @@ ; both branches out of while.body had the same weight. In reality, ; the edge while.body->if.then is taken most of the time. ; -; CHECK: edge while.body -> if.then probability is 5752 / 5752 = 100% [HOT edge] -; CHECK: edge while.body -> if.else probability is 0 / 5752 = 0% +; CHECK: edge while.body -> if.then probability is 100% +; CHECK: edge while.body -> if.else probability is 0% if.then: ; preds = %while.body Index: test/Transforms/SampleProfile/discriminator.ll =================================================================== --- test/Transforms/SampleProfile/discriminator.ll +++ test/Transforms/SampleProfile/discriminator.ll @@ -34,15 +34,15 @@ %0 = load i32, i32* %i.addr, align 4, !dbg !12 %cmp = icmp slt i32 %0, 100, !dbg !12 br i1 %cmp, label %while.body, label %while.end, !dbg !12 -; CHECK: edge while.cond -> while.body probability is 100 / 101 = 99.0099% [HOT edge] -; CHECK: edge while.cond -> while.end probability is 1 / 101 = 0.990099% +; CHECK: edge while.cond -> while.body probability is 99% +; CHECK: edge while.cond -> while.end probability is 1% while.body: ; preds = %while.cond %1 = load i32, i32* %i.addr, align 4, !dbg !14 %cmp1 = icmp slt i32 %1, 50, !dbg !14 br i1 %cmp1, label %if.then, label %if.end, !dbg !14 -; CHECK: edge while.body -> if.then probability is 5 / 100 = 5% -; CHECK: edge while.body -> if.end probability is 95 / 100 = 95% [HOT edge] +; CHECK: edge while.body -> if.then probability is 5% +; CHECK: edge while.body -> if.end probability is 95% [HOT edge] if.then: ; preds = %while.body %2 = load i32, i32* %x, align 4, !dbg !17 Index: test/Transforms/SampleProfile/fnptr.ll =================================================================== --- test/Transforms/SampleProfile/fnptr.ll +++ test/Transforms/SampleProfile/fnptr.ll @@ -5,12 +5,12 @@ ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/fnptr.prof | opt -analyze -branch-prob | FileCheck %s ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/fnptr.binprof | opt -analyze -branch-prob | FileCheck %s -; CHECK: edge for.body3 -> if.then probability is 534 / 2598 = 20.5543% -; CHECK: edge for.body3 -> if.else probability is 2064 / 2598 = 79.4457% -; CHECK: edge for.inc -> for.inc12 probability is 1052 / 2598 = 40.4927% -; CHECK: edge for.inc -> for.body3 probability is 1546 / 2598 = 59.5073% -; CHECK: edge for.inc12 -> for.end14 probability is 518 / 1052 = 49.2395% -; CHECK: edge for.inc12 -> for.cond1.preheader probability is 534 / 1052 = 50.7605% +; CHECK: edge for.body3 -> if.then probability is 21% +; CHECK: edge for.body3 -> if.else probability is 79% +; CHECK: edge for.inc -> for.inc12 probability is 40% +; CHECK: edge for.inc -> for.body3 probability is 60% +; CHECK: edge for.inc12 -> for.end14 probability is 49% +; CHECK: edge for.inc12 -> for.cond1.preheader probability is 51% ; Original C++ test case. ; Index: test/Transforms/SampleProfile/propagate.ll =================================================================== --- test/Transforms/SampleProfile/propagate.ll +++ test/Transforms/SampleProfile/propagate.ll @@ -73,8 +73,8 @@ %5 = load i64, i64* %N.addr, align 8, !dbg !15 %cmp1 = icmp slt i64 %4, %5, !dbg !15 br i1 %cmp1, label %for.body, label %for.end18, !dbg !15 -; CHECK: edge for.cond -> for.body probability is 10 / 10 = 100% [HOT edge] -; CHECK: edge for.cond -> for.end18 probability is 0 / 10 = 0% +; CHECK: edge for.cond -> for.body probability is 100% +; CHECK: edge for.cond -> for.end18 probability is 0% for.body: ; preds = %for.cond %6 = load i64, i64* %i, align 8, !dbg !18 @@ -82,8 +82,8 @@ %div = sdiv i64 %7, 3, !dbg !18 %cmp2 = icmp sgt i64 %6, %div, !dbg !18 br i1 %cmp2, label %if.then3, label %if.end, !dbg !18 -; CHECK: edge for.body -> if.then3 probability is 1 / 5 = 20% -; CHECK: edge for.body -> if.end probability is 4 / 5 = 80% +; CHECK: edge for.body -> if.then3 probability is 20% +; CHECK: edge for.body -> if.end probability is 80% if.then3: ; preds = %for.body %8 = load i32, i32* %x.addr, align 4, !dbg !21 @@ -97,8 +97,8 @@ %div4 = sdiv i64 %10, 4, !dbg !22 %cmp5 = icmp sgt i64 %9, %div4, !dbg !22 br i1 %cmp5, label %if.then6, label %if.else7, !dbg !22 -; CHECK: edge if.end -> if.then6 probability is 3 / 6342 = 0.0473037% -; CHECK: edge if.end -> if.else7 probability is 6339 / 6342 = 99.9527% [HOT edge] +; CHECK: edge if.end -> if.then6 probability is 0% +; CHECK: edge if.end -> if.else7 probability is 100% if.then6: ; preds = %if.end %11 = load i32, i32* %y.addr, align 4, !dbg !24 @@ -119,8 +119,8 @@ %14 = load i64, i64* %i, align 8, !dbg !28 %cmp10 = icmp slt i64 %conv9, %14, !dbg !28 br i1 %cmp10, label %for.body11, label %for.end, !dbg !28 -; CHECK: edge for.cond8 -> for.body11 probability is 16191 / 16191 = 100% [HOT edge] -; CHECK: edge for.cond8 -> for.end probability is 0 / 16191 = 0% +; CHECK: edge for.cond8 -> for.body11 probability is 100% [HOT edge] +; CHECK: edge for.cond8 -> for.end probability is 0% for.body11: ; preds = %for.cond8 %15 = load i32, i32* %j, align 4, !dbg !31