diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp index b45deccd913db4..9789a3e5364c3c 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(F).print(OS); return PreservedAnalyses::all(); } diff --git a/llvm/test/Analysis/BranchProbabilityInfo/basic.ll b/llvm/test/Analysis/BranchProbabilityInfo/basic.ll index 682de24ac5828a..4d280da84a0003 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' -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 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge] +; entry: %cond = icmp eq i32 %i, 0 br i1 %cond, label %then, label %else -; CHECK: edge entry -> then probability is 0x30000000 / 0x80000000 = 37.50% -; CHECK: edge entry -> else probability is 0x50000000 / 0x80000000 = 62.50% then: br label %exit @@ -371,12 +409,16 @@ exit: } define i32 @zero2(i32 %i, i32 %a, i32 %b) { -; CHECK: Printing analysis {{.*}} for function 'zero2' +; CHECK-LABEL: 'zero2' +; CHECK-NEXT: ---- Branch Probabilities ---- +; CHECK-NEXT: edge entry -> then probability is 0x50000000 / 0x80000000 = 62.50% +; CHECK-NEXT: edge entry -> else probability is 0x30000000 / 0x80000000 = 37.50% +; 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 ne i32 %i, -1 br i1 %cond, label %then, label %else -; CHECK: edge entry -> then probability is 0x50000000 / 0x80000000 = 62.50% -; CHECK: edge entry -> else probability is 0x30000000 / 0x80000000 = 37.50% then: br label %exit @@ -390,15 +432,20 @@ exit: } define i32 @zero3(i32 %i, i32 %a, i32 %b) { -; CHECK: Printing analysis {{.*}} for function 'zero3' +; CHECK-LABEL: 'zero3' +; CHECK-NEXT: ---- Branch Probabilities ---- +; CHECK-NEXT: edge entry -> then probability is 0x40000000 / 0x80000000 = 50.00% +; CHECK-NEXT: edge entry -> else probability is 0x40000000 / 0x80000000 = 50.00% +; CHECK-NEXT: edge then -> else probability is 0x30000000 / 0x80000000 = 37.50% +; CHECK-NEXT: edge then -> exit probability is 0x50000000 / 0x80000000 = 62.50% +; CHECK-NEXT: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge] +; entry: ; AND'ing with a single bit bitmask essentially leads to a bool comparison, ; meaning we don't have probability information. %and = and i32 %i, 2 %tobool = icmp eq i32 %and, 0 br i1 %tobool, label %then, label %else -; CHECK: edge entry -> then probability is 0x40000000 / 0x80000000 = 50.00% -; CHECK: edge entry -> else probability is 0x40000000 / 0x80000000 = 50.00% then: ; AND'ing with other bitmask might be something else, so we still assume the @@ -406,8 +453,6 @@ then: %and2 = and i32 %i, 5 %tobool2 = icmp eq i32 %and2, 0 br i1 %tobool2, label %else, label %exit -; CHECK: edge then -> else probability is 0x30000000 / 0x80000000 = 37.50% -; CHECK: edge then -> exit probability is 0x50000000 / 0x80000000 = 62.50% else: br label %exit @@ -418,13 +463,15 @@ exit: } define i32 @test_unreachable_with_prof_greater(i32 %a, i32 %b) { -; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_greater' +; CHECK-LABEL: 'test_unreachable_with_prof_greater' +; CHECK-NEXT: ---- Branch Probabilities ---- +; CHECK-NEXT: edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge] +; CHECK-NEXT: edge entry -> unr probability is 0x00000001 / 0x80000000 = 0.00% +; entry: %cond = icmp eq i32 %a, 42 br i1 %cond, label %exit, label %unr, !prof !4 -; CHECK: edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge] -; CHECK: edge entry -> unr probability is 0x00000001 / 0x80000000 = 0.00% unr: unreachable @@ -436,13 +483,15 @@ exit: !4 = !{!"branch_weights", i32 0, i32 1} define i32 @test_unreachable_with_prof_equal(i32 %a, i32 %b) { -; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_equal' +; CHECK-LABEL: 'test_unreachable_with_prof_equal' +; CHECK-NEXT: ---- Branch Probabilities ---- +; CHECK-NEXT: edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge] +; CHECK-NEXT: edge entry -> unr probability is 0x00000001 / 0x80000000 = 0.00% +; entry: %cond = icmp eq i32 %a, 42 br i1 %cond, label %exit, label %unr, !prof !5 -; CHECK: edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge] -; CHECK: edge entry -> unr probability is 0x00000001 / 0x80000000 = 0.00% unr: unreachable @@ -454,13 +503,15 @@ exit: !5 = !{!"branch_weights", i32 2147483647, i32 1} define i32 @test_unreachable_with_prof_zero(i32 %a, i32 %b) { -; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_zero' +; CHECK-LABEL: 'test_unreachable_with_prof_zero' +; CHECK-NEXT: ---- Branch Probabilities ---- +; CHECK-NEXT: edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge] +; CHECK-NEXT: edge entry -> unr probability is 0x00000001 / 0x80000000 = 0.00% +; entry: %cond = icmp eq i32 %a, 42 br i1 %cond, label %exit, label %unr, !prof !6 -; CHECK: edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge] -; CHECK: edge entry -> unr probability is 0x00000001 / 0x80000000 = 0.00% unr: unreachable @@ -472,13 +523,15 @@ exit: !6 = !{!"branch_weights", i32 0, i32 0} define i32 @test_unreachable_with_prof_less(i32 %a, i32 %b) { -; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_less' +; CHECK-LABEL: 'test_unreachable_with_prof_less' +; CHECK-NEXT: ---- Branch Probabilities ---- +; CHECK-NEXT: edge entry -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge] +; CHECK-NEXT: edge entry -> unr probability is 0x00000000 / 0x80000000 = 0.00% +; entry: %cond = icmp eq i32 %a, 42 br i1 %cond, label %exit, label %unr, !prof !7 -; CHECK: edge entry -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge] -; CHECK: edge entry -> unr probability is 0x00000000 / 0x80000000 = 0.00% unr: unreachable @@ -490,61 +543,69 @@ exit: !7 = !{!"branch_weights", i32 1, i32 0} define i32 @test_unreachable_with_switch_prof1(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) { -; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof1' +; CHECK-LABEL: 'test_unreachable_with_switch_prof1' +; CHECK-NEXT: ---- Branch Probabilities ---- +; CHECK-NEXT: edge entry -> case_a probability is 0x00000001 / 0x80000000 = 0.00% +; CHECK-NEXT: edge entry -> case_b probability is 0x06bca1af / 0x80000000 = 5.26% +; CHECK-NEXT: edge entry -> case_c probability is 0x6bca1af3 / 0x80000000 = 84.21% [HOT edge] +; CHECK-NEXT: edge entry -> case_d probability is 0x06bca1af / 0x80000000 = 5.26% +; CHECK-NEXT: edge entry -> case_e probability is 0x06bca1af / 0x80000000 = 5.26% +; 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 !8 + 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 !8 ; Reachable probabilities keep their relation: 4/64/4/4 = 5.26% / 84.21% / 5.26% / 5.26%. -; CHECK: edge entry -> case_a probability is 0x00000001 / 0x80000000 = 0.00% -; CHECK: edge entry -> case_b probability is 0x06bca1af / 0x80000000 = 5.26% -; CHECK: edge entry -> case_c probability is 0x6bca1af3 / 0x80000000 = 84.21% [HOT edge] -; CHECK: edge entry -> case_d probability is 0x06bca1af / 0x80000000 = 5.26% -; CHECK: edge entry -> case_e probability is 0x06bca1af / 0x80000000 = 5.26% case_a: unreachable 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 [ %b, %case_b ], - [ %c, %case_c ], - [ %d, %case_d ], - [ %e, %case_e ] + [ %c, %case_c ], + [ %d, %case_d ], + [ %e, %case_e ] ret i32 %result } !8 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4} define i32 @test_unreachable_with_switch_prof2(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) { -; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof2' +; CHECK-LABEL: 'test_unreachable_with_switch_prof2' +; CHECK-NEXT: ---- Branch Probabilities ---- +; CHECK-NEXT: edge entry -> case_a probability is 0x00000001 / 0x80000000 = 0.00% +; CHECK-NEXT: edge entry -> case_b probability is 0x00000001 / 0x80000000 = 0.00% +; CHECK-NEXT: edge entry -> case_c probability is 0x71c71c71 / 0x80000000 = 88.89% [HOT edge] +; CHECK-NEXT: edge entry -> case_d probability is 0x071c71c7 / 0x80000000 = 5.56% +; CHECK-NEXT: edge entry -> case_e probability is 0x071c71c7 / 0x80000000 = 5.56% +; 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 !9 + i32 2, label %case_c + i32 3, label %case_d + i32 4, label %case_e ], !prof !9 ; Reachable probabilities keep their relation: 64/4/4 = 88.89% / 5.56% / 5.56%. -; CHECK: edge entry -> case_a probability is 0x00000001 / 0x80000000 = 0.00% -; CHECK: edge entry -> case_b probability is 0x00000001 / 0x80000000 = 0.00% -; CHECK: edge entry -> case_c probability is 0x71c71c71 / 0x80000000 = 88.89% [HOT edge] -; CHECK: edge entry -> case_d probability is 0x071c71c7 / 0x80000000 = 5.56% -; CHECK: edge entry -> case_e probability is 0x071c71c7 / 0x80000000 = 5.56% case_a: @@ -555,38 +616,40 @@ case_b: 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 [ %c, %case_c ], - [ %d, %case_d ], - [ %e, %case_e ] + [ %d, %case_d ], + [ %e, %case_e ] ret i32 %result } !9 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4} define i32 @test_unreachable_with_switch_prof3(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) { -; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof3' +; CHECK-LABEL: 'test_unreachable_with_switch_prof3' +; CHECK-NEXT: ---- Branch Probabilities ---- +; CHECK-NEXT: edge entry -> case_a probability is 0x00000000 / 0x80000000 = 0.00% +; CHECK-NEXT: edge entry -> case_b probability is 0x00000001 / 0x80000000 = 0.00% +; CHECK-NEXT: edge entry -> case_c probability is 0x71c71c71 / 0x80000000 = 88.89% [HOT edge] +; CHECK-NEXT: edge entry -> case_d probability is 0x071c71c7 / 0x80000000 = 5.56% +; CHECK-NEXT: edge entry -> case_e probability is 0x071c71c7 / 0x80000000 = 5.56% +; 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 !10 + i32 2, label %case_c + i32 3, label %case_d + i32 4, label %case_e ], !prof !10 ; Reachable probabilities keep their relation: 64/4/4 = 88.89% / 5.56% / 5.56%. -; CHECK: edge entry -> case_a probability is 0x00000000 / 0x80000000 = 0.00% -; CHECK: edge entry -> case_b probability is 0x00000001 / 0x80000000 = 0.00% -; CHECK: edge entry -> case_c probability is 0x71c71c71 / 0x80000000 = 88.89% [HOT edge] -; CHECK: edge entry -> case_d probability is 0x071c71c7 / 0x80000000 = 5.56% -; CHECK: edge entry -> case_e probability is 0x071c71c7 / 0x80000000 = 5.56% case_a: unreachable @@ -596,37 +659,36 @@ case_b: 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 [ %c, %case_c ], - [ %d, %case_d ], - [ %e, %case_e ] + [ %d, %case_d ], + [ %e, %case_e ] ret i32 %result } !10 = !{!"branch_weights", i32 0, i32 4, i32 64, i32 4, i32 4} define i32 @test_unreachable_with_switch_prof4(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) { -; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof4' +; CHECK-LABEL: 'test_unreachable_with_switch_prof4' +; CHECK-NEXT: ---- Branch Probabilities ---- +; CHECK-NEXT: edge entry -> case_a probability is 0x1999999a / 0x80000000 = 20.00% +; CHECK-NEXT: edge entry -> case_b probability is 0x1999999a / 0x80000000 = 20.00% +; CHECK-NEXT: edge entry -> case_c probability is 0x1999999a / 0x80000000 = 20.00% +; CHECK-NEXT: edge entry -> case_d probability is 0x1999999a / 0x80000000 = 20.00% +; CHECK-NEXT: edge entry -> case_e probability is 0x1999999a / 0x80000000 = 20.00% +; 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 !11 -; CHECK: edge entry -> case_a probability is 0x1999999a / 0x80000000 = 20.00% -; CHECK: edge entry -> case_b probability is 0x1999999a / 0x80000000 = 20.00% -; CHECK: edge entry -> case_c probability is 0x1999999a / 0x80000000 = 20.00% -; CHECK: edge entry -> case_d probability is 0x1999999a / 0x80000000 = 20.00% -; CHECK: edge entry -> case_e probability is 0x1999999a / 0x80000000 = 20.00% + i32 2, label %case_c + i32 3, label %case_d + i32 4, label %case_e ], !prof !11 case_a: unreachable diff --git a/llvm/test/Analysis/BranchProbabilityInfo/pointer_heuristics.ll b/llvm/test/Analysis/BranchProbabilityInfo/pointer_heuristics.ll index 278a656aaa254a..3c6798d31f9ba7 100644 --- a/llvm/test/Analysis/BranchProbabilityInfo/pointer_heuristics.ll +++ b/llvm/test/Analysis/BranchProbabilityInfo/pointer_heuristics.ll @@ -1,7 +1,7 @@ ; RUN: opt < %s -passes='print' -disable-output 2>&1 | FileCheck %s define i32 @cmp1(ptr readnone %0, ptr readnone %1) { -; CHECK: Printing analysis results of BPI for function 'cmp1': +; CHECK-LABEL: 'cmp1' %3 = icmp eq ptr %0, %1 br i1 %3, label %4, label %6 ; CHECK: edge -> probability is 0x30000000 / 0x80000000 = 37.50% @@ -23,7 +23,7 @@ define i32 @cmp1(ptr readnone %0, ptr readnone %1) { } define i32 @cmp2(ptr readnone %0, ptr readnone %1) { -; CHECK: Printing analysis results of BPI for function 'cmp2': +; CHECK-LABEL: 'cmp2' %3 = icmp eq ptr %0, %1 br i1 %3, label %6, label %4 ; CHECK: edge -> probability is 0x30000000 / 0x80000000 = 37.50% @@ -44,8 +44,8 @@ define i32 @cmp2(ptr readnone %0, ptr readnone %1) { ret i32 %9 } -; CHECK: Printing analysis results of BPI for function 'cmp3': define i32 @cmp3(ptr readnone %0) { +; CHECK-LABEL: 'cmp3' %2 = icmp eq ptr %0, null br i1 %2, label %3, label %5 ; CHECK: edge -> probability is 0x30000000 / 0x80000000 = 37.50% diff --git a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/branch-probability-analysis.ll b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/branch-probability-analysis.ll new file mode 100644 index 00000000000000..dad35fcd100d96 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/branch-probability-analysis.ll @@ -0,0 +1,9 @@ +; RUN: opt < %s -passes='print' -disable-output 2>&1 | FileCheck %s + +define void @test1() { +entry: + br label %exit + +exit: + ret void +} diff --git a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/branch-probability-analysis.ll.expected b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/branch-probability-analysis.ll.expected new file mode 100644 index 00000000000000..e2f26a7052f182 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/branch-probability-analysis.ll.expected @@ -0,0 +1,14 @@ +; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py +; RUN: opt < %s -passes='print' -disable-output 2>&1 | FileCheck %s + +define void @test1() { +; CHECK-LABEL: 'test1' +; CHECK-NEXT: ---- Branch Probabilities ---- +; CHECK-NEXT: edge entry -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge] +; +entry: + br label %exit + +exit: + ret void +} diff --git a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/branch-probability-analysis.test b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/branch-probability-analysis.test new file mode 100644 index 00000000000000..1e7ac8dd7e8f03 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/branch-probability-analysis.test @@ -0,0 +1,6 @@ +## Basic test checking that update_analyze_test_checks.py works correctly +# RUN: cp -f %S/Inputs/branch-probability-analysis.ll %t.ll && %update_analyze_test_checks %t.ll +# RUN: diff -u %t.ll %S/Inputs/branch-probability-analysis.ll.expected +## Check that running the script again does not change the result: +# RUN: %update_analyze_test_checks %t.ll +# RUN: diff -u %t.ll %S/Inputs/branch-probability-analysis.ll.expected diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py index d1fd88444cfa12..5c3775e3d08591 100644 --- a/llvm/utils/UpdateTestChecks/common.py +++ b/llvm/utils/UpdateTestChecks/common.py @@ -32,6 +32,14 @@ DEFAULT_VERSION = 4 +SUPPORTED_ANALYSES = { + "Branch Probability Analysis", + "Cost Model Analysis", + "Loop Access Analysis", + "Scalar Evolution Analysis", +} + + class Regex(object): """Wrap a compiled regular expression object to allow deep copy of a regexp. This is required for the deep copy done in do_scrub. @@ -773,12 +781,7 @@ def process_run_line( ) if "analysis" in m.groupdict(): analysis = m.group("analysis") - supported_analyses = { - "cost model analysis", - "scalar evolution analysis", - "loop access analysis", - } - if analysis.lower() not in supported_analyses: + if analysis not in SUPPORTED_ANALYSES: warn("Unsupported analysis mode: %r!" % (analysis,)) if func.startswith("stress"): # We only use the last line of the function body for stress tests.