2 ; RUN: llvm-profdata merge %S/Inputs/misexpect-switch.proftext -o %t.profdata
4 ; 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
5 ; 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
6 ; 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
7 ; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED
10 ; 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
11 ; 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
12 ; 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
13 ; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED
15 ; WARNING-DAG: warning: <unknown>:0:0: 0.00%
16 ; WARNING-NOT: remark: <unknown>:0:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 27943) of profiled executions.
18 ; REMARK-NOT: warning: <unknown>:0:0: 0.00%
19 ; REMARK-DAG: remark: <unknown>:0:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 27943) of profiled executions.
21 ; BOTH-DAG: warning: <unknown>:0:0: 0.00%
22 ; BOTH-DAG: remark: <unknown>:0:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 27943) of profiled executions.
24 ; DISABLED-NOT: warning: <unknown>:0:0: 0.00%
25 ; DISABLED-NOT: remark: <unknown>:0:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 27943) of profiled executions.
27 ; DISABLED-NOT: warning: <unknown>:0:0: 0.00%
28 ; DISABLED-NOT: remark: <unknown>:0:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 27943) of profiled executions.
30 ; CORRECT-NOT: warning: {{.*}}
31 ; CORRECT-NOT: remark: {{.*}}
32 ; CHECK-DAG: !{!"misexpect", i64 0, i64 2000, i64 1}
36 ; ModuleID = 'misexpect-switch.c'
37 source_filename = "misexpect-switch.c"
38 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
39 target triple = "x86_64-unknown-linux-gnu"
41 @inner_loop = dso_local constant i32 1000, align 4
42 @outer_loop = dso_local constant i32 20, align 4
43 @arry_size = dso_local constant i32 25, align 4
44 @arry = dso_local global [25 x i32] zeroinitializer, align 16
46 ; Function Attrs: nounwind uwtable
47 define dso_local void @init_arry() #0 {
49 %i = alloca i32, align 4
50 %0 = bitcast i32* %i to i8*
51 call void @llvm.lifetime.start.p0i8(i64 4, i8* %0) #6
52 store i32 0, i32* %i, align 4, !tbaa !4
55 for.cond: ; preds = %for.inc, %entry
56 %1 = load i32, i32* %i, align 4, !tbaa !4
57 %cmp = icmp slt i32 %1, 25
58 br i1 %cmp, label %for.body, label %for.end
60 for.body: ; preds = %for.cond
61 %call = call i32 @rand() #6
62 %rem = srem i32 %call, 10
63 %2 = load i32, i32* %i, align 4, !tbaa !4
64 %idxprom = sext i32 %2 to i64
65 %arrayidx = getelementptr inbounds [25 x i32], [25 x i32]* @arry, i64 0, i64 %idxprom
66 store i32 %rem, i32* %arrayidx, align 4, !tbaa !4
69 for.inc: ; preds = %for.body
70 %3 = load i32, i32* %i, align 4, !tbaa !4
71 %inc = add nsw i32 %3, 1
72 store i32 %inc, i32* %i, align 4, !tbaa !4
75 for.end: ; preds = %for.cond
76 %4 = bitcast i32* %i to i8*
77 call void @llvm.lifetime.end.p0i8(i64 4, i8* %4) #6
81 ; Function Attrs: argmemonly nounwind willreturn
82 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1
84 ; Function Attrs: nounwind readnone speculatable willreturn
85 declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
87 ; Function Attrs: nounwind
88 declare dso_local i32 @rand() #3
90 ; Function Attrs: argmemonly nounwind willreturn
91 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1
93 ; Function Attrs: nounwind uwtable
94 define dso_local i32 @main() #0 {
96 %retval = alloca i32, align 4
97 %val = alloca i32, align 4
98 %j = alloca i32, align 4
99 %condition = alloca i32, align 4
100 store i32 0, i32* %retval, align 4
101 call void @init_arry()
102 %0 = bitcast i32* %val to i8*
103 call void @llvm.lifetime.start.p0i8(i64 4, i8* %0) #6
104 store i32 0, i32* %val, align 4, !tbaa !4
105 %1 = bitcast i32* %j to i8*
106 call void @llvm.lifetime.start.p0i8(i64 4, i8* %1) #6
107 store i32 0, i32* %j, align 4, !tbaa !4
110 for.cond: ; preds = %for.inc, %entry
111 %2 = load i32, i32* %j, align 4, !tbaa !4
112 %cmp = icmp slt i32 %2, 20000
113 br i1 %cmp, label %for.body, label %for.end
115 for.body: ; preds = %for.cond
116 %3 = bitcast i32* %condition to i8*
117 call void @llvm.lifetime.start.p0i8(i64 4, i8* %3) #6
118 %call = call i32 @rand() #6
119 %rem = srem i32 %call, 5
120 store i32 %rem, i32* %condition, align 4, !tbaa !4
121 %4 = load i32, i32* %condition, align 4, !tbaa !4
122 %conv = zext i32 %4 to i64
123 %expval = call i64 @llvm.expect.i64(i64 %conv, i64 6)
124 switch i64 %expval, label %sw.default [
132 sw.bb: ; preds = %for.body
133 %call1 = call i32 @sum(i32* getelementptr inbounds ([25 x i32], [25 x i32]* @arry, i64 0, i64 0), i32 25)
134 %5 = load i32, i32* %val, align 4, !tbaa !4
135 %add = add nsw i32 %5, %call1
136 store i32 %add, i32* %val, align 4, !tbaa !4
139 sw.bb2: ; preds = %for.body, %for.body, %for.body
142 sw.bb3: ; preds = %for.body
143 %call4 = call i32 @random_sample(i32* getelementptr inbounds ([25 x i32], [25 x i32]* @arry, i64 0, i64 0), i32 25)
144 %6 = load i32, i32* %val, align 4, !tbaa !4
145 %add5 = add nsw i32 %6, %call4
146 store i32 %add5, i32* %val, align 4, !tbaa !4
149 sw.default: ; preds = %for.body
152 sw.epilog: ; preds = %sw.bb3, %sw.bb2, %sw.bb
153 %7 = bitcast i32* %condition to i8*
154 call void @llvm.lifetime.end.p0i8(i64 4, i8* %7) #6
157 for.inc: ; preds = %sw.epilog
158 %8 = load i32, i32* %j, align 4, !tbaa !4
159 %inc = add nsw i32 %8, 1
160 store i32 %inc, i32* %j, align 4, !tbaa !4
163 for.end: ; preds = %for.cond
164 %9 = bitcast i32* %j to i8*
165 call void @llvm.lifetime.end.p0i8(i64 4, i8* %9) #6
166 %10 = bitcast i32* %val to i8*
167 call void @llvm.lifetime.end.p0i8(i64 4, i8* %10) #6
171 ; Function Attrs: nounwind readnone willreturn
172 declare i64 @llvm.expect.i64(i64, i64) #4
174 declare dso_local i32 @sum(i32*, i32) #5
176 declare dso_local i32 @random_sample(i32*, i32) #5
178 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" }
179 attributes #1 = { argmemonly nounwind willreturn }
180 attributes #2 = { nounwind readnone speculatable willreturn }
181 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" }
182 attributes #4 = { nounwind readnone willreturn }
183 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" }
184 attributes #6 = { nounwind }
186 !llvm.module.flags = !{!0, !1, !2}
189 !0 = !{i32 2, !"Dwarf Version", i32 4}
190 !1 = !{i32 2, !"Debug Info Version", i32 3}
191 !2 = !{i32 1, !"wchar_size", i32 4}
192 !3 = !{!"clang version 10.0.0 (60b79b85b1763d3d25630261e5cd1adb7f0835bc)"}
193 !4 = !{!5, !5, i64 0}
194 !5 = !{!"int", !6, i64 0}
195 !6 = !{!"omnipotent char", !7, i64 0}
196 !7 = !{!"Simple C/C++ TBAA"}