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)
8 define i1 @select_v_ne_fail(i8 %v, i8 %C, i8 %y) {
9 ; CHECK-LABEL: @select_v_ne_fail(
10 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
11 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
12 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[V:%.*]], [[C:%.*]]
13 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
14 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
15 ; CHECK-NEXT: ret i1 [[R]]
17 %ynz = icmp ne i8 %y, 0
18 call void @llvm.assume(i1 %ynz)
19 %cmp = icmp ne i8 %v, %C
20 %s = select i1 %cmp, i8 %v, i8 %y
25 define i1 @select_v_eq_nz(i8 %v, i8 %C, i8 %y) {
26 ; CHECK-LABEL: @select_v_eq_nz(
27 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
28 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
29 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp ne i8 [[C:%.*]], 0
30 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
31 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[C]], [[V:%.*]]
32 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
33 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
34 ; CHECK-NEXT: ret i1 [[R]]
36 %ynz = icmp ne i8 %y, 0
37 call void @llvm.assume(i1 %ynz)
38 %pcond0 = icmp ne i8 %C, 0
39 call void @llvm.assume(i1 %pcond0)
40 %cmp = icmp eq i8 %C, %v
41 %s = select i1 %cmp, i8 %v, i8 %y
46 define i1 @inv_select_v_ugt_nz(i8 %v, i8 %C, i8 %y) {
47 ; CHECK-LABEL: @inv_select_v_ugt_nz(
48 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
49 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
50 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp ne i8 [[C:%.*]], 0
51 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
52 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[C]], [[V:%.*]]
53 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[V]]
54 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
55 ; CHECK-NEXT: ret i1 [[R]]
57 %ynz = icmp ne i8 %y, 0
58 call void @llvm.assume(i1 %ynz)
59 %pcond0 = icmp ne i8 %C, 0
60 call void @llvm.assume(i1 %pcond0)
61 %cmp = icmp ugt i8 %C, %v
62 %s = select i1 %cmp, i8 %y, i8 %v
67 define i1 @inv_select_v_ugt_fail(i8 %v, i8 %C, i8 %y) {
68 ; CHECK-LABEL: @inv_select_v_ugt_fail(
69 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
70 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
71 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], -8
72 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
73 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[C]], [[V:%.*]]
74 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[V]]
75 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
76 ; CHECK-NEXT: ret i1 [[R]]
78 %ynz = icmp ne i8 %y, 0
79 call void @llvm.assume(i1 %ynz)
80 %pcond0 = icmp sge i8 %C, -8
81 call void @llvm.assume(i1 %pcond0)
82 %cmp = icmp ugt i8 %C, %v
83 %s = select i1 %cmp, i8 %y, i8 %v
88 define i1 @select_v_uge_nz(i8 %v, i8 %C, i8 %y) {
89 ; CHECK-LABEL: @select_v_uge_nz(
90 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
91 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
92 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp ne i8 [[C:%.*]], 0
93 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
94 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i8 [[V:%.*]], [[C]]
95 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
96 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
97 ; CHECK-NEXT: ret i1 [[R]]
99 %ynz = icmp ne i8 %y, 0
100 call void @llvm.assume(i1 %ynz)
101 %pcond0 = icmp ne i8 %C, 0
102 call void @llvm.assume(i1 %pcond0)
103 %cmp = icmp uge i8 %v, %C
104 %s = select i1 %cmp, i8 %v, i8 %y
105 %r = icmp eq i8 %s, 0
109 define i1 @select_v_sgt_nonneg(i8 %v, i8 %C, i8 %y) {
110 ; CHECK-LABEL: @select_v_sgt_nonneg(
111 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
112 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
113 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], 0
114 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
115 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[V:%.*]], [[C]]
116 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
117 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
118 ; CHECK-NEXT: ret i1 [[R]]
120 %ynz = icmp ne i8 %y, 0
121 call void @llvm.assume(i1 %ynz)
122 %pcond0 = icmp sge i8 %C, 0
123 call void @llvm.assume(i1 %pcond0)
124 %cmp = icmp sgt i8 %v, %C
125 %s = select i1 %cmp, i8 %v, i8 %y
126 %r = icmp eq i8 %s, 0
130 define i1 @select_v_sgt_fail(i8 %v, i8 %C, i8 %y) {
131 ; CHECK-LABEL: @select_v_sgt_fail(
132 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
133 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
134 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], -4
135 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
136 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[V:%.*]], [[C]]
137 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
138 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
139 ; CHECK-NEXT: ret i1 [[R]]
141 %ynz = icmp ne i8 %y, 0
142 call void @llvm.assume(i1 %ynz)
143 %pcond0 = icmp sge i8 %C, -4
144 call void @llvm.assume(i1 %pcond0)
145 %cmp = icmp sgt i8 %v, %C
146 %s = select i1 %cmp, i8 %v, i8 %y
147 %r = icmp eq i8 %s, 0
151 define i1 @inv_select_v_sgt_neg(i8 %v, i8 %C, i8 %y) {
152 ; CHECK-LABEL: @inv_select_v_sgt_neg(
153 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
154 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
155 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp slt i8 [[C:%.*]], 0
156 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
157 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[V:%.*]], [[C]]
158 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[V]]
159 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
160 ; CHECK-NEXT: ret i1 [[R]]
162 %ynz = icmp ne i8 %y, 0
163 call void @llvm.assume(i1 %ynz)
164 %pcond0 = icmp slt i8 %C, 0
165 call void @llvm.assume(i1 %pcond0)
166 %cmp = icmp sgt i8 %v, %C
167 %s = select i1 %cmp, i8 %y, i8 %v
168 %r = icmp eq i8 %s, 0
172 define i1 @inv_select_v_sgt_nonneg_nz(i8 %v, i8 %C, i8 %y) {
173 ; CHECK-LABEL: @inv_select_v_sgt_nonneg_nz(
174 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
175 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
176 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sgt i8 [[C:%.*]], 0
177 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
178 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[C]], [[V:%.*]]
179 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[V]]
180 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
181 ; CHECK-NEXT: ret i1 [[R]]
183 %ynz = icmp ne i8 %y, 0
184 call void @llvm.assume(i1 %ynz)
185 %pcond0 = icmp sgt i8 %C, 0
186 call void @llvm.assume(i1 %pcond0)
187 %cmp = icmp sgt i8 %C, %v
188 %s = select i1 %cmp, i8 %y, i8 %v
189 %r = icmp eq i8 %s, 0
193 define i1 @select_v_slt_nonneg(i8 %v, i8 %C, i8 %y) {
194 ; CHECK-LABEL: @select_v_slt_nonneg(
195 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
196 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
197 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], 0
198 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
199 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[C]], [[V:%.*]]
200 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
201 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
202 ; CHECK-NEXT: ret i1 [[R]]
204 %ynz = icmp ne i8 %y, 0
205 call void @llvm.assume(i1 %ynz)
206 %pcond0 = icmp sge i8 %C, 0
207 call void @llvm.assume(i1 %pcond0)
208 %cmp = icmp slt i8 %C, %v
209 %s = select i1 %cmp, i8 %v, i8 %y
210 %r = icmp eq i8 %s, 0
214 define i1 @select_v_slt_nonneg_fail(i8 %v, i8 %C, i8 %y) {
215 ; CHECK-LABEL: @select_v_slt_nonneg_fail(
216 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
217 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
218 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], -1
219 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
220 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[C]], [[V:%.*]]
221 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
222 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
223 ; CHECK-NEXT: ret i1 [[R]]
225 %ynz = icmp ne i8 %y, 0
226 call void @llvm.assume(i1 %ynz)
227 %pcond0 = icmp sge i8 %C, -1
228 call void @llvm.assume(i1 %pcond0)
229 %cmp = icmp slt i8 %C, %v
230 %s = select i1 %cmp, i8 %v, i8 %y
231 %r = icmp eq i8 %s, 0
235 define i1 @select_v_slt_neg(i8 %v, i8 %C, i8 %y) {
236 ; CHECK-LABEL: @select_v_slt_neg(
237 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
238 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
239 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp slt i8 [[C:%.*]], 0
240 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
241 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[V:%.*]], [[C]]
242 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
243 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
244 ; CHECK-NEXT: ret i1 [[R]]
246 %ynz = icmp ne i8 %y, 0
247 call void @llvm.assume(i1 %ynz)
248 %pcond0 = icmp slt i8 %C, 0
249 call void @llvm.assume(i1 %pcond0)
250 %cmp = icmp slt i8 %v, %C
251 %s = select i1 %cmp, i8 %v, i8 %y
252 %r = icmp eq i8 %s, 0
256 define i1 @select_v_sge_nonneg_nz(i8 %v, i8 %C, i8 %y) {
257 ; CHECK-LABEL: @select_v_sge_nonneg_nz(
258 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
259 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
260 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sgt i8 [[C:%.*]], 0
261 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
262 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[V:%.*]], [[C]]
263 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
264 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
265 ; CHECK-NEXT: ret i1 [[R]]
267 %ynz = icmp ne i8 %y, 0
268 call void @llvm.assume(i1 %ynz)
269 %pcond0 = icmp sgt i8 %C, 0
270 call void @llvm.assume(i1 %pcond0)
271 %cmp = icmp sge i8 %v, %C
272 %s = select i1 %cmp, i8 %v, i8 %y
273 %r = icmp eq i8 %s, 0
277 define i1 @select_v_sge_neg(i8 %v, i8 %C, i8 %y) {
278 ; CHECK-LABEL: @select_v_sge_neg(
279 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
280 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
281 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp slt i8 [[C:%.*]], 0
282 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
283 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[C]], [[V:%.*]]
284 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
285 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
286 ; CHECK-NEXT: ret i1 [[R]]
288 %ynz = icmp ne i8 %y, 0
289 call void @llvm.assume(i1 %ynz)
290 %pcond0 = icmp slt i8 %C, 0
291 call void @llvm.assume(i1 %pcond0)
292 %cmp = icmp sge i8 %C, %v
293 %s = select i1 %cmp, i8 %v, i8 %y
294 %r = icmp eq i8 %s, 0
298 define i1 @inv_select_v_sge_fail(i8 %v, i8 %C, i8 %y) {
299 ; CHECK-LABEL: @inv_select_v_sge_fail(
300 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
301 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
302 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[V:%.*]], [[C:%.*]]
303 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[V]]
304 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
305 ; CHECK-NEXT: ret i1 [[R]]
307 %ynz = icmp ne i8 %y, 0
308 call void @llvm.assume(i1 %ynz)
309 %cmp = icmp sge i8 %v, %C
310 %s = select i1 %cmp, i8 %y, i8 %v
311 %r = icmp eq i8 %s, 0
315 define i1 @select_v_sle_neg(i8 %v, i8 %C, i8 %y) {
316 ; CHECK-LABEL: @select_v_sle_neg(
317 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
318 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
319 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp slt i8 [[C:%.*]], 0
320 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
321 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[V:%.*]], [[C]]
322 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
323 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
324 ; CHECK-NEXT: ret i1 [[R]]
326 %ynz = icmp ne i8 %y, 0
327 call void @llvm.assume(i1 %ynz)
328 %pcond0 = icmp slt i8 %C, 0
329 call void @llvm.assume(i1 %pcond0)
330 %cmp = icmp sle i8 %v, %C
331 %s = select i1 %cmp, i8 %v, i8 %y
332 %r = icmp eq i8 %s, 0
336 define i1 @select_v_sle_nonneg_nz(i8 %v, i8 %C, i8 %y) {
337 ; CHECK-LABEL: @select_v_sle_nonneg_nz(
338 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
339 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
340 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sgt i8 [[C:%.*]], 0
341 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
342 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[C]], [[V:%.*]]
343 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
344 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
345 ; CHECK-NEXT: ret i1 [[R]]
347 %ynz = icmp ne i8 %y, 0
348 call void @llvm.assume(i1 %ynz)
349 %pcond0 = icmp sgt i8 %C, 0
350 call void @llvm.assume(i1 %pcond0)
351 %cmp = icmp sle i8 %C, %v
352 %s = select i1 %cmp, i8 %v, i8 %y
353 %r = icmp eq i8 %s, 0
357 define i1 @select_v_sle_fail(i8 %v, i8 %C, i8 %y) {
358 ; CHECK-LABEL: @select_v_sle_fail(
359 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
360 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
361 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], 0
362 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
363 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[C]], [[V:%.*]]
364 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
365 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
366 ; CHECK-NEXT: ret i1 [[R]]
368 %ynz = icmp ne i8 %y, 0
369 call void @llvm.assume(i1 %ynz)
370 %pcond0 = icmp sge i8 %C, 0
371 call void @llvm.assume(i1 %pcond0)
372 %cmp = icmp sle i8 %C, %v
373 %s = select i1 %cmp, i8 %v, i8 %y
374 %r = icmp eq i8 %s, 0
378 define i1 @inv_select_v_sle_nonneg(i8 %v, i8 %C, i8 %y) {
379 ; CHECK-LABEL: @inv_select_v_sle_nonneg(
380 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
381 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
382 ; CHECK-NEXT: [[PCOND0:%.*]] = icmp sge i8 [[C:%.*]], 0
383 ; CHECK-NEXT: call void @llvm.assume(i1 [[PCOND0]])
384 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[V:%.*]], [[C]]
385 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[V]]
386 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
387 ; CHECK-NEXT: ret i1 [[R]]
389 %ynz = icmp ne i8 %y, 0
390 call void @llvm.assume(i1 %ynz)
391 %pcond0 = icmp sge i8 %C, 0
392 call void @llvm.assume(i1 %pcond0)
393 %cmp = icmp sle i8 %v, %C
394 %s = select i1 %cmp, i8 %y, i8 %v
395 %r = icmp eq i8 %s, 0
399 ; Check udiv/sdiv occuring before icmp.
400 define i64 @incorrect_safe_div_1(i64 %n, i64 %d) {
401 ; CHECK-LABEL: @incorrect_safe_div_1(
402 ; CHECK-NEXT: [[TMP1:%.*]] = udiv i64 [[N:%.*]], [[D:%.*]]
403 ; CHECK-NEXT: ret i64 [[TMP1]]
406 %2 = icmp eq i64 %d, 0
407 %3 = select i1 %2, i64 -1, i64 %1
411 ; Check icmp occuring before udiv/sdiv.
412 define i64 @incorrect_safe_div_2(i64 %n, i64 %d) {
413 ; CHECK-LABEL: @incorrect_safe_div_2(
414 ; CHECK-NEXT: [[TMP1:%.*]] = sdiv i64 [[N:%.*]], [[D:%.*]]
415 ; CHECK-NEXT: ret i64 [[TMP1]]
417 %1 = icmp eq i64 %d, 0
419 %3 = select i1 %1, i64 -1, i64 %2
423 define i64 @incorrect_safe_div_call_1(i64 %n, i64 %d) {
424 ; CHECK-LABEL: @incorrect_safe_div_call_1(
425 ; CHECK-NEXT: [[TMP1:%.*]] = sdiv i64 [[N:%.*]], [[D:%.*]]
426 ; CHECK-NEXT: tail call void @use(i64 [[D]])
427 ; CHECK-NEXT: ret i64 [[TMP1]]
430 tail call void @use(i64 %d)
431 %2 = icmp eq i64 %d, 0
432 %3 = select i1 %2, i64 -1, i64 %1
436 define i64 @incorrect_safe_div_call_2(i64 %n, i64 %d) {
437 ; CHECK-LABEL: @incorrect_safe_div_call_2(
438 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[D:%.*]], 0
439 ; CHECK-NEXT: tail call void @use(i64 [[D]])
440 ; CHECK-NEXT: [[TMP2:%.*]] = udiv i64 [[N:%.*]], [[D]]
441 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP1]], i64 -1, i64 [[TMP2]]
442 ; CHECK-NEXT: ret i64 [[TMP3]]
444 %1 = icmp eq i64 %d, 0
445 tail call void @use(i64 %d)
447 %3 = select i1 %1, i64 -1, i64 %2
451 ; https://alive2.llvm.org/ce/z/Si_B7b
452 define i4 @icmp_urem(i4 %n, i4 %d) {
453 ; CHECK-LABEL: @icmp_urem(
454 ; CHECK-NEXT: [[TMP1:%.*]] = urem i4 [[N:%.*]], [[D:%.*]]
455 ; CHECK-NEXT: ret i4 [[TMP1]]
457 %1 = icmp eq i4 %d, 0
459 %3 = select i1 %1, i4 -1, i4 %2
463 define i4 @icmp_urem_clobber_by_call(i4 %n, i4 %d) {
464 ; CHECK-LABEL: @icmp_urem_clobber_by_call(
465 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i4 [[D:%.*]], 0
466 ; CHECK-NEXT: tail call void @use4(i4 [[D]])
467 ; CHECK-NEXT: [[TMP2:%.*]] = urem i4 [[N:%.*]], [[D]]
468 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP1]], i4 -1, i4 [[TMP2]]
469 ; CHECK-NEXT: ret i4 [[TMP3]]
471 %1 = icmp eq i4 %d, 0
472 tail call void @use4(i4 %d)
474 %3 = select i1 %1, i4 -1, i4 %2
478 ; https://alive2.llvm.org/ce/z/Fn3Wac
479 define i4 @icmp_srem(i4 %n, i4 %d) {
480 ; CHECK-LABEL: @icmp_srem(
481 ; CHECK-NEXT: [[TMP1:%.*]] = srem i4 [[N:%.*]], [[D:%.*]]
482 ; CHECK-NEXT: ret i4 [[TMP1]]
484 %1 = icmp eq i4 %d, 0
486 %3 = select i1 %1, i4 -1, i4 %2
490 define i4 @icmp_srem_clobber_by_call(i4 %n, i4 %d) {
491 ; CHECK-LABEL: @icmp_srem_clobber_by_call(
492 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i4 [[D:%.*]], 0
493 ; CHECK-NEXT: tail call void @use4(i4 [[D]])
494 ; CHECK-NEXT: [[TMP2:%.*]] = srem i4 [[N:%.*]], [[D]]
495 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP1]], i4 -1, i4 [[TMP2]]
496 ; CHECK-NEXT: ret i4 [[TMP3]]
498 %1 = icmp eq i4 %d, 0
499 tail call void @use4(i4 %d)
501 %3 = select i1 %1, i4 -1, i4 %2