1 ; RUN: opt -S -passes='function(lower-expect),strip-dead-prototypes' < %s | FileCheck %s
4 define i32 @test1(i32 %x) nounwind uwtable ssp {
6 %retval = alloca i32, align 4
7 %x.addr = alloca i32, align 4
8 store i32 %x, ptr %x.addr, align 4
9 %tmp = load i32, ptr %x.addr, align 4
10 %cmp = icmp sgt i32 %tmp, 1
11 %conv = zext i1 %cmp to i32
12 %conv1 = sext i32 %conv to i64
13 %expval = call i64 @llvm.expect.i64(i64 %conv1, i64 1)
14 %tobool = icmp ne i64 %expval, 0
16 ; CHECK-NOT: @llvm.expect
17 br i1 %tobool, label %if.then, label %if.end
19 if.then: ; preds = %entry
20 %call = call i32 (...) @f()
21 store i32 %call, ptr %retval
24 if.end: ; preds = %entry
25 store i32 1, ptr %retval
28 return: ; preds = %if.end, %if.then
29 %0 = load i32, ptr %retval
33 declare i64 @llvm.expect.i64(i64, i64) nounwind readnone
37 ; CHECK-LABEL: @test2(
38 define i32 @test2(i32 %x) nounwind uwtable ssp {
40 %retval = alloca i32, align 4
41 %x.addr = alloca i32, align 4
42 store i32 %x, ptr %x.addr, align 4
43 %tmp = load i32, ptr %x.addr, align 4
44 %conv = sext i32 %tmp to i64
45 %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
46 %tobool = icmp ne i64 %expval, 0
48 ; CHECK-NOT: @llvm.expect
49 br i1 %tobool, label %if.then, label %if.end
51 if.then: ; preds = %entry
52 %call = call i32 (...) @f()
53 store i32 %call, ptr %retval
56 if.end: ; preds = %entry
57 store i32 1, ptr %retval
60 return: ; preds = %if.end, %if.then
61 %0 = load i32, ptr %retval
65 ; CHECK-LABEL: @test3(
66 define i32 @test3(i32 %x) nounwind uwtable ssp {
68 %retval = alloca i32, align 4
69 %x.addr = alloca i32, align 4
70 store i32 %x, ptr %x.addr, align 4
71 %tmp = load i32, ptr %x.addr, align 4
72 %tobool = icmp ne i32 %tmp, 0
73 %lnot = xor i1 %tobool, true
74 %lnot.ext = zext i1 %lnot to i32
75 %conv = sext i32 %lnot.ext to i64
76 %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
77 %tobool1 = icmp ne i64 %expval, 0
79 ; CHECK-NOT: @llvm.expect
80 br i1 %tobool1, label %if.then, label %if.end
82 if.then: ; preds = %entry
83 %call = call i32 (...) @f()
84 store i32 %call, ptr %retval
87 if.end: ; preds = %entry
88 store i32 1, ptr %retval
91 return: ; preds = %if.end, %if.then
92 %0 = load i32, ptr %retval
96 ; CHECK-LABEL: @test4(
97 define i32 @test4(i32 %x) nounwind uwtable ssp {
99 %retval = alloca i32, align 4
100 %x.addr = alloca i32, align 4
101 store i32 %x, ptr %x.addr, align 4
102 %tmp = load i32, ptr %x.addr, align 4
103 %tobool = icmp ne i32 %tmp, 0
104 %lnot = xor i1 %tobool, true
105 %lnot1 = xor i1 %lnot, true
106 %lnot.ext = zext i1 %lnot1 to i32
107 %conv = sext i32 %lnot.ext to i64
108 %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
109 %tobool2 = icmp ne i64 %expval, 0
111 ; CHECK-NOT: @llvm.expect
112 br i1 %tobool2, label %if.then, label %if.end
114 if.then: ; preds = %entry
115 %call = call i32 (...) @f()
116 store i32 %call, ptr %retval
119 if.end: ; preds = %entry
120 store i32 1, ptr %retval
123 return: ; preds = %if.end, %if.then
124 %0 = load i32, ptr %retval
128 ; CHECK-LABEL: @test5(
129 define i32 @test5(i32 %x) nounwind uwtable ssp {
131 %retval = alloca i32, align 4
132 %x.addr = alloca i32, align 4
133 store i32 %x, ptr %x.addr, align 4
134 %tmp = load i32, ptr %x.addr, align 4
135 %cmp = icmp slt i32 %tmp, 0
136 %conv = zext i1 %cmp to i32
137 %conv1 = sext i32 %conv to i64
138 %expval = call i64 @llvm.expect.i64(i64 %conv1, i64 0)
139 %tobool = icmp ne i64 %expval, 0
141 ; CHECK-NOT: @llvm.expect
142 br i1 %tobool, label %if.then, label %if.end
144 if.then: ; preds = %entry
145 %call = call i32 (...) @f()
146 store i32 %call, ptr %retval
149 if.end: ; preds = %entry
150 store i32 1, ptr %retval
153 return: ; preds = %if.end, %if.then
154 %0 = load i32, ptr %retval
158 ; CHECK-LABEL: @test6(
159 define i32 @test6(i32 %x) nounwind uwtable ssp {
161 %retval = alloca i32, align 4
162 %x.addr = alloca i32, align 4
163 store i32 %x, ptr %x.addr, align 4
164 %tmp = load i32, ptr %x.addr, align 4
165 %conv = sext i32 %tmp to i64
166 %expval = call i64 @llvm.expect.i64(i64 %conv, i64 2)
168 ; CHECK-NOT: @llvm.expect
169 switch i64 %expval, label %sw.epilog [
174 sw.bb: ; preds = %entry, %entry
175 store i32 0, ptr %retval
178 sw.epilog: ; preds = %entry
179 store i32 1, ptr %retval
182 return: ; preds = %sw.epilog, %sw.bb
183 %0 = load i32, ptr %retval
187 ; CHECK-LABEL: @test7(
188 define i32 @test7(i32 %x) nounwind uwtable ssp {
190 %retval = alloca i32, align 4
191 %x.addr = alloca i32, align 4
192 store i32 %x, ptr %x.addr, align 4
193 %tmp = load i32, ptr %x.addr, align 4
194 %conv = sext i32 %tmp to i64
195 %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
197 ; CHECK-NOT: @llvm.expect
198 switch i64 %expval, label %sw.epilog [
203 sw.bb: ; preds = %entry, %entry
204 %tmp1 = load i32, ptr %x.addr, align 4
205 store i32 %tmp1, ptr %retval
208 sw.epilog: ; preds = %entry
209 store i32 0, ptr %retval
212 return: ; preds = %sw.epilog, %sw.bb
213 %0 = load i32, ptr %retval
217 ; CHECK-LABEL: @test8(
218 define i32 @test8(i32 %x) nounwind uwtable ssp {
220 %retval = alloca i32, align 4
221 %x.addr = alloca i32, align 4
222 store i32 %x, ptr %x.addr, align 4
223 %tmp = load i32, ptr %x.addr, align 4
224 %cmp = icmp sgt i32 %tmp, 1
225 %conv = zext i1 %cmp to i32
226 %expval = call i32 @llvm.expect.i32(i32 %conv, i32 1)
227 %tobool = icmp ne i32 %expval, 0
229 ; CHECK-NOT: @llvm.expect
230 br i1 %tobool, label %if.then, label %if.end
232 if.then: ; preds = %entry
233 %call = call i32 (...) @f()
234 store i32 %call, ptr %retval
237 if.end: ; preds = %entry
238 store i32 1, ptr %retval
241 return: ; preds = %if.end, %if.then
242 %0 = load i32, ptr %retval
246 declare i32 @llvm.expect.i32(i32, i32) nounwind readnone
248 ; CHECK-LABEL: @test9(
249 define i32 @test9(i32 %x) nounwind uwtable ssp {
251 %retval = alloca i32, align 4
252 %x.addr = alloca i32, align 4
253 store i32 %x, ptr %x.addr, align 4
254 %tmp = load i32, ptr %x.addr, align 4
255 %cmp = icmp sgt i32 %tmp, 1
256 %expval = call i1 @llvm.expect.i1(i1 %cmp, i1 1)
258 ; CHECK-NOT: @llvm.expect
259 br i1 %expval, label %if.then, label %if.end
261 if.then: ; preds = %entry
262 %call = call i32 (...) @f()
263 store i32 %call, ptr %retval
266 if.end: ; preds = %entry
267 store i32 1, ptr %retval
270 return: ; preds = %if.end, %if.then
271 %0 = load i32, ptr %retval
275 ; CHECK-LABEL: @test10(
276 define i32 @test10(i64 %t6) {
277 %t7 = call i64 @llvm.expect.i64(i64 %t6, i64 0)
278 %t8 = icmp ne i64 %t7, 0
279 %t9 = select i1 %t8, i32 1, i32 2
280 ; CHECK: select{{.*}}, !prof !1
285 declare i1 @llvm.expect.i1(i1, i1) nounwind readnone
287 ; CHECK: !0 = !{!"branch_weights", i32 2000, i32 1}
288 ; CHECK: !1 = !{!"branch_weights", i32 1, i32 2000}
289 ; CHECK: !2 = !{!"branch_weights", i32 1, i32 1, i32 2000}
290 ; CHECK: !3 = !{!"branch_weights", i32 2000, i32 1, i32 1}