2 ; RUN: llvm-profdata merge %S/Inputs/misexpect-switch.proftext -o %t.profdata
3 ; RUN: llvm-profdata merge %S/Inputs/misexpect-switch-correct.proftext -o %t.c.profdata
5 ; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect 2>&1 | FileCheck %s --check-prefix=WARNING
6 ; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=REMARK
7 ; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=BOTH
8 ; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED
11 ; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING
12 ; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK
13 ; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH
14 ; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED
16 ; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.c.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=CORRECT
17 ; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.c.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=CORRECT
19 ; WARNING-DAG: warning: misexpect-switch.c:26:5: 0.00%
20 ; WARNING-NOT: remark: misexpect-switch.c:26:5: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 8112) of profiled executions.
22 ; REMARK-NOT: warning: misexpect-switch.c:26:5: 0.00%
23 ; REMARK-DAG: remark: misexpect-switch.c:26:5: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 8112) of profiled executions.
25 ; BOTH-DAG: warning: misexpect-switch.c:26:5: 0.00%
26 ; BOTH-DAG: remark: misexpect-switch.c:26:5: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 8112) of profiled executions.
28 ; DISABLED-NOT: warning: misexpect-switch.c:26:5: 0.00%
29 ; DISABLED-NOT: remark: misexpect-switch.c:26:5: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 8112) of profiled executions.
31 ; DISABLED-NOT: warning: misexpect-switch.c:26:5: 0.00%
32 ; DISABLED-NOT: remark: misexpect-switch.c:26:5: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 8112) of profiled executions.
34 ; CORRECT-NOT: warning: {{.*}}
35 ; CORRECT-NOT: remark: {{.*}}
36 ; CHECK-DAG: !{!"misexpect", i64 0, i64 2000, i64 1}
40 ; ModuleID = 'misexpect-switch.c'
41 source_filename = "misexpect-switch.c"
42 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
43 target triple = "x86_64-unknown-linux-gnu"
45 @inner_loop = dso_local constant i32 1000, align 4, !dbg !0
46 @outer_loop = dso_local constant i32 20, align 4, !dbg !6
47 @arry_size = dso_local constant i32 25, align 4, !dbg !10
48 @arry = dso_local global [25 x i32] zeroinitializer, align 16, !dbg !12
50 ; Function Attrs: nounwind uwtable
51 define dso_local void @init_arry() #0 !dbg !21 {
53 %i = alloca i32, align 4
54 %0 = bitcast i32* %i to i8*, !dbg !26
55 call void @llvm.lifetime.start.p0i8(i64 4, i8* %0) #6, !dbg !26
56 call void @llvm.dbg.declare(metadata i32* %i, metadata !25, metadata !DIExpression()), !dbg !27
57 store i32 0, i32* %i, align 4, !dbg !28, !tbaa !30
58 br label %for.cond, !dbg !34
60 for.cond: ; preds = %for.inc, %entry
61 %1 = load i32, i32* %i, align 4, !dbg !35, !tbaa !30
62 %cmp = icmp slt i32 %1, 25, !dbg !37
63 br i1 %cmp, label %for.body, label %for.end, !dbg !38
65 for.body: ; preds = %for.cond
66 %call = call i32 @rand() #6, !dbg !39
67 %rem = srem i32 %call, 10, !dbg !41
68 %2 = load i32, i32* %i, align 4, !dbg !42, !tbaa !30
69 %idxprom = sext i32 %2 to i64, !dbg !43
70 %arrayidx = getelementptr inbounds [25 x i32], [25 x i32]* @arry, i64 0, i64 %idxprom, !dbg !43
71 store i32 %rem, i32* %arrayidx, align 4, !dbg !44, !tbaa !30
72 br label %for.inc, !dbg !45
74 for.inc: ; preds = %for.body
75 %3 = load i32, i32* %i, align 4, !dbg !46, !tbaa !30
76 %inc = add nsw i32 %3, 1, !dbg !46
77 store i32 %inc, i32* %i, align 4, !dbg !46, !tbaa !30
78 br label %for.cond, !dbg !47, !llvm.loop !48
80 for.end: ; preds = %for.cond
81 %4 = bitcast i32* %i to i8*, !dbg !50
82 call void @llvm.lifetime.end.p0i8(i64 4, i8* %4) #6, !dbg !50
86 ; Function Attrs: argmemonly nounwind willreturn
87 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1
89 ; Function Attrs: nounwind readnone speculatable willreturn
90 declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
92 ; Function Attrs: nounwind
93 declare dso_local i32 @rand() #3
95 ; Function Attrs: argmemonly nounwind willreturn
96 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1
98 ; Function Attrs: nounwind uwtable
99 define dso_local i32 @main() #0 !dbg !51 {
101 %retval = alloca i32, align 4
102 %val = alloca i32, align 4
103 %j = alloca i32, align 4
104 %condition = alloca i32, align 4
105 store i32 0, i32* %retval, align 4
106 call void @init_arry(), !dbg !62
107 %0 = bitcast i32* %val to i8*, !dbg !63
108 call void @llvm.lifetime.start.p0i8(i64 4, i8* %0) #6, !dbg !63
109 call void @llvm.dbg.declare(metadata i32* %val, metadata !55, metadata !DIExpression()), !dbg !64
110 store i32 0, i32* %val, align 4, !dbg !64, !tbaa !30
111 %1 = bitcast i32* %j to i8*, !dbg !65
112 call void @llvm.lifetime.start.p0i8(i64 4, i8* %1) #6, !dbg !65
113 call void @llvm.dbg.declare(metadata i32* %j, metadata !56, metadata !DIExpression()), !dbg !66
114 store i32 0, i32* %j, align 4, !dbg !67, !tbaa !30
115 br label %for.cond, !dbg !68
117 for.cond: ; preds = %for.inc, %entry
118 %2 = load i32, i32* %j, align 4, !dbg !69, !tbaa !30
119 %cmp = icmp slt i32 %2, 20000, !dbg !70
120 br i1 %cmp, label %for.body, label %for.end, !dbg !71
122 for.body: ; preds = %for.cond
123 %3 = bitcast i32* %condition to i8*, !dbg !72
124 call void @llvm.lifetime.start.p0i8(i64 4, i8* %3) #6, !dbg !72
125 call void @llvm.dbg.declare(metadata i32* %condition, metadata !57, metadata !DIExpression()), !dbg !73
126 %call = call i32 @rand() #6, !dbg !74
127 %rem = srem i32 %call, 5, !dbg !75
128 store i32 %rem, i32* %condition, align 4, !dbg !73, !tbaa !30
129 %4 = load i32, i32* %condition, align 4, !dbg !76, !tbaa !30
130 %conv = zext i32 %4 to i64, !dbg !76
131 %expval = call i64 @llvm.expect.i64(i64 %conv, i64 0), !dbg !77
132 switch i64 %expval, label %sw.default [
140 sw.bb: ; preds = %for.body
141 %call1 = call i32 @sum(i32* getelementptr inbounds ([25 x i32], [25 x i32]* @arry, i64 0, i64 0), i32 25), !dbg !79
142 %5 = load i32, i32* %val, align 4, !dbg !81, !tbaa !30
143 %add = add nsw i32 %5, %call1, !dbg !81
144 store i32 %add, i32* %val, align 4, !dbg !81, !tbaa !30
145 br label %sw.epilog, !dbg !82
147 sw.bb2: ; preds = %for.body, %for.body, %for.body
148 br label %sw.epilog, !dbg !83
150 sw.bb3: ; preds = %for.body
151 %call4 = call i32 @random_sample(i32* getelementptr inbounds ([25 x i32], [25 x i32]* @arry, i64 0, i64 0), i32 25), !dbg !84
152 %6 = load i32, i32* %val, align 4, !dbg !85, !tbaa !30
153 %add5 = add nsw i32 %6, %call4, !dbg !85
154 store i32 %add5, i32* %val, align 4, !dbg !85, !tbaa !30
155 br label %sw.epilog, !dbg !86
157 sw.default: ; preds = %for.body
158 unreachable, !dbg !87
160 sw.epilog: ; preds = %sw.bb3, %sw.bb2, %sw.bb
161 %7 = bitcast i32* %condition to i8*, !dbg !88
162 call void @llvm.lifetime.end.p0i8(i64 4, i8* %7) #6, !dbg !88
163 br label %for.inc, !dbg !89
165 for.inc: ; preds = %sw.epilog
166 %8 = load i32, i32* %j, align 4, !dbg !90, !tbaa !30
167 %inc = add nsw i32 %8, 1, !dbg !90
168 store i32 %inc, i32* %j, align 4, !dbg !90, !tbaa !30
169 br label %for.cond, !dbg !91, !llvm.loop !92
171 for.end: ; preds = %for.cond
172 %9 = bitcast i32* %j to i8*, !dbg !94
173 call void @llvm.lifetime.end.p0i8(i64 4, i8* %9) #6, !dbg !94
174 %10 = bitcast i32* %val to i8*, !dbg !94
175 call void @llvm.lifetime.end.p0i8(i64 4, i8* %10) #6, !dbg !94
179 ; Function Attrs: nounwind readnone willreturn
180 declare i64 @llvm.expect.i64(i64, i64) #4
182 declare dso_local i32 @sum(i32*, i32) #5
184 declare dso_local i32 @random_sample(i32*, i32) #5
186 attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
187 attributes #1 = { argmemonly nounwind willreturn }
188 attributes #2 = { nounwind readnone speculatable willreturn }
189 attributes #3 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
190 attributes #4 = { nounwind readnone willreturn }
191 attributes #5 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
192 attributes #6 = { nounwind }
195 !llvm.module.flags = !{!17, !18, !19}
198 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
199 !1 = distinct !DIGlobalVariable(name: "inner_loop", scope: !2, file: !3, line: 7, type: !8, isLocal: false, isDefinition: true)
200 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 10.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None)
201 !3 = !DIFile(filename: "misexpect-switch.c", directory: ".")
203 !5 = !{!0, !6, !10, !12}
204 !6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
205 !7 = distinct !DIGlobalVariable(name: "outer_loop", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true)
206 !8 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !9)
207 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
208 !10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression())
209 !11 = distinct !DIGlobalVariable(name: "arry_size", scope: !2, file: !3, line: 9, type: !8, isLocal: false, isDefinition: true)
210 !12 = !DIGlobalVariableExpression(var: !13, expr: !DIExpression())
211 !13 = distinct !DIGlobalVariable(name: "arry", scope: !2, file: !3, line: 11, type: !14, isLocal: false, isDefinition: true)
212 !14 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, size: 800, elements: !15)
214 !16 = !DISubrange(count: 25)
215 !17 = !{i32 2, !"Dwarf Version", i32 4}
216 !18 = !{i32 2, !"Debug Info Version", i32 3}
217 !19 = !{i32 1, !"wchar_size", i32 4}
218 !20 = !{!"clang version 10.0.0"}
219 !21 = distinct !DISubprogram(name: "init_arry", scope: !3, file: !3, line: 13, type: !22, scopeLine: 13, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !24)
220 !22 = !DISubroutineType(types: !23)
223 !25 = !DILocalVariable(name: "i", scope: !21, file: !3, line: 14, type: !9)
224 !26 = !DILocation(line: 14, column: 3, scope: !21)
225 !27 = !DILocation(line: 14, column: 7, scope: !21)
226 !28 = !DILocation(line: 15, column: 10, scope: !29)
227 !29 = distinct !DILexicalBlock(scope: !21, file: !3, line: 15, column: 3)
228 !30 = !{!31, !31, i64 0}
229 !31 = !{!"int", !32, i64 0}
230 !32 = !{!"omnipotent char", !33, i64 0}
231 !33 = !{!"Simple C/C++ TBAA"}
232 !34 = !DILocation(line: 15, column: 8, scope: !29)
233 !35 = !DILocation(line: 15, column: 15, scope: !36)
234 !36 = distinct !DILexicalBlock(scope: !29, file: !3, line: 15, column: 3)
235 !37 = !DILocation(line: 15, column: 17, scope: !36)
236 !38 = !DILocation(line: 15, column: 3, scope: !29)
237 !39 = !DILocation(line: 16, column: 15, scope: !40)
238 !40 = distinct !DILexicalBlock(scope: !36, file: !3, line: 15, column: 35)
239 !41 = !DILocation(line: 16, column: 22, scope: !40)
240 !42 = !DILocation(line: 16, column: 10, scope: !40)
241 !43 = !DILocation(line: 16, column: 5, scope: !40)
242 !44 = !DILocation(line: 16, column: 13, scope: !40)
243 !45 = !DILocation(line: 17, column: 3, scope: !40)
244 !46 = !DILocation(line: 15, column: 30, scope: !36)
245 !47 = !DILocation(line: 15, column: 3, scope: !36)
246 !48 = distinct !{!48, !38, !49}
247 !49 = !DILocation(line: 17, column: 3, scope: !29)
248 !50 = !DILocation(line: 18, column: 1, scope: !21)
249 !51 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 20, type: !52, scopeLine: 20, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !54)
250 !52 = !DISubroutineType(types: !53)
252 !54 = !{!55, !56, !57}
253 !55 = !DILocalVariable(name: "val", scope: !51, file: !3, line: 22, type: !9)
254 !56 = !DILocalVariable(name: "j", scope: !51, file: !3, line: 23, type: !9)
255 !57 = !DILocalVariable(name: "condition", scope: !58, file: !3, line: 25, type: !61)
256 !58 = distinct !DILexicalBlock(scope: !59, file: !3, line: 24, column: 49)
257 !59 = distinct !DILexicalBlock(scope: !60, file: !3, line: 24, column: 3)
258 !60 = distinct !DILexicalBlock(scope: !51, file: !3, line: 24, column: 3)
259 !61 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
260 !62 = !DILocation(line: 21, column: 3, scope: !51)
261 !63 = !DILocation(line: 22, column: 3, scope: !51)
262 !64 = !DILocation(line: 22, column: 7, scope: !51)
263 !65 = !DILocation(line: 23, column: 3, scope: !51)
264 !66 = !DILocation(line: 23, column: 7, scope: !51)
265 !67 = !DILocation(line: 24, column: 10, scope: !60)
266 !68 = !DILocation(line: 24, column: 8, scope: !60)
267 !69 = !DILocation(line: 24, column: 15, scope: !59)
268 !70 = !DILocation(line: 24, column: 17, scope: !59)
269 !71 = !DILocation(line: 24, column: 3, scope: !60)
270 !72 = !DILocation(line: 25, column: 5, scope: !58)
271 !73 = !DILocation(line: 25, column: 14, scope: !58)
272 !74 = !DILocation(line: 25, column: 26, scope: !58)
273 !75 = !DILocation(line: 25, column: 33, scope: !58)
274 !76 = !DILocation(line: 26, column: 30, scope: !58)
275 !77 = !DILocation(line: 26, column: 13, scope: !58)
276 !78 = !DILocation(line: 26, column: 5, scope: !58)
277 !79 = !DILocation(line: 28, column: 14, scope: !80)
278 !80 = distinct !DILexicalBlock(scope: !58, file: !3, line: 26, column: 45)
279 !81 = !DILocation(line: 28, column: 11, scope: !80)
280 !82 = !DILocation(line: 29, column: 7, scope: !80)
281 !83 = !DILocation(line: 33, column: 7, scope: !80)
282 !84 = !DILocation(line: 35, column: 14, scope: !80)
283 !85 = !DILocation(line: 35, column: 11, scope: !80)
284 !86 = !DILocation(line: 36, column: 7, scope: !80)
285 !87 = !DILocation(line: 38, column: 7, scope: !80)
286 !88 = !DILocation(line: 40, column: 3, scope: !59)
287 !89 = !DILocation(line: 40, column: 3, scope: !58)
288 !90 = !DILocation(line: 24, column: 44, scope: !59)
289 !91 = !DILocation(line: 24, column: 3, scope: !59)
290 !92 = distinct !{!92, !71, !93}
291 !93 = !DILocation(line: 40, column: 3, scope: !60)
292 !94 = !DILocation(line: 43, column: 1, scope: !51)
293 !95 = !DILocation(line: 42, column: 3, scope: !51)