• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; Test the profile summary for context sensitive PGO (CSPGO)
2
3; RUN: llvm-profdata merge %S/Inputs/cspgo.proftext -o %t.profdata
4; RUN: opt < %s -passes='default<O2>' -disable-preinline -pgo-instrument-entry=false -pgo-kind=pgo-instr-use-pipeline -profile-file=%t.profdata -S | FileCheck %s --check-prefix=PGOSUMMARY
5; RUN: opt < %s -O2 -disable-preinline -pgo-instrument-entry=false -pgo-kind=pgo-instr-use-pipeline -profile-file=%t.profdata -S | FileCheck %s --check-prefix=PGOSUMMARY
6; RUN: opt < %s -O2 -disable-preinline -pgo-instrument-entry=false -pgo-kind=pgo-instr-use-pipeline -profile-file=%t.profdata -S -cspgo-kind=cspgo-instr-use-pipeline| FileCheck %s --check-prefix=CSPGOSUMMARY
7
8target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
9target triple = "x86_64-unknown-linux-gnu"
10
11@odd = common dso_local global i32 0, align 4
12@even = common dso_local global i32 0, align 4
13@not_six = common dso_local global i32 0, align 4
14
15define dso_local i32 @goo(i32 %n) {
16entry:
17  %i = alloca i32, align 4
18  %i.0..sroa_cast = bitcast i32* %i to i8*
19  store volatile i32 %n, i32* %i, align 4
20  %i.0. = load volatile i32, i32* %i, align 4
21  ret i32 %i.0.
22}
23
24define dso_local void @bar(i32 %n) {
25entry:
26  %call = call fastcc i32 @cond(i32 %n)
27  %tobool = icmp eq i32 %call, 0
28  br i1 %tobool, label %if.else, label %if.then
29
30if.then:
31  %0 = load i32, i32* @odd, align 4
32  %inc = add i32 %0, 1
33  store i32 %inc, i32* @odd, align 4
34  br label %if.end
35
36if.else:
37  %1 = load i32, i32* @even, align 4
38  %inc1 = add i32 %1, 1
39  store i32 %inc1, i32* @even, align 4
40  br label %if.end
41
42if.end:
43  br label %for.cond
44
45for.cond:
46  %i.0 = phi i32 [ 0, %if.end ], [ %inc6, %for.inc ]
47  %cmp = icmp ult i32 %i.0, 4
48  br i1 %cmp, label %for.body, label %for.end
49
50for.body:
51  %mul = mul nsw i32 %i.0, %n
52  %rem = srem i32 %mul, 6
53  %tobool2 = icmp eq i32 %rem, 0
54  br i1 %tobool2, label %for.inc, label %if.then3
55
56if.then3:
57  %2 = load i32, i32* @not_six, align 4
58  %inc4 = add i32 %2, 1
59  store i32 %inc4, i32* @not_six, align 4
60  br label %for.inc
61
62for.inc:
63  %inc6 = add nuw nsw i32 %i.0, 1
64  br label %for.cond
65
66for.end:
67  ret void
68}
69; PGOSUMMARY-LABEL: @bar
70; PGOSUMMARY: %odd.sink{{[0-9]*}} = select i1 %tobool{{[0-9]*}}, i32* @even, i32* @odd
71; PGOSUMMARY-SAME: !prof ![[BW_PGO_BAR:[0-9]+]]
72; CSPGOSUMMARY-LABEL: @bar
73; CSPGOSUMMARY: %odd.sink{{[0-9]*}} = select i1 %tobool{{[0-9]*}}, i32* @even, i32* @odd
74; CSPGOSUMMARY-SAME: !prof ![[BW_CSPGO_BAR:[0-9]+]]
75
76define internal fastcc i32 @cond(i32 %i) {
77entry:
78  %rem = srem i32 %i, 2
79  ret i32 %rem
80}
81
82define dso_local void @foo() {
83entry:
84  br label %for.cond
85
86for.cond:
87  %i.0 = phi i32 [ 0, %entry ], [ %add4, %for.body ]
88  %cmp = icmp slt i32 %i.0, 200000
89  br i1 %cmp, label %for.body, label %for.end
90
91for.body:
92  %call = call i32 @goo(i32 %i.0)
93  call void @bar(i32 %call)
94  %add = add nsw i32 %call, 1
95  call void @bar(i32 %add)
96  %call1 = call i32 @bar_m(i32 %call) #4
97  %call3 = call i32 @bar_m2(i32 %add) #4
98  call fastcc void @barbar()
99  %add4 = add nsw i32 %call, 2
100  br label %for.cond
101
102for.end:
103  ret void
104}
105; CSPGOSUMMARY-LABEL: @foo
106; CSPGOSUMMARY: %even.sink{{[0-9]*}} = select i1 %tobool.i{{[0-9]*}}, i32* @even, i32* @odd
107; CSPGOSUMMARY-SAME: !prof ![[BW1_CSPGO_FOO:[0-9]+]]
108; CSPGOSUMMARY: %even.sink{{[0-9]*}} = select i1 %tobool.i{{[0-9]*}}, i32* @even, i32* @odd
109; CSPGOSUMMARY-SAME: !prof ![[BW2_CSPGO_FOO:[0-9]+]]
110
111declare dso_local i32 @bar_m(i32)
112declare dso_local i32 @bar_m2(i32)
113
114define internal fastcc void @barbar() {
115entry:
116  %0 = load i32, i32* @odd, align 4
117  %inc = add i32 %0, 1
118  store i32 %inc, i32* @odd, align 4
119  ret void
120}
121
122define dso_local i32 @main() {
123entry:
124  call void @foo()
125  ret i32 0
126}
127
128; PGOSUMMARY: {{![0-9]+}} = !{i32 1, !"ProfileSummary", !{{[0-9]+}}}
129; PGOSUMMARY: {{![0-9]+}} = !{!"ProfileFormat", !"InstrProf"}
130; PGOSUMMARY: {{![0-9]+}} = !{!"TotalCount", i64 2100001}
131; PGOSUMMARY: {{![0-9]+}} = !{!"MaxCount", i64 800000}
132; PGOSUMMARY: {{![0-9]+}} = !{!"MaxInternalCount", i64 399999}
133; PGOSUMMARY: {{![0-9]+}} = !{!"MaxFunctionCount", i64 800000}
134; PGOSUMMARY: {{![0-9]+}} = !{!"NumCounts", i64 14}
135; PGOSUMMARY: {{![0-9]+}} = !{!"NumFunctions", i64 8}
136; PGOSUMMARY-DAG: ![[BW_PGO_BAR]] = !{!"branch_weights", i32 100000, i32 100000}
137
138; CSPGOSUMMARY: {{![0-9]+}} = !{i32 1, !"ProfileSummary", !1}
139; CSPGOSUMMARY: {{![0-9]+}} = !{!"ProfileFormat", !"InstrProf"}
140; CSPGOSUMMARY: {{![0-9]+}} = !{!"TotalCount", i64 2100001}
141; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxCount", i64 800000}
142; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxInternalCount", i64 399999}
143; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxFunctionCount", i64 800000}
144; CSPGOSUMMARY: {{![0-9]+}} = !{!"NumCounts", i64 14}
145; CSPGOSUMMARY: {{![0-9]+}} = !{!"NumFunctions", i64 8}
146; CSPGOSUMMARY: {{![0-9]+}} = !{!"DetailedSummary", !{{[0-9]+}}}
147; CSPGOSUMMARY: {{![0-9]+}} = !{i32 1, !"CSProfileSummary", !{{[0-9]+}}}
148; CSPGOSUMMARY: {{![0-9]+}} = !{!"ProfileFormat", !"CSInstrProf"}
149; CSPGOSUMMARY: {{![0-9]+}} = !{!"TotalCount", i64 1299950}
150; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxCount", i64 200000}
151; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxInternalCount", i64 100000}
152; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxFunctionCount", i64 200000}
153; CSPGOSUMMARY: {{![0-9]+}} = !{!"NumCounts", i64 23}
154; CSPGOSUMMARY-DAG: ![[BW_CSPGO_BAR]] = !{!"branch_weights", i32 100000, i32 100000}
155; CSPGOSUMMARY-DAG: ![[BW1_CSPGO_FOO]] = !{!"branch_weights", i32 100000, i32 0}
156; CSPGOSUMMARY-DAG: ![[BW2_CSPGO_FOO]] = !{!"branch_weights", i32 0, i32 100000}
157