xref: /llvm-project/llvm/test/Transforms/PGOProfile/cspgo_sample.ll (revision b4fcaa137f057e68a9011b26c11627a16a8c9374)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2; REQUIRES: x86-registered-target
3
4; RUN: opt -module-summary %s -o %t1.bc
5; RUN: opt -module-summary %S/Inputs/cspgo_bar_sample.ll -o %t2.bc
6; RUN: llvm-lto2 run -lto-cspgo-profile-file=alloc -enable-sampled-instrumentation -lto-cspgo-gen -save-temps -o %t %t1.bc %t2.bc \
7; RUN:   -r=%t1.bc,foo,pl \
8; RUN:   -r=%t1.bc,bar,l \
9; RUN:   -r=%t1.bc,main,plx \
10; RUN:   -r=%t1.bc,__llvm_profile_filename,plx \
11; RUN:   -r=%t1.bc,__llvm_profile_raw_version,plx \
12; RUN:   -r=%t1.bc,__llvm_profile_sampling,pl \
13; RUN:   -r=%t2.bc,bar,pl \
14; RUN:   -r=%t2.bc,odd,pl \
15; RUN:   -r=%t2.bc,even,pl \
16; RUN:   -r=%t2.bc,__llvm_profile_filename,x \
17; RUN:   -r=%t2.bc,__llvm_profile_raw_version,x \
18; RUN:   -r=%t2.bc,__llvm_profile_sampling,
19; RUN: llvm-dis %t.1.4.opt.bc -o - | FileCheck %s --check-prefix=CSGEN
20
21; CSGEN: @__llvm_profile_sampling = thread_local global i16 0, comdat
22; CSGEN: @__profc_
23; CSGEN: @__profd_
24
25source_filename = "cspgo.c"
26target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
27target triple = "x86_64-unknown-linux-gnu"
28
29$__llvm_profile_filename = comdat any
30$__llvm_profile_raw_version = comdat any
31$__llvm_profile_sampling = comdat any
32@__llvm_profile_filename = local_unnamed_addr constant [25 x i8] c"pass2/default_%m.profraw\00", comdat
33@__llvm_profile_raw_version = local_unnamed_addr constant i64 216172782113783812, comdat
34@__llvm_profile_sampling = thread_local global i16 0, comdat
35@llvm.used = appending global [1 x i8*] [i8* bitcast (i64* @__llvm_profile_sampling to i8*)], section "llvm.metadata"
36
37define dso_local void @foo() #0 !prof !30 {
38entry:
39  br label %for.body
40
41for.body:
42  %i.06 = phi i32 [ 0, %entry ], [ %add1, %for.body ]
43  tail call void @bar(i32 %i.06) #3
44  %add = or i32 %i.06, 1
45  tail call void @bar(i32 %add) #3
46  %add1 = add nuw nsw i32 %i.06, 2
47  %cmp = icmp ult i32 %add1, 200000
48  br i1 %cmp, label %for.body, label %for.end, !prof !31
49
50for.end:
51  ret void
52}
53
54; CSGEN-LABEL: @foo
55; CSGEN:        [[TMP0:%.*]]  = load i16, ptr @__llvm_profile_sampling, align 2
56; CSGEN-NEXT:   [[TMP1:%.*]] = icmp ult i16 [[TMP0]], 200
57; CSGEN-NEXT:   br i1 [[TMP1]], label %{{.*}}, label %{{.*}}, !prof [[PROF:![0-9]+]]
58; CSGEN:        [[TMP2:%.*]] = add i16 {{.*}}, 1
59; CSGEN-NEXT:   store i16 [[TMP2]], ptr @__llvm_profile_sampling, align 2
60
61declare dso_local void @bar(i32)
62
63define dso_local i32 @main() !prof !30 {
64entry:
65  tail call void @foo()
66  ret i32 0
67}
68; CSGEN-LABEL: @main
69; CSGEN:        [[TMP0:%.*]]  = load i16, ptr @__llvm_profile_sampling, align 2
70; CSGEN-NEXT:   [[TMP1:%.*]] = icmp ult i16 [[TMP0]], 200
71; CSGEN-NEXT:   br i1 [[TMP1]], label %{{.*}}, label %{{.*}}, !prof [[PROF:![0-9]+]]
72; CSGEN:        [[TMP2:%.*]] = add i16 {{.*}}, 1
73; CSGEN-NEXT:   store i16 [[TMP2]], ptr @__llvm_profile_sampling, align 2
74
75attributes #0 = { "target-cpu"="x86-64" }
76
77!llvm.module.flags = !{!0, !1, !2}
78
79!0 = !{i32 1, !"wchar_size", i32 4}
80!1 = !{i32 1, !"EnableSplitLTOUnit", i32 0}
81!2 = !{i32 1, !"ProfileSummary", !3}
82!3 = !{!4, !5, !6, !7, !8, !9, !10, !11}
83!4 = !{!"ProfileFormat", !"InstrProf"}
84!5 = !{!"TotalCount", i64 500002}
85!6 = !{!"MaxCount", i64 200000}
86!7 = !{!"MaxInternalCount", i64 100000}
87!8 = !{!"MaxFunctionCount", i64 200000}
88!9 = !{!"NumCounts", i64 6}
89!10 = !{!"NumFunctions", i64 4}
90!11 = !{!"DetailedSummary", !12}
91!12 = !{!13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28}
92!13 = !{i32 10000, i64 200000, i32 1}
93!14 = !{i32 100000, i64 200000, i32 1}
94!15 = !{i32 200000, i64 200000, i32 1}
95!16 = !{i32 300000, i64 200000, i32 1}
96!17 = !{i32 400000, i64 200000, i32 1}
97!18 = !{i32 500000, i64 100000, i32 4}
98!19 = !{i32 600000, i64 100000, i32 4}
99!20 = !{i32 700000, i64 100000, i32 4}
100!21 = !{i32 800000, i64 100000, i32 4}
101!22 = !{i32 900000, i64 100000, i32 4}
102!23 = !{i32 950000, i64 100000, i32 4}
103!24 = !{i32 990000, i64 100000, i32 4}
104!25 = !{i32 999000, i64 100000, i32 4}
105!26 = !{i32 999900, i64 100000, i32 4}
106!27 = !{i32 999990, i64 100000, i32 4}
107!28 = !{i32 999999, i64 1, i32 6}
108!30 = !{!"function_entry_count", i64 1}
109!31 = !{!"branch_weights", i32 100000, i32 1}
110
111; CSGEN: [[PROF]] = !{!"branch_weights", i32 200, i32 65336}
112
113