72ada2476fdebab5107b81d9166a975f4b12110b
[oota-llvm.git] / test / Transforms / InstCombine / icmp.ll
1 ; RUN: opt < %s -instcombine -S | FileCheck %s
2
3 target datalayout =
4 "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
5
6 define i32 @test1(i32 %X) {
7 entry:
8         icmp slt i32 %X, 0              ; <i1>:0 [#uses=1]
9         zext i1 %0 to i32               ; <i32>:1 [#uses=1]
10         ret i32 %1
11 ; CHECK: @test1
12 ; CHECK: lshr i32 %X, 31
13 ; CHECK-NEXT: ret i32
14 }
15
16 define i32 @test2(i32 %X) {
17 entry:
18         icmp ult i32 %X, -2147483648            ; <i1>:0 [#uses=1]
19         zext i1 %0 to i32               ; <i32>:1 [#uses=1]
20         ret i32 %1
21 ; CHECK: @test2
22 ; CHECK: lshr i32 %X, 31
23 ; CHECK-NEXT: xor i32
24 ; CHECK-NEXT: ret i32
25 }
26
27 define i32 @test3(i32 %X) {
28 entry:
29         icmp slt i32 %X, 0              ; <i1>:0 [#uses=1]
30         sext i1 %0 to i32               ; <i32>:1 [#uses=1]
31         ret i32 %1
32 ; CHECK: @test3
33 ; CHECK: ashr i32 %X, 31
34 ; CHECK-NEXT: ret i32
35 }
36
37 define i32 @test4(i32 %X) {
38 entry:
39         icmp ult i32 %X, -2147483648            ; <i1>:0 [#uses=1]
40         sext i1 %0 to i32               ; <i32>:1 [#uses=1]
41         ret i32 %1
42 ; CHECK: @test4
43 ; CHECK: ashr i32 %X, 31
44 ; CHECK-NEXT: xor i32
45 ; CHECK-NEXT: ret i32
46 }
47
48 ; PR4837
49 define <2 x i1> @test5(<2 x i64> %x) {
50 entry:
51   %V = icmp eq <2 x i64> %x, undef
52   ret <2 x i1> %V
53 ; CHECK: @test5
54 ; CHECK: ret <2 x i1> <i1 true, i1 true>
55 }
56
57 define i32 @test6(i32 %a, i32 %b) {
58         %c = icmp sle i32 %a, -1
59         %d = zext i1 %c to i32
60         %e = sub i32 0, %d
61         %f = and i32 %e, %b
62         ret i32 %f
63 ; CHECK: @test6
64 ; CHECK-NEXT: ashr i32 %a, 31
65 ; CHECK-NEXT: %f = and i32 %e, %b
66 ; CHECK-NEXT: ret i32 %f
67 }
68
69
70 define i1 @test7(i32 %x) {
71 entry:
72   %a = add i32 %x, -1
73   %b = icmp ult i32 %a, %x
74   ret i1 %b
75 ; CHECK: @test7
76 ; CHECK: %b = icmp ne i32 %x, 0
77 ; CHECK: ret i1 %b
78 }
79
80 define i1 @test8(i32 %x){
81 entry:
82   %a = add i32 %x, -1 
83   %b = icmp eq i32 %a, %x
84   ret i1 %b
85 ; CHECK: @test8
86 ; CHECK: ret i1 false
87 }
88
89 define i1 @test9(i32 %x)  {
90 entry:
91   %a = add i32 %x, -2
92   %b = icmp ugt i32 %x, %a 
93   ret i1 %b
94 ; CHECK: @test9
95 ; CHECK: icmp ugt i32 %x, 1
96 ; CHECK: ret i1 %b
97 }
98
99 define i1 @test10(i32 %x){
100 entry:
101   %a = add i32 %x, -1      
102   %b = icmp slt i32 %a, %x 
103   ret i1 %b
104   
105 ; CHECK: @test10
106 ; CHECK: %b = icmp ne i32 %x, -2147483648
107 ; CHECK: ret i1 %b
108 }
109
110 define i1 @test11(i32 %x) {
111   %a = add nsw i32 %x, 8
112   %b = icmp slt i32 %x, %a
113   ret i1 %b
114 ; CHECK: @test11  
115 ; CHECK: ret i1 true
116 }
117
118 ; PR6195
119 define i1 @test12(i1 %A) {
120   %S = select i1 %A, i64 -4294967295, i64 8589934591
121   %B = icmp ne i64 bitcast (<2 x i32> <i32 1, i32 -1> to i64), %S
122   ret i1 %B
123 ; CHECK: @test12
124 ; CHECK-NEXT: %B = select i1
125 ; CHECK-NEXT: ret i1 %B
126 }
127
128 ; PR6481
129 define i1 @test13(i8 %X) nounwind readnone {
130 entry:
131         %cmp = icmp slt i8 undef, %X
132         ret i1 %cmp
133 ; CHECK: @test13
134 ; CHECK: ret i1 false
135 }
136
137 define i1 @test14(i8 %X) nounwind readnone {
138 entry:
139         %cmp = icmp slt i8 undef, -128
140         ret i1 %cmp
141 ; CHECK: @test14
142 ; CHECK: ret i1 false
143 }
144
145 define i1 @test15() nounwind readnone {
146 entry:
147         %cmp = icmp eq i8 undef, -128
148         ret i1 %cmp
149 ; CHECK: @test15
150 ; CHECK: ret i1 undef
151 }
152
153 define i1 @test16() nounwind readnone {
154 entry:
155         %cmp = icmp ne i8 undef, -128
156         ret i1 %cmp
157 ; CHECK: @test16
158 ; CHECK: ret i1 undef
159 }
160
161 define i1 @test17(i32 %x) nounwind {
162   %shl = shl i32 1, %x
163   %and = and i32 %shl, 8
164   %cmp = icmp eq i32 %and, 0
165   ret i1 %cmp
166 ; CHECK: @test17
167 ; CHECK-NEXT: %cmp = icmp ne i32 %x, 3
168 }
169
170
171 define i1 @test18(i32 %x) nounwind {
172   %sh = lshr i32 8, %x
173   %and = and i32 %sh, 1
174   %cmp = icmp eq i32 %and, 0
175   ret i1 %cmp
176 ; CHECK: @test18
177 ; CHECK-NEXT: %cmp = icmp ne i32 %x, 3
178 }
179
180 define i1 @test19(i32 %x) nounwind {
181   %shl = shl i32 1, %x
182   %and = and i32 %shl, 8
183   %cmp = icmp eq i32 %and, 8
184   ret i1 %cmp
185 ; CHECK: @test19
186 ; CHECK-NEXT: %cmp = icmp eq i32 %x, 3
187 }
188
189 define i1 @test20(i32 %x) nounwind {
190   %shl = shl i32 1, %x
191   %and = and i32 %shl, 8
192   %cmp = icmp ne i32 %and, 0
193   ret i1 %cmp
194 ; CHECK: @test20
195 ; CHECK-NEXT: %cmp = icmp eq i32 %x, 3
196 }
197
198 define i1 @test21(i8 %x, i8 %y) {
199 ; CHECK: @test21
200 ; CHECK-NOT: or i8
201 ; CHECK: icmp ugt
202   %A = or i8 %x, 1
203   %B = icmp ugt i8 %A, 3
204   ret i1 %B
205 }
206
207 define i1 @test22(i8 %x, i8 %y) {
208 ; CHECK: @test22
209 ; CHECK-NOT: or i8
210 ; CHECK: icmp ult
211   %A = or i8 %x, 1
212   %B = icmp ult i8 %A, 4
213   ret i1 %B
214 }
215
216 ; PR2740
217 ; CHECK: @test23
218 ; CHECK: icmp sgt i32 %x, 1328634634
219 define i1 @test23(i32 %x) nounwind {
220         %i3 = sdiv i32 %x, -1328634635
221         %i4 = icmp eq i32 %i3, -1
222         ret i1 %i4
223 }
224
225 @X = global [1000 x i32] zeroinitializer
226
227 ; PR8882
228 ; CHECK: @test24
229 ; CHECK:    %cmp = icmp eq i64 %i, 1000
230 ; CHECK:   ret i1 %cmp
231 define i1 @test24(i64 %i) {
232   %p1 = getelementptr inbounds i32* getelementptr inbounds ([1000 x i32]* @X, i64 0, i64 0), i64 %i
233   %cmp = icmp eq i32* %p1, getelementptr inbounds ([1000 x i32]* @X, i64 1, i64 0)
234   ret i1 %cmp
235 }
236