[llvm] Support BranchProbabilityInfo in update_analyze_test_checks.py (PR #72943)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 20 18:50:23 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-testing-tools

Author: Matthias Braun (MatzeB)

<details>
<summary>Changes</summary>

- Change `BranchProbabilityPrinterPass` output to match expectations of `update_analyze_test_checks.py`.
- Add `Branch Probability Analysis` to list of supported analyses.
- Process `llvm/test/Analysis/BranchProbabilityInfo/basic.ll` with `update_analyze_test_checks.py` as proof of concept. Leaving the other tests unchanged to reduce the amount of churn.

---

Patch is 37.21 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/72943.diff


4 Files Affected:

- (modified) llvm/lib/Analysis/BranchProbabilityInfo.cpp (+2-3) 
- (modified) llvm/test/Analysis/BranchProbabilityInfo/basic.ll (+228-166) 
- (modified) llvm/test/Analysis/BranchProbabilityInfo/pointer_heuristics.ll (+3-3) 
- (modified) llvm/utils/UpdateTestChecks/common.py (+9-6) 


``````````diff
diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index b45deccd913db47..9789a3e5364c3c6 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -1322,9 +1322,8 @@ BranchProbabilityAnalysis::run(Function &F, FunctionAnalysisManager &AM) {
 
 PreservedAnalyses
 BranchProbabilityPrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
-  OS << "Printing analysis results of BPI for function "
-     << "'" << F.getName() << "':"
-     << "\n";
+  OS << "Printing analysis 'Branch Probability Analysis' for function '"
+     << F.getName() << "':\n";
   AM.getResult<BranchProbabilityAnalysis>(F).print(OS);
   return PreservedAnalyses::all();
 }
diff --git a/llvm/test/Analysis/BranchProbabilityInfo/basic.ll b/llvm/test/Analysis/BranchProbabilityInfo/basic.ll
index 682de24ac5828af..4d280da84a0003b 100644
--- a/llvm/test/Analysis/BranchProbabilityInfo/basic.ll
+++ b/llvm/test/Analysis/BranchProbabilityInfo/basic.ll
@@ -1,10 +1,15 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
 ; RUN: opt < %s -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
 
 define i32 @test1(i32 %i, ptr %a) {
-; CHECK: Printing analysis {{.*}} for function 'test1'
+; CHECK-LABEL: 'test1'
+; CHECK-NEXT:  ---- Branch Probabilities ----
+; CHECK-NEXT:    edge entry -> body probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge body -> exit probability is 0x04000000 / 0x80000000 = 3.12%
+; CHECK-NEXT:    edge body -> body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
+;
 entry:
   br label %body
-; CHECK: edge entry -> body probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 body:
   %iv = phi i32 [ 0, %entry ], [ %next, %body ]
@@ -15,28 +20,28 @@ body:
   %next = add i32 %iv, 1
   %exitcond = icmp eq i32 %next, %i
   br i1 %exitcond, label %exit, label %body
-; CHECK: edge body -> exit probability is 0x04000000 / 0x80000000 = 3.12%
-; CHECK: edge body -> body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
 
 exit:
   ret i32 %sum
 }
 
 define i32 @test2(i32 %i, i32 %a, i32 %b) {
-; CHECK: Printing analysis {{.*}} for function 'test2'
+; CHECK-LABEL: 'test2'
+; CHECK-NEXT:  ---- Branch Probabilities ----
+; CHECK-NEXT:    edge entry -> then probability is 0x78787878 / 0x80000000 = 94.12% [HOT edge]
+; CHECK-NEXT:    edge entry -> else probability is 0x07878788 / 0x80000000 = 5.88%
+; CHECK-NEXT:    edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+;
 entry:
   %cond = icmp ult i32 %i, 42
   br i1 %cond, label %then, label %else, !prof !0
-; CHECK: edge entry -> then probability is 0x78787878 / 0x80000000 = 94.12% [HOT edge]
-; CHECK: edge entry -> else probability is 0x07878788 / 0x80000000 = 5.88%
 
 then:
   br label %exit
-; CHECK: edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 else:
   br label %exit
-; CHECK: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 exit:
   %result = phi i32 [ %a, %then ], [ %b, %else ]
@@ -46,62 +51,66 @@ exit:
 !0 = !{!"branch_weights", i32 64, i32 4}
 
 define i32 @test3(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
-; CHECK: Printing analysis {{.*}} for function 'test3'
+; CHECK-LABEL: 'test3'
+; CHECK-NEXT:  ---- Branch Probabilities ----
+; CHECK-NEXT:    edge entry -> case_a probability is 0x06666666 / 0x80000000 = 5.00%
+; CHECK-NEXT:    edge entry -> case_b probability is 0x06666666 / 0x80000000 = 5.00%
+; CHECK-NEXT:    edge entry -> case_c probability is 0x66666666 / 0x80000000 = 80.00%
+; CHECK-NEXT:    edge entry -> case_d probability is 0x06666666 / 0x80000000 = 5.00%
+; CHECK-NEXT:    edge entry -> case_e probability is 0x06666666 / 0x80000000 = 5.00%
+; CHECK-NEXT:    edge case_a -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge case_b -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge case_c -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge case_d -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge case_e -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+;
 entry:
   switch i32 %i, label %case_a [ i32 1, label %case_b
-                                 i32 2, label %case_c
-                                 i32 3, label %case_d
-                                 i32 4, label %case_e ], !prof !1
-; CHECK: edge entry -> case_a probability is 0x06666666 / 0x80000000 = 5.00%
-; CHECK: edge entry -> case_b probability is 0x06666666 / 0x80000000 = 5.00%
-; CHECK: edge entry -> case_c probability is 0x66666666 / 0x80000000 = 80.00%
-; CHECK: edge entry -> case_d probability is 0x06666666 / 0x80000000 = 5.00%
-; CHECK: edge entry -> case_e probability is 0x06666666 / 0x80000000 = 5.00%
+  i32 2, label %case_c
+  i32 3, label %case_d
+  i32 4, label %case_e ], !prof !1
 
 case_a:
   br label %exit
-; CHECK: edge case_a -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 case_b:
   br label %exit
-; CHECK: edge case_b -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 case_c:
   br label %exit
-; CHECK: edge case_c -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 case_d:
   br label %exit
-; CHECK: edge case_d -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 case_e:
   br label %exit
-; CHECK: edge case_e -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 exit:
-  %result = phi i32 [ %a, %case_a ],
-                    [ %b, %case_b ],
-                    [ %c, %case_c ],
-                    [ %d, %case_d ],
-                    [ %e, %case_e ]
+  %result = phi i32 [ %a, %case_a ], [ %b, %case_b ], [ %c, %case_c ], [ %d, %case_d ], [ %e, %case_e ]
   ret i32 %result
 }
 
 !1 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4}
 
 define i32 @test4(i32 %x) nounwind uwtable readnone ssp {
-; CHECK: Printing analysis {{.*}} for function 'test4'
+; CHECK-LABEL: 'test4'
+; CHECK-NEXT:  ---- Branch Probabilities ----
+; CHECK-NEXT:    edge entry -> return probability is 0x0a8a8a8b / 0x80000000 = 8.24%
+; CHECK-NEXT:    edge entry -> sw.bb probability is 0x15151515 / 0x80000000 = 16.47%
+; CHECK-NEXT:    edge entry -> sw.bb probability is 0x15151515 / 0x80000000 = 16.47%
+; CHECK-NEXT:    edge entry -> sw.bb probability is 0x15151515 / 0x80000000 = 16.47%
+; CHECK-NEXT:    edge entry -> sw.bb1 probability is 0x60606060 / 0x80000000 = 75.29%
+; CHECK-NEXT:    edge sw.bb -> return probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge sw.bb1 -> return probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+;
 entry:
   %conv = sext i32 %x to i64
   switch i64 %conv, label %return [
-    i64 0, label %sw.bb
-    i64 1, label %sw.bb
-    i64 2, label %sw.bb
-    i64 5, label %sw.bb1
+  i64 0, label %sw.bb
+  i64 1, label %sw.bb
+  i64 2, label %sw.bb
+  i64 5, label %sw.bb1
   ], !prof !2
-; CHECK: edge entry -> return probability is 0x0a8a8a8b / 0x80000000 = 8.24%
-; CHECK: edge entry -> sw.bb probability is 0x15151515 / 0x80000000 = 16.47%
-; CHECK: edge entry -> sw.bb1 probability is 0x60606060 / 0x80000000 = 75.29%
 
 sw.bb:
   br label %return
@@ -119,20 +128,22 @@ return:
 declare void @coldfunc() cold
 
 define i32 @test5(i32 %a, i32 %b, i1 %flag) {
-; CHECK: Printing analysis {{.*}} for function 'test5'
+; CHECK-LABEL: 'test5'
+; CHECK-NEXT:  ---- Branch Probabilities ----
+; CHECK-NEXT:    edge entry -> then probability is 0x078780e3 / 0x80000000 = 5.88%
+; CHECK-NEXT:    edge entry -> else probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
+; CHECK-NEXT:    edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+;
 entry:
   br i1 %flag, label %then, label %else
-; CHECK: edge entry -> then probability is 0x078780e3 / 0x80000000 = 5.88%
-; CHECK: edge entry -> else probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
 
 then:
   call void @coldfunc()
   br label %exit
-; CHECK: edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 else:
   br label %exit
-; CHECK: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 exit:
   %result = phi i32 [ %a, %then ], [ %b, %else ]
@@ -140,19 +151,23 @@ exit:
 }
 
 define i32 @test_cold_loop(i32 %a, i32 %b) {
+; CHECK-LABEL: 'test_cold_loop'
+; CHECK-NEXT:  ---- Branch Probabilities ----
+; CHECK-NEXT:    edge entry -> header probability is 0x40000000 / 0x80000000 = 50.00%
+; CHECK-NEXT:    edge entry -> exit probability is 0x40000000 / 0x80000000 = 50.00%
+; CHECK-NEXT:    edge header -> body probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge body -> header probability is 0x7fbe1203 / 0x80000000 = 99.80% [HOT edge]
+; CHECK-NEXT:    edge body -> exit probability is 0x0041edfd / 0x80000000 = 0.20%
+;
 entry:
   %cond1 = icmp eq i32 %a, 42
   br i1 %cond1, label %header, label %exit
-; CHECK: edge entry -> header probability is 0x40000000 / 0x80000000 = 50.00%
-; CHECK: edge entry -> exit probability is 0x40000000 / 0x80000000 = 50.00%
 header:
   br label %body
 
 body:
   %cond2 = icmp eq i32 %b, 42
   br i1 %cond2, label %header, label %exit
-; CHECK: edge body -> header probability is 0x7fbe1203 / 0x80000000 = 99.80% [HOT edge]
-; CHECK: edge body -> exit probability is 0x0041edfd / 0x80000000 = 0.20%
 exit:
   call void @coldfunc()
   ret i32 %b
@@ -161,34 +176,36 @@ exit:
 declare i32 @regular_function(i32 %i)
 
 define i32 @test_cold_call_sites_with_prof(i32 %a, i32 %b, i1 %flag, i1 %flag2) {
-; CHECK: Printing analysis {{.*}} for function 'test_cold_call_sites_with_prof'
+; CHECK-LABEL: 'test_cold_call_sites_with_prof'
+; CHECK-NEXT:  ---- Branch Probabilities ----
+; CHECK-NEXT:    edge entry -> then probability is 0x078780e3 / 0x80000000 = 5.88%
+; CHECK-NEXT:    edge entry -> else probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
+; CHECK-NEXT:    edge then -> then2 probability is 0x7ebb907a / 0x80000000 = 99.01% [HOT edge]
+; CHECK-NEXT:    edge then -> else2 probability is 0x01446f86 / 0x80000000 = 0.99%
+; CHECK-NEXT:    edge then2 -> join probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge else2 -> join probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge join -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+;
 entry:
   br i1 %flag, label %then, label %else
-; CHECK: edge entry -> then probability is 0x078780e3 / 0x80000000 = 5.88%
-; CHECK: edge entry -> else probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
 
 then:
   br i1 %flag2, label %then2, label %else2, !prof !3
-; CHECK: edge then -> then2 probability is 0x7ebb907a / 0x80000000 = 99.01% [HOT edge]
-; CHECK: edge then -> else2 probability is 0x01446f86 / 0x80000000 = 0.99%
 
 then2:
   br label %join
-; CHECK: edge then2 -> join probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 else2:
   br label %join
-; CHECK: edge else2 -> join probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 join:
   %joinresult = phi i32 [ %a, %then2 ], [ %b, %else2 ]
   call void @coldfunc()
   br label %exit
-; CHECK: edge join -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 else:
   br label %exit
-; CHECK: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 exit:
   %result = phi i32 [ %joinresult, %join ], [ %b, %else ]
@@ -203,10 +220,13 @@ define i32 @test_cold_call_sites(ptr %a) {
 ; TODO(dnovillo) The calls to regular_function should not be merged, but
 ; they are currently being merged. Convert this into a code generation test
 ; after that is fixed.
-
-; CHECK: Printing analysis {{.*}} for function 'test_cold_call_sites'
-; CHECK: edge entry -> then probability is 0x078780e3 / 0x80000000 = 5.88%
-; CHECK: edge entry -> else probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
+; CHECK-LABEL: 'test_cold_call_sites'
+; CHECK-NEXT:  ---- Branch Probabilities ----
+; CHECK-NEXT:    edge entry -> then probability is 0x078780e3 / 0x80000000 = 5.88%
+; CHECK-NEXT:    edge entry -> else probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
+; CHECK-NEXT:    edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+;
 
 entry:
   %gep1 = getelementptr i32, ptr %a, i32 1
@@ -230,21 +250,25 @@ exit:
   ret i32 %ret
 }
 
-; CHECK-LABEL: test_invoke_code_callsite1
 define i32 @test_invoke_code_callsite1(i1 %c) personality ptr @__gxx_personality_v0 {
+; CHECK-LABEL: 'test_invoke_code_callsite1'
+; CHECK-NEXT:  ---- Branch Probabilities ----
+; CHECK-NEXT:    edge entry -> if.then probability is 0x078780e3 / 0x80000000 = 5.88%
+; CHECK-NEXT:    edge entry -> if.end probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
+; CHECK-NEXT:    edge if.then -> invoke.cont probability is 0x7fff8000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge if.then -> lpad probability is 0x00008000 / 0x80000000 = 0.00%
+; CHECK-NEXT:    edge invoke.cont -> if.end probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge lpad -> if.end probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+;
 entry:
   br i1 %c, label %if.then, label %if.end
 ; Edge "entry->if.end" should have higher probability based on the cold call
 ; heuristic which treat %if.then as a cold block because the normal destination
 ; of the invoke instruction in %if.then is post-dominated by ColdFunc().
-; CHECK:  edge entry -> if.then probability is 0x078780e3 / 0x80000000 = 5.88%
-; CHECK:  edge entry -> if.end probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
 
 if.then:
   invoke i32 @InvokeCall()
-          to label %invoke.cont unwind label %lpad
-; CHECK:  edge if.then -> invoke.cont probability is 0x7fff8000 / 0x80000000 = 100.00% [HOT edge]
-; CHECK:  edge if.then -> lpad probability is 0x00008000 / 0x80000000 = 0.00%
+  to label %invoke.cont unwind label %lpad
 
 invoke.cont:
   call void @ColdFunc() #0
@@ -252,33 +276,37 @@ invoke.cont:
 
 lpad:
   %ll = landingpad { ptr, i32 }
-          cleanup
+  cleanup
   br label %if.end
 
 if.end:
   ret i32 0
 }
 
-; CHECK-LABEL: test_invoke_code_callsite2
 define i32 @test_invoke_code_callsite2(i1 %c) personality ptr @__gxx_personality_v0 {
+; CHECK-LABEL: 'test_invoke_code_callsite2'
+; CHECK-NEXT:  ---- Branch Probabilities ----
+; CHECK-NEXT:    edge entry -> if.then probability is 0x40000000 / 0x80000000 = 50.00%
+; CHECK-NEXT:    edge entry -> if.end probability is 0x40000000 / 0x80000000 = 50.00%
+; CHECK-NEXT:    edge if.then -> invoke.cont probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge if.then -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
+; CHECK-NEXT:    edge invoke.cont -> if.end probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge lpad -> if.end probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+;
 entry:
   br i1 %c, label %if.then, label %if.end
 
-; CHECK:  edge entry -> if.then probability is 0x40000000 / 0x80000000 = 50.00%
-; CHECK:  edge entry -> if.end probability is 0x40000000 / 0x80000000 = 50.00%
 if.then:
   invoke i32 @InvokeCall()
-          to label %invoke.cont unwind label %lpad
+  to label %invoke.cont unwind label %lpad
 ; The cold call heuristic should not kick in when the cold callsite is in EH path.
-; CHECK: edge if.then -> invoke.cont probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
-; CHECK: edge if.then -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
 
 invoke.cont:
   br label %if.end
 
 lpad:
   %ll = landingpad { ptr, i32 }
-          cleanup
+  cleanup
   call void @ColdFunc() #0
   br label %if.end
 
@@ -286,20 +314,24 @@ if.end:
   ret i32 0
 }
 
-; CHECK-LABEL: test_invoke_code_callsite3
 define i32 @test_invoke_code_callsite3(i1 %c) personality ptr @__gxx_personality_v0 {
+; CHECK-LABEL: 'test_invoke_code_callsite3'
+; CHECK-NEXT:  ---- Branch Probabilities ----
+; CHECK-NEXT:    edge entry -> if.then probability is 0x078780e3 / 0x80000000 = 5.88%
+; CHECK-NEXT:    edge entry -> if.end probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
+; CHECK-NEXT:    edge if.then -> invoke.cont probability is 0x7fff8000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge if.then -> lpad probability is 0x00008000 / 0x80000000 = 0.00%
+; CHECK-NEXT:    edge invoke.cont -> if.end probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge lpad -> if.end probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+;
 entry:
   br i1 %c, label %if.then, label %if.end
-; CHECK: edge entry -> if.then probability is 0x078780e3 / 0x80000000 = 5.88%
-; CHECK: edge entry -> if.end probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
 
 if.then:
   invoke i32 @InvokeCall()
-          to label %invoke.cont unwind label %lpad
+  to label %invoke.cont unwind label %lpad
 ; Regardless of cold calls, edge weights from a invoke instruction should be
 ; determined by the invoke heuristic.
-; CHECK: edge if.then -> invoke.cont probability is 0x7fff8000 / 0x80000000 = 100.00% [HOT edge]
-; CHECK: edge if.then -> lpad probability is 0x00008000 / 0x80000000 = 0.00%
 
 invoke.cont:
   call void @ColdFunc() #0
@@ -307,7 +339,7 @@ invoke.cont:
 
 lpad:
   %ll = landingpad { ptr, i32 }
-          cleanup
+  cleanup
   call void @ColdFunc() #0
   br label %if.end
 
@@ -315,24 +347,26 @@ if.end:
   ret i32 0
 }
 
-; CHECK-LABEL: test_invoke_code_profiled
 define void @test_invoke_code_profiled(i1 %c) personality ptr @__gxx_personality_v0 {
+; CHECK-LABEL: 'test_invoke_code_profiled'
+; CHECK-NEXT:  ---- Branch Probabilities ----
+; CHECK-NEXT:    edge entry -> invoke.to0 probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge entry -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
+; CHECK-NEXT:    edge invoke.to0 -> invoke.to1 probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge invoke.to0 -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
+; CHECK-NEXT:    edge invoke.to1 -> invoke.to2 probability is 0x55555555 / 0x80000000 = 66.67%
+; CHECK-NEXT:    edge invoke.to1 -> lpad probability is 0x2aaaaaab / 0x80000000 = 33.33%
+;
 entry:
-; CHECK: edge entry -> invoke.to0 probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
-; CHECK: edge entry -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
   invoke i32 @InvokeCall() to label %invoke.to0 unwind label %lpad
 
 invoke.to0:
-; CHECK: edge invoke.to0 -> invoke.to1 probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
-; CHECK: edge invoke.to0 -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
   invoke i32 @InvokeCall() to label %invoke.to1 unwind label %lpad,
-     !prof !{!"branch_weights", i32 444}
+  !prof !{!"branch_weights", i32 444}
 
 invoke.to1:
-; CHECK: invoke.to1 -> invoke.to2 probability is 0x55555555 / 0x80000000 = 66.67%
-; CHECK: invoke.to1 -> lpad probability is 0x2aaaaaab / 0x80000000 = 33.33%
   invoke i32 @InvokeCall() to label %invoke.to2 unwind label %lpad,
-     !prof !{!"branch_weights", i32 222, i32 111}
+  !prof !{!"branch_weights", i32 222, i32 111}
   ret void
 
 invoke.to2:
@@ -340,7 +374,7 @@ invoke.to2:
 
 lpad:
   %ll = landingpad { ptr, i32 }
-          cleanup
+  cleanup
   ret void
 }
 
@@ -352,12 +386,16 @@ attributes #0 = { cold }
 
 
 define i32 @zero1(i32 %i, i32 %a, i32 %b) {
-; CHECK: Printing analysis {{.*}} for function 'zero1'
+; CHECK-LABEL: 'zero1'
+; CHECK-NEXT:  ---- Branch Probabilities ----
+; CHECK-NEXT:    edge entry -> then probability is 0x30000000 / 0x80000000 = 37.50%
+; CHECK-NEXT:    edge entry -> else probability is 0x50000000 / 0x80000000 = 62.50%
+; CHECK-NEXT:    edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK-NEXT:    edge else -> exit proba...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/72943


More information about the llvm-commits mailing list