1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4 declare void @llvm.assume(i1)
6 define i1 @select_v_ne_fail(i8 %v, i8 %C, i8 %y) {
7 ; CHECK-LABEL: @select_v_ne_fail(
8 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
9 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
10 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[V:%.*]], [[C:%.*]]
11 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
12 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
13 ; CHECK-NEXT: ret i1 [[R]]
15 %ynz = icmp ne i8 %y, 0
16 call void @llvm.assume(i1 %ynz)
17 %cmp = icmp ne i8 %v, %C
18 %s = select i1 %cmp, i8 %v, i8 %y
23 define i1 @select_v_eq_nz(i8 %v, i8 %C, i8 %y) {
24 ; CHECK-LABEL: @select_v_eq_nz(
25 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
26 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
27 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp ne i8 [[C:%.*]], 0
28 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
29 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[C]], [[V:%.*]]
30 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
31 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
32 ; CHECK-NEXT: ret i1 [[R]]
34 %ynz = icmp ne i8 %y, 0
35 call void @llvm.assume(i1 %ynz)
36 %pcond0 = icmp ne i8 %C, 0
37 call void @llvm.assume(i1 %pcond0)
38 %cmp = icmp eq i8 %C, %v
39 %s = select i1 %cmp, i8 %v, i8 %y
44 define i1 @inv_select_v_ugt_nz(i8 %v, i8 %C, i8 %y) {
45 ; CHECK-LABEL: @inv_select_v_ugt_nz(
46 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
47 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
48 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp ne i8 [[C:%.*]], 0
49 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
50 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[C]], [[V:%.*]]
51 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[V]]
52 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
53 ; CHECK-NEXT: ret i1 [[R]]
55 %ynz = icmp ne i8 %y, 0
56 call void @llvm.assume(i1 %ynz)
57 %pcond0 = icmp ne i8 %C, 0
58 call void @llvm.assume(i1 %pcond0)
59 %cmp = icmp ugt i8 %C, %v
60 %s = select i1 %cmp, i8 %y, i8 %v
65 define i1 @inv_select_v_ugt_fail(i8 %v, i8 %C, i8 %y) {
66 ; CHECK-LABEL: @inv_select_v_ugt_fail(
67 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
68 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
69 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], -8
70 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
71 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[C]], [[V:%.*]]
72 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[V]]
73 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
74 ; CHECK-NEXT: ret i1 [[R]]
76 %ynz = icmp ne i8 %y, 0
77 call void @llvm.assume(i1 %ynz)
78 %pcond0 = icmp sge i8 %C, -8
79 call void @llvm.assume(i1 %pcond0)
80 %cmp = icmp ugt i8 %C, %v
81 %s = select i1 %cmp, i8 %y, i8 %v
86 define i1 @select_v_uge_nz(i8 %v, i8 %C, i8 %y) {
87 ; CHECK-LABEL: @select_v_uge_nz(
88 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
89 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
90 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp ne i8 [[C:%.*]], 0
91 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
92 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i8 [[V:%.*]], [[C]]
93 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
94 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
95 ; CHECK-NEXT: ret i1 [[R]]
97 %ynz = icmp ne i8 %y, 0
98 call void @llvm.assume(i1 %ynz)
99 %pcond0 = icmp ne i8 %C, 0
100 call void @llvm.assume(i1 %pcond0)
101 %cmp = icmp uge i8 %v, %C
102 %s = select i1 %cmp, i8 %v, i8 %y
103 %r = icmp eq i8 %s, 0
107 define i1 @select_v_sgt_nonneg(i8 %v, i8 %C, i8 %y) {
108 ; CHECK-LABEL: @select_v_sgt_nonneg(
109 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
110 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
111 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], 0
112 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
113 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[V:%.*]], [[C]]
114 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
115 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
116 ; CHECK-NEXT: ret i1 [[R]]
118 %ynz = icmp ne i8 %y, 0
119 call void @llvm.assume(i1 %ynz)
120 %pcond0 = icmp sge i8 %C, 0
121 call void @llvm.assume(i1 %pcond0)
122 %cmp = icmp sgt i8 %v, %C
123 %s = select i1 %cmp, i8 %v, i8 %y
124 %r = icmp eq i8 %s, 0
128 define i1 @select_v_sgt_fail(i8 %v, i8 %C, i8 %y) {
129 ; CHECK-LABEL: @select_v_sgt_fail(
130 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
131 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
132 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], -4
133 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
134 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[V:%.*]], [[C]]
135 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
136 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
137 ; CHECK-NEXT: ret i1 [[R]]
139 %ynz = icmp ne i8 %y, 0
140 call void @llvm.assume(i1 %ynz)
141 %pcond0 = icmp sge i8 %C, -4
142 call void @llvm.assume(i1 %pcond0)
143 %cmp = icmp sgt i8 %v, %C
144 %s = select i1 %cmp, i8 %v, i8 %y
145 %r = icmp eq i8 %s, 0
149 define i1 @inv_select_v_sgt_neg(i8 %v, i8 %C, i8 %y) {
150 ; CHECK-LABEL: @inv_select_v_sgt_neg(
151 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
152 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
153 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp slt i8 [[C:%.*]], 0
154 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
155 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[V:%.*]], [[C]]
156 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[V]]
157 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
158 ; CHECK-NEXT: ret i1 [[R]]
160 %ynz = icmp ne i8 %y, 0
161 call void @llvm.assume(i1 %ynz)
162 %pcond0 = icmp slt i8 %C, 0
163 call void @llvm.assume(i1 %pcond0)
164 %cmp = icmp sgt i8 %v, %C
165 %s = select i1 %cmp, i8 %y, i8 %v
166 %r = icmp eq i8 %s, 0
170 define i1 @inv_select_v_sgt_nonneg_nz(i8 %v, i8 %C, i8 %y) {
171 ; CHECK-LABEL: @inv_select_v_sgt_nonneg_nz(
172 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
173 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
174 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sgt i8 [[C:%.*]], 0
175 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
176 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[C]], [[V:%.*]]
177 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[V]]
178 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
179 ; CHECK-NEXT: ret i1 [[R]]
181 %ynz = icmp ne i8 %y, 0
182 call void @llvm.assume(i1 %ynz)
183 %pcond0 = icmp sgt i8 %C, 0
184 call void @llvm.assume(i1 %pcond0)
185 %cmp = icmp sgt i8 %C, %v
186 %s = select i1 %cmp, i8 %y, i8 %v
187 %r = icmp eq i8 %s, 0
191 define i1 @select_v_slt_nonneg(i8 %v, i8 %C, i8 %y) {
192 ; CHECK-LABEL: @select_v_slt_nonneg(
193 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
194 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
195 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], 0
196 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
197 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[C]], [[V:%.*]]
198 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
199 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
200 ; CHECK-NEXT: ret i1 [[R]]
202 %ynz = icmp ne i8 %y, 0
203 call void @llvm.assume(i1 %ynz)
204 %pcond0 = icmp sge i8 %C, 0
205 call void @llvm.assume(i1 %pcond0)
206 %cmp = icmp slt i8 %C, %v
207 %s = select i1 %cmp, i8 %v, i8 %y
208 %r = icmp eq i8 %s, 0
212 define i1 @select_v_slt_nonneg_fail(i8 %v, i8 %C, i8 %y) {
213 ; CHECK-LABEL: @select_v_slt_nonneg_fail(
214 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
215 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
216 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], -1
217 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
218 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[C]], [[V:%.*]]
219 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
220 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
221 ; CHECK-NEXT: ret i1 [[R]]
223 %ynz = icmp ne i8 %y, 0
224 call void @llvm.assume(i1 %ynz)
225 %pcond0 = icmp sge i8 %C, -1
226 call void @llvm.assume(i1 %pcond0)
227 %cmp = icmp slt i8 %C, %v
228 %s = select i1 %cmp, i8 %v, i8 %y
229 %r = icmp eq i8 %s, 0
233 define i1 @select_v_slt_neg(i8 %v, i8 %C, i8 %y) {
234 ; CHECK-LABEL: @select_v_slt_neg(
235 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
236 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
237 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp slt i8 [[C:%.*]], 0
238 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
239 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[V:%.*]], [[C]]
240 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
241 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
242 ; CHECK-NEXT: ret i1 [[R]]
244 %ynz = icmp ne i8 %y, 0
245 call void @llvm.assume(i1 %ynz)
246 %pcond0 = icmp slt i8 %C, 0
247 call void @llvm.assume(i1 %pcond0)
248 %cmp = icmp slt i8 %v, %C
249 %s = select i1 %cmp, i8 %v, i8 %y
250 %r = icmp eq i8 %s, 0
254 define i1 @select_v_sge_nonneg_nz(i8 %v, i8 %C, i8 %y) {
255 ; CHECK-LABEL: @select_v_sge_nonneg_nz(
256 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
257 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
258 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sgt i8 [[C:%.*]], 0
259 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
260 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[V:%.*]], [[C]]
261 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
262 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
263 ; CHECK-NEXT: ret i1 [[R]]
265 %ynz = icmp ne i8 %y, 0
266 call void @llvm.assume(i1 %ynz)
267 %pcond0 = icmp sgt i8 %C, 0
268 call void @llvm.assume(i1 %pcond0)
269 %cmp = icmp sge i8 %v, %C
270 %s = select i1 %cmp, i8 %v, i8 %y
271 %r = icmp eq i8 %s, 0
275 define i1 @select_v_sge_neg(i8 %v, i8 %C, i8 %y) {
276 ; CHECK-LABEL: @select_v_sge_neg(
277 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
278 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
279 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp slt i8 [[C:%.*]], 0
280 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
281 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[C]], [[V:%.*]]
282 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
283 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
284 ; CHECK-NEXT: ret i1 [[R]]
286 %ynz = icmp ne i8 %y, 0
287 call void @llvm.assume(i1 %ynz)
288 %pcond0 = icmp slt i8 %C, 0
289 call void @llvm.assume(i1 %pcond0)
290 %cmp = icmp sge i8 %C, %v
291 %s = select i1 %cmp, i8 %v, i8 %y
292 %r = icmp eq i8 %s, 0
296 define i1 @inv_select_v_sge_fail(i8 %v, i8 %C, i8 %y) {
297 ; CHECK-LABEL: @inv_select_v_sge_fail(
298 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
299 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
300 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[V:%.*]], [[C:%.*]]
301 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[V]]
302 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
303 ; CHECK-NEXT: ret i1 [[R]]
305 %ynz = icmp ne i8 %y, 0
306 call void @llvm.assume(i1 %ynz)
307 %cmp = icmp sge i8 %v, %C
308 %s = select i1 %cmp, i8 %y, i8 %v
309 %r = icmp eq i8 %s, 0
313 define i1 @select_v_sle_neg(i8 %v, i8 %C, i8 %y) {
314 ; CHECK-LABEL: @select_v_sle_neg(
315 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
316 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
317 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp slt i8 [[C:%.*]], 0
318 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
319 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[V:%.*]], [[C]]
320 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
321 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
322 ; CHECK-NEXT: ret i1 [[R]]
324 %ynz = icmp ne i8 %y, 0
325 call void @llvm.assume(i1 %ynz)
326 %pcond0 = icmp slt i8 %C, 0
327 call void @llvm.assume(i1 %pcond0)
328 %cmp = icmp sle i8 %v, %C
329 %s = select i1 %cmp, i8 %v, i8 %y
330 %r = icmp eq i8 %s, 0
334 define i1 @select_v_sle_nonneg_nz(i8 %v, i8 %C, i8 %y) {
335 ; CHECK-LABEL: @select_v_sle_nonneg_nz(
336 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
337 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
338 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sgt i8 [[C:%.*]], 0
339 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
340 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[C]], [[V:%.*]]
341 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
342 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
343 ; CHECK-NEXT: ret i1 [[R]]
345 %ynz = icmp ne i8 %y, 0
346 call void @llvm.assume(i1 %ynz)
347 %pcond0 = icmp sgt i8 %C, 0
348 call void @llvm.assume(i1 %pcond0)
349 %cmp = icmp sle i8 %C, %v
350 %s = select i1 %cmp, i8 %v, i8 %y
351 %r = icmp eq i8 %s, 0
355 define i1 @select_v_sle_fail(i8 %v, i8 %C, i8 %y) {
356 ; CHECK-LABEL: @select_v_sle_fail(
357 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
358 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
359 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], 0
360 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
361 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[C]], [[V:%.*]]
362 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
363 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
364 ; CHECK-NEXT: ret i1 [[R]]
366 %ynz = icmp ne i8 %y, 0
367 call void @llvm.assume(i1 %ynz)
368 %pcond0 = icmp sge i8 %C, 0
369 call void @llvm.assume(i1 %pcond0)
370 %cmp = icmp sle i8 %C, %v
371 %s = select i1 %cmp, i8 %v, i8 %y
372 %r = icmp eq i8 %s, 0
376 define i1 @inv_select_v_sle_nonneg(i8 %v, i8 %C, i8 %y) {
377 ; CHECK-LABEL: @inv_select_v_sle_nonneg(
378 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
379 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
380 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], 0
381 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
382 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[V:%.*]], [[C]]
383 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[V]]
384 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
385 ; CHECK-NEXT: ret i1 [[R]]
387 %ynz = icmp ne i8 %y, 0
388 call void @llvm.assume(i1 %ynz)
389 %pcond0 = icmp sge i8 %C, 0
390 call void @llvm.assume(i1 %pcond0)
391 %cmp = icmp sle i8 %v, %C
392 %s = select i1 %cmp, i8 %y, i8 %v
393 %r = icmp eq i8 %s, 0
397 ; Check udiv/sdiv occuring before icmp.
398 define i64 @incorrect_safe_div_1(i64 %n, i64 %d) {
399 ; CHECK-LABEL: @incorrect_safe_div_1(
400 ; CHECK-NEXT: [[TMP1:%.*]] = udiv i64 [[N:%.*]], [[D:%.*]]
401 ; CHECK-NEXT: ret i64 [[TMP1]]
404 %2 = icmp eq i64 %d, 0
405 %3 = select i1 %2, i64 -1, i64 %1
409 ; Check icmp occuring before udiv/sdiv.
410 define i64 @incorrect_safe_div_2(i64 %n, i64 %d) {
411 ; CHECK-LABEL: @incorrect_safe_div_2(
412 ; CHECK-NEXT: [[TMP1:%.*]] = sdiv i64 [[N:%.*]], [[D:%.*]]
413 ; CHECK-NEXT: ret i64 [[TMP1]]
415 %1 = icmp eq i64 %d, 0
417 %3 = select i1 %1, i64 -1, i64 %2
421 define i64 @incorrect_safe_div_call_1(i64 %n, i64 %d) {
422 ; CHECK-LABEL: @incorrect_safe_div_call_1(
423 ; CHECK-NEXT: [[TMP1:%.*]] = sdiv i64 [[N:%.*]], [[D:%.*]]
424 ; CHECK-NEXT: tail call void @use(i64 [[D]])
425 ; CHECK-NEXT: ret i64 [[TMP1]]
428 tail call void @use(i64 %d)
429 %2 = icmp eq i64 %d, 0
430 %3 = select i1 %2, i64 -1, i64 %1
434 define i64 @incorrect_safe_div_call_2(i64 %n, i64 %d) {
435 ; CHECK-LABEL: @incorrect_safe_div_call_2(
436 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[D:%.*]], 0
437 ; CHECK-NEXT: tail call void @use(i64 [[D]])
438 ; CHECK-NEXT: [[TMP2:%.*]] = udiv i64 [[N:%.*]], [[D]]
439 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP1]], i64 -1, i64 [[TMP2]]
440 ; CHECK-NEXT: ret i64 [[TMP3]]
442 %1 = icmp eq i64 %d, 0
443 tail call void @use(i64 %d)
445 %3 = select i1 %1, i64 -1, i64 %2
449 declare void @use(i64)