@@ -264,3 +264,62 @@ define i1 @pr69091(i32 %arg, i32 %arg1) {
264264 %or = or i1 %icmp , %icmp2
265265 ret i1 %or
266266}
267+
268+ declare void @barrier ()
269+
270+ define i1 @or_icmp_implies_ub (i32 %x ) {
271+ ; CHECK-LABEL: @or_icmp_implies_ub(
272+ ; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[X:%.*]], 0
273+ ; CHECK-NEXT: call void @barrier()
274+ ; CHECK-NEXT: ret i1 [[CMP1]]
275+ ;
276+ %cmp1 = icmp ne i32 %x , 0
277+ call void @barrier ()
278+ %div = udiv i32 2147483647 , %x
279+ %cmp2 = icmp ugt i32 %x , %div
280+ %or = or i1 %cmp1 , %cmp2
281+ ret i1 %or
282+ }
283+
284+ define i1 @and_icmp_implies_ub (i32 %x ) {
285+ ; CHECK-LABEL: @and_icmp_implies_ub(
286+ ; CHECK-NEXT: call void @barrier()
287+ ; CHECK-NEXT: ret i1 false
288+ ;
289+ %cmp1 = icmp eq i32 %x , 0
290+ call void @barrier ()
291+ %div = udiv i32 2147483647 , %x
292+ %cmp2 = icmp ugt i32 %x , %div
293+ %and = and i1 %cmp1 , %cmp2
294+ ret i1 %and
295+ }
296+
297+ define i1 @or_icmp_implies_poison (i32 %x ) {
298+ ; CHECK-LABEL: @or_icmp_implies_poison(
299+ ; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[X:%.*]], 32
300+ ; CHECK-NEXT: [[SHL:%.*]] = shl i32 1, [[X]]
301+ ; CHECK-NEXT: [[CMP2:%.*]] = icmp ugt i32 [[X]], [[SHL]]
302+ ; CHECK-NEXT: [[OR:%.*]] = or i1 [[CMP1]], [[CMP2]]
303+ ; CHECK-NEXT: ret i1 [[OR]]
304+ ;
305+ %cmp1 = icmp ne i32 %x , 32
306+ %shl = shl i32 1 , %x
307+ %cmp2 = icmp ugt i32 %x , %shl
308+ %or = or i1 %cmp1 , %cmp2
309+ ret i1 %or
310+ }
311+
312+ define i1 @and_icmp_implies_poison (i32 %x ) {
313+ ; CHECK-LABEL: @and_icmp_implies_poison(
314+ ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[X:%.*]], 32
315+ ; CHECK-NEXT: [[SHL:%.*]] = shl i32 1, [[X]]
316+ ; CHECK-NEXT: [[CMP2:%.*]] = icmp ugt i32 [[X]], [[SHL]]
317+ ; CHECK-NEXT: [[AND:%.*]] = and i1 [[CMP1]], [[CMP2]]
318+ ; CHECK-NEXT: ret i1 [[AND]]
319+ ;
320+ %cmp1 = icmp eq i32 %x , 32
321+ %shl = shl i32 1 , %x
322+ %cmp2 = icmp ugt i32 %x , %shl
323+ %and = and i1 %cmp1 , %cmp2
324+ ret i1 %and
325+ }
0 commit comments