1 ; Test the profile summary for context sensitive PGO (CSPGO)
3 ; RUN: llvm-profdata merge %S/Inputs/cspgo.proftext -o %t.profdata
4 ; RUN: opt < %s -O2 -disable-preinline -pgo-kind=pgo-instr-use-pipeline -profile-file=%t.profdata -S | FileCheck %s --check-prefix=PGOSUMMARY
5 ; RUN: opt < %s -O2 -disable-preinline -pgo-kind=pgo-instr-use-pipeline -profile-file=%t.profdata -S -cspgo-kind=cspgo-instr-use-pipeline| FileCheck %s --check-prefix=CSPGOSUMMARY
7 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
8 target triple = "x86_64-unknown-linux-gnu"
10 @odd = common dso_local global i32 0, align 4
11 @even = common dso_local global i32 0, align 4
12 @not_six = common dso_local global i32 0, align 4
14 define dso_local i32 @goo(i32 %n) {
16 %i = alloca i32, align 4
17 %i.0..sroa_cast = bitcast i32* %i to i8*
18 store volatile i32 %n, i32* %i, align 4
19 %i.0. = load volatile i32, i32* %i, align 4
23 define dso_local void @bar(i32 %n) {
25 %call = call fastcc i32 @cond(i32 %n)
26 %tobool = icmp eq i32 %call, 0
27 br i1 %tobool, label %if.else, label %if.then
30 %0 = load i32, i32* @odd, align 4
32 store i32 %inc, i32* @odd, align 4
36 %1 = load i32, i32* @even, align 4
38 store i32 %inc1, i32* @even, align 4
45 %i.0 = phi i32 [ 0, %if.end ], [ %inc6, %for.inc ]
46 %cmp = icmp ult i32 %i.0, 4
47 br i1 %cmp, label %for.body, label %for.end
50 %mul = mul nsw i32 %i.0, %n
51 %rem = srem i32 %mul, 6
52 %tobool2 = icmp eq i32 %rem, 0
53 br i1 %tobool2, label %for.inc, label %if.then3
56 %2 = load i32, i32* @not_six, align 4
58 store i32 %inc4, i32* @not_six, align 4
62 %inc6 = add nuw nsw i32 %i.0, 1
68 ; PGOSUMMARY-LABEL: @bar
69 ; PGOSUMMARY: %odd.sink = select i1 %tobool, i32* @even, i32* @odd
70 ; PGOSUMMARY-SAME: !prof ![[BW_PGO_BAR:[0-9]+]]
71 ; CSPGOSUMMARY-LABEL: @bar
72 ; CSPGOSUMMARY: %odd.sink = select i1 %tobool, i32* @even, i32* @odd
73 ; CSPGOSUMMARY-SAME: !prof ![[BW_CSPGO_BAR:[0-9]+]]
75 define internal fastcc i32 @cond(i32 %i) {
81 define dso_local void @foo() {
86 %i.0 = phi i32 [ 0, %entry ], [ %add4, %for.body ]
87 %cmp = icmp slt i32 %i.0, 200000
88 br i1 %cmp, label %for.body, label %for.end
91 %call = call i32 @goo(i32 %i.0)
92 call void @bar(i32 %call)
93 %add = add nsw i32 %call, 1
94 call void @bar(i32 %add)
95 %call1 = call i32 @bar_m(i32 %call) #4
96 %call3 = call i32 @bar_m2(i32 %add) #4
97 call fastcc void @barbar()
98 %add4 = add nsw i32 %call, 2
104 ; CSPGOSUMMARY-LABEL: @foo
105 ; CSPGOSUMMARY: %even.sink{{[0-9]*}} = select i1 %tobool.i{{[0-9]*}}, i32* @even, i32* @odd
106 ; CSPGOSUMMARY-SAME: !prof ![[BW1_CSPGO_FOO:[0-9]+]]
107 ; CSPGOSUMMARY: %even.sink{{[0-9]*}} = select i1 %tobool.i{{[0-9]*}}, i32* @even, i32* @odd
108 ; CSPGOSUMMARY-SAME: !prof ![[BW2_CSPGO_FOO:[0-9]+]]
110 declare dso_local i32 @bar_m(i32)
111 declare dso_local i32 @bar_m2(i32)
113 define internal fastcc void @barbar() {
115 %0 = load i32, i32* @odd, align 4
117 store i32 %inc, i32* @odd, align 4
121 define dso_local i32 @main() {
127 ; PGOSUMMARY: {{![0-9]+}} = !{i32 1, !"ProfileSummary", !{{[0-9]+}}}
128 ; PGOSUMMARY: {{![0-9]+}} = !{!"ProfileFormat", !"InstrProf"}
129 ; PGOSUMMARY: {{![0-9]+}} = !{!"TotalCount", i64 2100001}
130 ; PGOSUMMARY: {{![0-9]+}} = !{!"MaxCount", i64 800000}
131 ; PGOSUMMARY: {{![0-9]+}} = !{!"MaxInternalCount", i64 399999}
132 ; PGOSUMMARY: {{![0-9]+}} = !{!"MaxFunctionCount", i64 800000}
133 ; PGOSUMMARY: {{![0-9]+}} = !{!"NumCounts", i64 14}
134 ; PGOSUMMARY: {{![0-9]+}} = !{!"NumFunctions", i64 8}
135 ; PGOSUMMARY-DAG: ![[BW_PGO_BAR]] = !{!"branch_weights", i32 100000, i32 100000}
137 ; CSPGOSUMMARY: {{![0-9]+}} = !{i32 1, !"ProfileSummary", !1}
138 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"ProfileFormat", !"InstrProf"}
139 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"TotalCount", i64 2100001}
140 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxCount", i64 800000}
141 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxInternalCount", i64 399999}
142 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxFunctionCount", i64 800000}
143 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"NumCounts", i64 14}
144 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"NumFunctions", i64 8}
145 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"DetailedSummary", !10}
146 ; CSPGOSUMMARY: {{![0-9]+}} = !{i32 1, !"CSProfileSummary", !{{[0-9]+}}}
147 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"ProfileFormat", !"CSInstrProf"}
148 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"TotalCount", i64 1299950}
149 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxCount", i64 200000}
150 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxInternalCount", i64 100000}
151 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxFunctionCount", i64 200000}
152 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"NumCounts", i64 23}
153 ; CSPGOSUMMARY-DAG: ![[BW_CSPGO_BAR]] = !{!"branch_weights", i32 100000, i32 100000}
154 ; CSPGOSUMMARY-DAG: ![[BW1_CSPGO_FOO]] = !{!"branch_weights", i32 100000, i32 0}
155 ; CSPGOSUMMARY-DAG: ![[BW2_CSPGO_FOO]] = !{!"branch_weights", i32 0, i32 100000}