1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=correlated-propagation -S | FileCheck %s
4 define void @test_nop(i32 %n) {
5 ; CHECK-LABEL: @test_nop(
6 ; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[N:%.*]], 100
9 %div = udiv i32 %n, 100
13 define void @test1(i32 %n) {
14 ; CHECK-LABEL: @test1(
16 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule i32 [[N:%.*]], 65535
17 ; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
19 ; CHECK-NEXT: [[DIV_LHS_TRUNC:%.*]] = trunc i32 [[N]] to i16
20 ; CHECK-NEXT: [[DIV1:%.*]] = urem i16 [[DIV_LHS_TRUNC]], 100
21 ; CHECK-NEXT: [[DIV_ZEXT:%.*]] = zext i16 [[DIV1]] to i32
22 ; CHECK-NEXT: br label [[EXIT]]
24 ; CHECK-NEXT: ret void
26 entry: %cmp = icmp ule i32 %n, 65535
27 br i1 %cmp, label %bb, label %exit
30 %div = urem i32 %n, 100
37 define void @test2(i32 %n) {
38 ; CHECK-LABEL: @test2(
40 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule i32 [[N:%.*]], 65536
41 ; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
43 ; CHECK-NEXT: [[DIV:%.*]] = urem i32 [[N]], 100
44 ; CHECK-NEXT: br label [[EXIT]]
46 ; CHECK-NEXT: ret void
49 %cmp = icmp ule i32 %n, 65536
50 br i1 %cmp, label %bb, label %exit
53 %div = urem i32 %n, 100
60 define void @test3(i32 %m, i32 %n) {
61 ; CHECK-LABEL: @test3(
63 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i32 [[M:%.*]], 65535
64 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 [[N:%.*]], 65535
65 ; CHECK-NEXT: [[CMP:%.*]] = and i1 [[CMP1]], [[CMP2]]
66 ; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
68 ; CHECK-NEXT: [[DIV_LHS_TRUNC:%.*]] = trunc i32 [[M]] to i16
69 ; CHECK-NEXT: [[DIV_RHS_TRUNC:%.*]] = trunc i32 [[N]] to i16
70 ; CHECK-NEXT: [[DIV1:%.*]] = urem i16 [[DIV_LHS_TRUNC]], [[DIV_RHS_TRUNC]]
71 ; CHECK-NEXT: [[DIV_ZEXT:%.*]] = zext i16 [[DIV1]] to i32
72 ; CHECK-NEXT: br label [[EXIT]]
74 ; CHECK-NEXT: ret void
77 %cmp1 = icmp ult i32 %m, 65535
78 %cmp2 = icmp ult i32 %n, 65535
79 %cmp = and i1 %cmp1, %cmp2
80 br i1 %cmp, label %bb, label %exit
83 %div = urem i32 %m, %n
90 define void @test4(i32 %m, i32 %n) {
91 ; CHECK-LABEL: @test4(
93 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i32 [[M:%.*]], 65535
94 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ule i32 [[N:%.*]], 65536
95 ; CHECK-NEXT: [[CMP:%.*]] = and i1 [[CMP1]], [[CMP2]]
96 ; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
98 ; CHECK-NEXT: [[DIV:%.*]] = urem i32 [[M]], [[N]]
99 ; CHECK-NEXT: br label [[EXIT]]
101 ; CHECK-NEXT: ret void
104 %cmp1 = icmp ult i32 %m, 65535
105 %cmp2 = icmp ule i32 %n, 65536
106 %cmp = and i1 %cmp1, %cmp2
107 br i1 %cmp, label %bb, label %exit
110 %div = urem i32 %m, %n
117 define void @test5(i32 %n) {
118 ; CHECK-LABEL: @test5(
119 ; CHECK-NEXT: [[TRUNC:%.*]] = and i32 [[N:%.*]], 63
120 ; CHECK-NEXT: [[TRUNC_FROZEN:%.*]] = freeze i32 [[TRUNC]]
121 ; CHECK-NEXT: [[DIV_UREM:%.*]] = sub nuw i32 [[TRUNC_FROZEN]], 42
122 ; CHECK-NEXT: [[DIV_CMP:%.*]] = icmp ult i32 [[TRUNC_FROZEN]], 42
123 ; CHECK-NEXT: [[DIV:%.*]] = select i1 [[DIV_CMP]], i32 [[TRUNC_FROZEN]], i32 [[DIV_UREM]]
124 ; CHECK-NEXT: ret void
126 %trunc = and i32 %n, 63
127 %div = urem i32 %trunc, 42
131 define void @test6(i32 %n) {
132 ; CHECK-LABEL: @test6(
134 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule i32 [[N:%.*]], 255
135 ; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
137 ; CHECK-NEXT: [[DIV1_LHS_TRUNC:%.*]] = trunc i32 [[N]] to i8
138 ; CHECK-NEXT: [[DIV12:%.*]] = urem i8 [[DIV1_LHS_TRUNC]], 100
139 ; CHECK-NEXT: [[DIV1_ZEXT:%.*]] = zext i8 [[DIV12]] to i32
140 ; CHECK-NEXT: br label [[EXIT]]
142 ; CHECK-NEXT: ret void
145 %cmp = icmp ule i32 %n, 255
146 br i1 %cmp, label %bb, label %exit
149 %div = srem i32 %n, 100
156 declare void @llvm.assume(i1)
158 define i16 @test7(i16 %x, i16 %y) {
159 ; CHECK-LABEL: @test7(
160 ; CHECK-NEXT: [[ABOVE_RANGE:%.*]] = icmp uge i16 [[Y:%.*]], 13
161 ; CHECK-NEXT: call void @llvm.assume(i1 [[ABOVE_RANGE]])
162 ; CHECK-NEXT: [[BELOW_RANGE:%.*]] = icmp ult i16 [[X:%.*]], 13
163 ; CHECK-NEXT: call void @llvm.assume(i1 [[BELOW_RANGE]])
164 ; CHECK-NEXT: ret i16 [[X]]
166 %above_range = icmp uge i16 %y, 13
167 call void @llvm.assume(i1 %above_range)
169 %below_range = icmp ult i16 %x, 13
170 call void @llvm.assume(i1 %below_range)
176 define void @non_power_of_2(i24 %n) {
177 ; CHECK-LABEL: @non_power_of_2(
178 ; CHECK-NEXT: [[DIV:%.*]] = urem i24 [[N:%.*]], 42
179 ; CHECK-NEXT: ret void
181 %div = urem i24 %n, 42
185 ; (x urem 5) uge 2 implies x uge 2 on the true branch.
186 ; We don't know anything about the lower bound on the false branch.
187 define void @urem_implied_cond_uge(i8 %x, i8 %m) {
188 ; CHECK-LABEL: @urem_implied_cond_uge(
189 ; CHECK-NEXT: [[U:%.*]] = urem i8 [[X:%.*]], [[M:%.*]]
190 ; CHECK-NEXT: [[C1:%.*]] = icmp uge i8 [[U]], 2
191 ; CHECK-NEXT: br i1 [[C1]], label [[IF:%.*]], label [[ELSE:%.*]]
193 ; CHECK-NEXT: call void @use(i1 false)
194 ; CHECK-NEXT: [[C3:%.*]] = icmp ule i8 [[X]], 2
195 ; CHECK-NEXT: call void @use(i1 [[C3]])
196 ; CHECK-NEXT: call void @use(i1 true)
197 ; CHECK-NEXT: [[C5:%.*]] = icmp ugt i8 [[X]], 2
198 ; CHECK-NEXT: call void @use(i1 [[C5]])
199 ; CHECK-NEXT: ret void
201 ; CHECK-NEXT: [[C2_2:%.*]] = icmp ult i8 [[X]], 2
202 ; CHECK-NEXT: call void @use(i1 [[C2_2]])
203 ; CHECK-NEXT: [[C3_2:%.*]] = icmp ule i8 [[X]], 2
204 ; CHECK-NEXT: call void @use(i1 [[C3_2]])
205 ; CHECK-NEXT: [[C4_2:%.*]] = icmp uge i8 [[X]], 2
206 ; CHECK-NEXT: call void @use(i1 [[C4_2]])
207 ; CHECK-NEXT: [[C5_2:%.*]] = icmp ugt i8 [[X]], 2
208 ; CHECK-NEXT: call void @use(i1 [[C5_2]])
209 ; CHECK-NEXT: ret void
212 %c1 = icmp uge i8 %u, 2
213 br i1 %c1, label %if, label %else
216 %c2 = icmp ult i8 %x, 2
217 call void @use(i1 %c2)
218 %c3 = icmp ule i8 %x, 2
219 call void @use(i1 %c3)
220 %c4 = icmp uge i8 %x, 2
221 call void @use(i1 %c4)
222 %c5 = icmp ugt i8 %x, 2
223 call void @use(i1 %c5)
227 %c2.2 = icmp ult i8 %x, 2
228 call void @use(i1 %c2.2)
229 %c3.2 = icmp ule i8 %x, 2
230 call void @use(i1 %c3.2)
231 %c4.2 = icmp uge i8 %x, 2
232 call void @use(i1 %c4.2)
233 %c5.2 = icmp ugt i8 %x, 2
234 call void @use(i1 %c5.2)
238 ; (x urem 5) uge 5 is always false. It ends up being folded first, but if it
239 ; weren't, we should handle that gracefully.
240 define void @urem_implied_cond_uge_out_of_range(i8 %x) {
241 ; CHECK-LABEL: @urem_implied_cond_uge_out_of_range(
242 ; CHECK-NEXT: [[U:%.*]] = urem i8 [[X:%.*]], 5
243 ; CHECK-NEXT: br i1 false, label [[IF:%.*]], label [[ELSE:%.*]]
245 ; CHECK-NEXT: [[C2:%.*]] = icmp ult i8 [[X]], 5
246 ; CHECK-NEXT: call void @use(i1 [[C2]])
247 ; CHECK-NEXT: [[C3:%.*]] = icmp ule i8 [[X]], 5
248 ; CHECK-NEXT: call void @use(i1 [[C3]])
249 ; CHECK-NEXT: [[C4:%.*]] = icmp uge i8 [[X]], 5
250 ; CHECK-NEXT: call void @use(i1 [[C4]])
251 ; CHECK-NEXT: [[C5:%.*]] = icmp ugt i8 [[X]], 5
252 ; CHECK-NEXT: call void @use(i1 [[C5]])
253 ; CHECK-NEXT: ret void
255 ; CHECK-NEXT: [[C2_2:%.*]] = icmp ult i8 [[X]], 5
256 ; CHECK-NEXT: call void @use(i1 [[C2_2]])
257 ; CHECK-NEXT: [[C3_2:%.*]] = icmp ule i8 [[X]], 5
258 ; CHECK-NEXT: call void @use(i1 [[C3_2]])
259 ; CHECK-NEXT: [[C4_2:%.*]] = icmp uge i8 [[X]], 5
260 ; CHECK-NEXT: call void @use(i1 [[C4_2]])
261 ; CHECK-NEXT: [[C5_2:%.*]] = icmp ugt i8 [[X]], 5
262 ; CHECK-NEXT: call void @use(i1 [[C5_2]])
263 ; CHECK-NEXT: ret void
266 %c1 = icmp uge i8 %u, 5
267 br i1 %c1, label %if, label %else
270 %c2 = icmp ult i8 %x, 5
271 call void @use(i1 %c2)
272 %c3 = icmp ule i8 %x, 5
273 call void @use(i1 %c3)
274 %c4 = icmp uge i8 %x, 5
275 call void @use(i1 %c4)
276 %c5 = icmp ugt i8 %x, 5
277 call void @use(i1 %c5)
281 %c2.2 = icmp ult i8 %x, 5
282 call void @use(i1 %c2.2)
283 %c3.2 = icmp ule i8 %x, 5
284 call void @use(i1 %c3.2)
285 %c4.2 = icmp uge i8 %x, 5
286 call void @use(i1 %c4.2)
287 %c5.2 = icmp ugt i8 %x, 5
288 call void @use(i1 %c5.2)
292 ; (x urem 5) != 0 is the same as (x urem 5) >= 1 and implies x >= 1.
293 define void @urem_implied_cond_ne_zero(i8 %x, i8 %m) {
294 ; CHECK-LABEL: @urem_implied_cond_ne_zero(
295 ; CHECK-NEXT: [[U:%.*]] = urem i8 [[X:%.*]], [[M:%.*]]
296 ; CHECK-NEXT: [[C1:%.*]] = icmp ne i8 [[U]], 0
297 ; CHECK-NEXT: br i1 [[C1]], label [[IF:%.*]], label [[ELSE:%.*]]
299 ; CHECK-NEXT: call void @use(i1 false)
300 ; CHECK-NEXT: [[C3:%.*]] = icmp ule i8 [[X]], 1
301 ; CHECK-NEXT: call void @use(i1 [[C3]])
302 ; CHECK-NEXT: call void @use(i1 true)
303 ; CHECK-NEXT: [[C5:%.*]] = icmp ugt i8 [[X]], 1
304 ; CHECK-NEXT: call void @use(i1 [[C5]])
305 ; CHECK-NEXT: ret void
307 ; CHECK-NEXT: [[C2_2:%.*]] = icmp ult i8 [[X]], 1
308 ; CHECK-NEXT: call void @use(i1 [[C2_2]])
309 ; CHECK-NEXT: [[C3_2:%.*]] = icmp ule i8 [[X]], 1
310 ; CHECK-NEXT: call void @use(i1 [[C3_2]])
311 ; CHECK-NEXT: [[C4_2:%.*]] = icmp uge i8 [[X]], 1
312 ; CHECK-NEXT: call void @use(i1 [[C4_2]])
313 ; CHECK-NEXT: [[C5_2:%.*]] = icmp ugt i8 [[X]], 1
314 ; CHECK-NEXT: call void @use(i1 [[C5_2]])
315 ; CHECK-NEXT: ret void
318 %c1 = icmp ne i8 %u, 0
319 br i1 %c1, label %if, label %else
322 %c2 = icmp ult i8 %x, 1
323 call void @use(i1 %c2)
324 %c3 = icmp ule i8 %x, 1
325 call void @use(i1 %c3)
326 %c4 = icmp uge i8 %x, 1
327 call void @use(i1 %c4)
328 %c5 = icmp ugt i8 %x, 1
329 call void @use(i1 %c5)
333 %c2.2 = icmp ult i8 %x, 1
334 call void @use(i1 %c2.2)
335 %c3.2 = icmp ule i8 %x, 1
336 call void @use(i1 %c3.2)
337 %c4.2 = icmp uge i8 %x, 1
338 call void @use(i1 %c4.2)
339 %c5.2 = icmp ugt i8 %x, 1
340 call void @use(i1 %c5.2)
344 ; (x urem 5) != 1 doesn't imply anything on the true branch. However, on the
345 ; false branch (x urem 5) == 1 implies x >= 1.
346 define void @urem_implied_cond_ne_non_zero(i8 %x, i8 %m) {
347 ; CHECK-LABEL: @urem_implied_cond_ne_non_zero(
348 ; CHECK-NEXT: [[U:%.*]] = urem i8 [[X:%.*]], [[M:%.*]]
349 ; CHECK-NEXT: [[C1:%.*]] = icmp ne i8 [[U]], 1
350 ; CHECK-NEXT: br i1 [[C1]], label [[IF:%.*]], label [[ELSE:%.*]]
352 ; CHECK-NEXT: [[C2:%.*]] = icmp ult i8 [[X]], 1
353 ; CHECK-NEXT: call void @use(i1 [[C2]])
354 ; CHECK-NEXT: [[C3:%.*]] = icmp ule i8 [[X]], 1
355 ; CHECK-NEXT: call void @use(i1 [[C3]])
356 ; CHECK-NEXT: [[C4:%.*]] = icmp uge i8 [[X]], 1
357 ; CHECK-NEXT: call void @use(i1 [[C4]])
358 ; CHECK-NEXT: [[C5:%.*]] = icmp ugt i8 [[X]], 1
359 ; CHECK-NEXT: call void @use(i1 [[C5]])
360 ; CHECK-NEXT: ret void
362 ; CHECK-NEXT: call void @use(i1 false)
363 ; CHECK-NEXT: [[C3_2:%.*]] = icmp ule i8 [[X]], 1
364 ; CHECK-NEXT: call void @use(i1 [[C3_2]])
365 ; CHECK-NEXT: call void @use(i1 true)
366 ; CHECK-NEXT: [[C5_2:%.*]] = icmp ugt i8 [[X]], 1
367 ; CHECK-NEXT: call void @use(i1 [[C5_2]])
368 ; CHECK-NEXT: ret void
371 %c1 = icmp ne i8 %u, 1
372 br i1 %c1, label %if, label %else
375 %c2 = icmp ult i8 %x, 1
376 call void @use(i1 %c2)
377 %c3 = icmp ule i8 %x, 1
378 call void @use(i1 %c3)
379 %c4 = icmp uge i8 %x, 1
380 call void @use(i1 %c4)
381 %c5 = icmp ugt i8 %x, 1
382 call void @use(i1 %c5)
386 %c2.2 = icmp ult i8 %x, 1
387 call void @use(i1 %c2.2)
388 %c3.2 = icmp ule i8 %x, 1
389 call void @use(i1 %c3.2)
390 %c4.2 = icmp uge i8 %x, 1
391 call void @use(i1 %c4.2)
392 %c5.2 = icmp ugt i8 %x, 1
393 call void @use(i1 %c5.2)
397 define i8 @urem_undef_range_op1(i8 %x) {
398 ; CHECK-LABEL: @urem_undef_range_op1(
400 ; CHECK-NEXT: switch i8 [[X:%.*]], label [[JOIN:%.*]] [
401 ; CHECK-NEXT: i8 1, label [[CASE1:%.*]]
402 ; CHECK-NEXT: i8 2, label [[CASE2:%.*]]
405 ; CHECK-NEXT: br label [[JOIN]]
407 ; CHECK-NEXT: br label [[JOIN]]
409 ; CHECK-NEXT: [[PHI:%.*]] = phi i8 [ 1, [[CASE1]] ], [ 2, [[CASE2]] ], [ undef, [[ENTRY:%.*]] ]
410 ; CHECK-NEXT: [[RES:%.*]] = urem i8 [[PHI]], 3
411 ; CHECK-NEXT: ret i8 [[RES]]
414 switch i8 %x, label %join [
426 %phi = phi i8 [ 1, %case1 ], [ 2, %case2 ], [ undef, %entry ]
427 %res = urem i8 %phi, 3
431 define i8 @urem_undef_range_op2(i8 %x) {
432 ; CHECK-LABEL: @urem_undef_range_op2(
434 ; CHECK-NEXT: switch i8 [[X:%.*]], label [[JOIN:%.*]] [
435 ; CHECK-NEXT: i8 1, label [[CASE1:%.*]]
436 ; CHECK-NEXT: i8 2, label [[CASE2:%.*]]
439 ; CHECK-NEXT: br label [[JOIN]]
441 ; CHECK-NEXT: br label [[JOIN]]
443 ; CHECK-NEXT: [[PHI:%.*]] = phi i8 [ 5, [[CASE1]] ], [ 6, [[CASE2]] ], [ undef, [[ENTRY:%.*]] ]
444 ; CHECK-NEXT: [[RES:%.*]] = sub nuw i8 7, [[PHI]]
445 ; CHECK-NEXT: ret i8 [[RES]]
448 switch i8 %x, label %join [
460 %phi = phi i8 [ 5, %case1 ], [ 6, %case2 ], [ undef, %entry ]
461 %res = urem i8 7, %phi
465 define i1 @urem_i1() {
466 ; CHECK-LABEL: @urem_i1(
467 ; CHECK-NEXT: [[REM:%.*]] = urem i1 false, false
468 ; CHECK-NEXT: ret i1 [[REM]]
470 %rem = urem i1 false, false
474 declare void @use(i1)