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
80 define <4 x i1> @test5(<4 x i1> %vec) {
82 ; CHECK: ret <4 x i1> <i1 true, i1 true, i1 true, i1 true>
83 %res = icmp ule <4 x i1> %vec, %vec
87 ; Don't crash on vector inputs - pr25040
88 define <4 x i1> @test6(<4 x i1> %a, <4 x i1> %b) {
90 ; CHECK: ret <4 x i1> %res
91 %res = icmp ule <4 x i1> %a, %b
95 ; i +_{nsw} 1 <s L ==> i < L +_{nsw} 1
96 define i1 @test7(i32 %length.i, i32 %i) {
97 ; CHECK-LABEL: @test7(
99 %iplus1 = add nsw i32 %i, 1
100 %len.plus.one = add nsw i32 %length.i, 1
101 %var29 = icmp slt i32 %i, %len.plus.one
102 %var30 = icmp slt i32 %iplus1, %length.i
103 %res = icmp ule i1 %var30, %var29
107 ; i +_{nuw} 1 <s L ==> i < L +_{nuw} 1
108 define i1 @test8(i32 %length.i, i32 %i) {
109 ; CHECK-LABEL: @test8(
111 %iplus1 = add nuw i32 %i, 1
112 %len.plus.one = add nuw i32 %length.i, 1
113 %var29 = icmp ult i32 %i, %len.plus.one
114 %var30 = icmp ult i32 %iplus1, %length.i
115 %res = icmp ule i1 %var30, %var29
119 ; X >=(s) Y == X ==> Y (i1 1 becomes -1 for reasoning)
120 define i1 @test_sge(i32 %length.i, i32 %i) {
121 ; CHECK-LABEL: @test_sge
123 %iplus1 = add nsw nuw i32 %i, 1
124 %var29 = icmp ult i32 %i, %length.i
125 %var30 = icmp ult i32 %iplus1, %length.i
126 %res = icmp sge i1 %var30, %var29