xref: /llvm-project/llvm/test/Transforms/SampleProfile/pseudo-probe-update.ll (revision 5bbce06ac642bedcb93158ed04253cf6deedf5e6)
1; RUN: opt < %s -passes='pseudo-probe,sample-profile,jump-threading,pseudo-probe-update' -sample-profile-file=%S/Inputs/pseudo-probe-update.prof -S  | FileCheck %s
2
3declare i32 @f1()
4declare i32 @f2()
5declare void @f3()
6
7
8;; This tests that the branch in 'merge' can be cloned up into T1.
9define i32 @foo(i1 %cond, i1 %cond2) #0 {
10; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1)
11	br i1 %cond, label %T1, label %F1
12T1:
13; CHECK: %v1 = call i32 @f1(), !prof ![[#PROF1:]]
14	%v1 = call i32 @f1()
15; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1)
16;; The distribution factor -8513881372706734080 stands for 53.85%, whic is from 7/6+7.
17; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 6, i32 0, i64 -8513881372706734080)
18    %cond3 = icmp eq i32 %v1, 412
19	br label %Merge
20F1:
21; CHECK: %v2 = call i32 @f2(), !prof ![[#PROF2:]]
22	%v2 = call i32 @f2()
23; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
24;; The distribution factor 8513881922462547968 stands for 46.25%, which is from 6/6+7.
25; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 6, i32 0, i64 8513881922462547968)
26	br label %Merge
27Merge:
28
29	%A = phi i1 [%cond3, %T1], [%cond2, %F1]
30	%B = phi i32 [%v1, %T1], [%v2, %F1]
31	br i1 %A, label %T2, label %F2
32T2:
33; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 7, i32 0, i64 -1)
34	call void @f3()
35	ret i32 %B
36F2:
37; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 9, i32 0, i64 -1)
38	ret i32 %B
39}
40
41; CHECK: ![[#PROF1]] = !{!"branch_weights", i32 7}
42; CHECK: ![[#PROF2]] = !{!"branch_weights", i32 6}
43
44attributes #0 = {"use-sample-profile"}
45