1 ; RUN: opt -S %s -instsimplify | FileCheck %s
4 define i1 @test(i32 %length.i, i32 %i) {
7 %var29 = icmp slt i32 %i, %length.i
8 %res = icmp uge i1 %var29, %var29
12 ; i +_{nsw} C_{>0} <s L ==> i <s L -> true
13 define i1 @test2(i32 %length.i, i32 %i) {
16 %iplus1 = add nsw i32 %i, 1
17 %var29 = icmp slt i32 %i, %length.i
18 %var30 = icmp slt i32 %iplus1, %length.i
19 %res = icmp ule i1 %var30, %var29
23 ; i + C_{>0} <s L ==> i <s L -> unknown without the nsw
24 define i1 @test2_neg(i32 %length.i, i32 %i) {
25 ; CHECK-LABEL: @test2_neg
27 %iplus1 = add i32 %i, 1
28 %var29 = icmp slt i32 %i, %length.i
29 %var30 = icmp slt i32 %iplus1, %length.i
30 %res = icmp ule i1 %var30, %var29
34 ; sle is not implication
35 define i1 @test2_neg2(i32 %length.i, i32 %i) {
36 ; CHECK-LABEL: @test2_neg2
38 %iplus1 = add i32 %i, 1
39 %var29 = icmp slt i32 %i, %length.i
40 %var30 = icmp slt i32 %iplus1, %length.i
41 %res = icmp sle i1 %var30, %var29
45 ; The binary operator has to be an add
46 define i1 @test2_neg3(i32 %length.i, i32 %i) {
47 ; CHECK-LABEL: @test2_neg3
49 %iplus1 = sub nsw i32 %i, 1
50 %var29 = icmp slt i32 %i, %length.i
51 %var30 = icmp slt i32 %iplus1, %length.i
52 %res = icmp ule i1 %var30, %var29
56 ; i +_{nsw} C_{>0} <s L ==> i <s L -> true
57 ; With an inverted conditional (ule B A rather than canonical ugt A B
58 define i1 @test3(i32 %length.i, i32 %i) {
61 %iplus1 = add nsw i32 %i, 1
62 %var29 = icmp slt i32 %i, %length.i
63 %var30 = icmp slt i32 %iplus1, %length.i
64 %res = icmp uge i1 %var29, %var30
68 ; i +_{nuw} C_{>0} <u L ==> i <u L
69 define i1 @test4(i32 %length.i, i32 %i) {
72 %iplus1 = add nuw i32 %i, 1
73 %var29 = icmp ult i32 %i, %length.i
74 %var30 = icmp ult i32 %iplus1, %length.i
75 %res = icmp ule i1 %var30, %var29