1 ; REQUIRES: x86_64-linux
4 ; RUN: split-file %s %t
5 ; RUN: llvm-ctxprof-util fromJSON --input=%t/profile.json --output=%t/profile.ctxprofdata
6 ; RUN: opt -module-summary -passes='thinlto-pre-link<O2>' -use-ctx-profile=%t/profile.ctxprofdata \
7 ; RUN: %t/example.ll -S -o %t/prelink.ll
8 ; RUN: FileCheck --input-file %t/prelink.ll %s --check-prefix=PRELINK
9 ; RUN: opt -passes='ctx-prof-flatten' -use-ctx-profile=%t/profile.ctxprofdata %t/prelink.ll -S | FileCheck %s
12 ; Check that instrumentation occurs where expected: the "no" block for both foo and
13 ; @an_entrypoint - which explains the subsequent branch weights
18 ; PRELINK-NEXT: call void @llvm.instrprof.increment(ptr @foo, i64 [[#]], i32 2, i32 1)
20 ; PRELINK-LABEL: @an_entrypoint
22 ; PRELINK-NEXT: call void @llvm.instrprof.increment(ptr @an_entrypoint, i64 [[#]], i32 2, i32 1)
23 ; PRELINK-NOT: "ProfileSummary"
25 ; Check that the output has:
26 ; - no instrumentation
27 ; - the 2 functions have an entry count
28 ; - each conditional branch has profile annotation
30 ; CHECK-NOT: call void @llvm.instrprof
32 ; make sure we have function entry counts, branch weights, and a profile summary.
34 ; CHECK-SAME: !prof ![[FOO_EP:[0-9]+]]
35 ; CHECK: br i1 %t, label %yes, label %no, !prof ![[FOO_BW:[0-9]+]]
36 ; CHECK-LABEL: @an_entrypoint
37 ; CHECK-SAME: !prof ![[AN_ENTRYPOINT_EP:[0-9]+]]
38 ; CHECK: br i1 %t, label %yes, label %common.ret, !prof ![[AN_ENTRYPOINT_BW:[0-9]+]]
41 ; CHECK: ![[#]] = !{i32 1, !"ProfileSummary", !1}
42 ; CHECK: ![[#]] = !{!"TotalCount", i64 480}
43 ; CHECK: ![[#]] = !{!"MaxCount", i64 140}
44 ; CHECK: ![[#]] = !{!"MaxInternalCount", i64 125}
45 ; CHECK: ![[#]] = !{!"MaxFunctionCount", i64 140}
46 ; CHECK: ![[#]] = !{!"NumCounts", i64 6}
47 ; CHECK: ![[#]] = !{!"NumFunctions", i64 2}
49 ; @foo will be called both unconditionally and conditionally, on the "yes" branch
50 ; which has a count of 40. So 140 times.
52 ; CHECK: ![[FOO_EP]] = !{!"function_entry_count", i64 140}
54 ; foo's "no" branch is taken 10+5 times (from the 2 contexts belonging to foo).
55 ; Which means its "yes" branch is taken 140 - 15 times.
57 ; CHECK: ![[FOO_BW]] = !{!"branch_weights", i32 125, i32 15}
58 ; CHECK: ![[AN_ENTRYPOINT_EP]] = !{!"function_entry_count", i64 100}
59 ; CHECK: ![[AN_ENTRYPOINT_BW]] = !{!"branch_weights", i32 40, i32 60}
64 "Guid": 4909520559318251808,
65 "Counters": [100, 40],
69 "Guid": 11872291593386833696,
70 "Counters": [ 100, 5 ]
75 "Guid": 11872291593386833696,
76 "Counters": [ 40, 10 ]
85 define void @foo(i32 %a, ptr %fct) #0 !guid !0 {
86 %t = icmp sgt i32 %a, 7
87 br i1 %t, label %yes, label %no
89 call void %fct(i32 %a)
98 define void @an_entrypoint(i32 %a) !guid !1 {
99 %t = icmp sgt i32 %a, 0
100 call void @foo(i32 10, ptr null)
101 br i1 %t, label %yes, label %no
104 call void @foo(i32 1, ptr null)
110 attributes #0 = { noinline }
111 !0 = !{ i64 11872291593386833696 }
112 !1 = !{i64 4909520559318251808}