1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 ; icmp u/s (a ^ signmask), (b ^ signmask) --> icmp s/u a, b
6 define i1 @slt_to_ult(i8 %x, i8 %y) {
7 ; CHECK-LABEL: @slt_to_ult(
8 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[X:%.*]], [[Y:%.*]]
9 ; CHECK-NEXT: ret i1 [[CMP]]
13 %cmp = icmp slt i8 %a, %b
17 ; PR33138 - https://bugs.llvm.org/show_bug.cgi?id=33138
19 define <2 x i1> @slt_to_ult_splat(<2 x i8> %x, <2 x i8> %y) {
20 ; CHECK-LABEL: @slt_to_ult_splat(
21 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i8> [[X:%.*]], [[Y:%.*]]
22 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
24 %a = xor <2 x i8> %x, <i8 128, i8 128>
25 %b = xor <2 x i8> %y, <i8 128, i8 128>
26 %cmp = icmp slt <2 x i8> %a, %b
30 ; Make sure that unsigned -> signed works too.
32 define i1 @ult_to_slt(i8 %x, i8 %y) {
33 ; CHECK-LABEL: @ult_to_slt(
34 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], [[Y:%.*]]
35 ; CHECK-NEXT: ret i1 [[CMP]]
39 %cmp = icmp ult i8 %a, %b
43 define <2 x i1> @ult_to_slt_splat(<2 x i8> %x, <2 x i8> %y) {
44 ; CHECK-LABEL: @ult_to_slt_splat(
45 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], [[Y:%.*]]
46 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
48 %a = xor <2 x i8> %x, <i8 128, i8 128>
49 %b = xor <2 x i8> %y, <i8 128, i8 128>
50 %cmp = icmp ult <2 x i8> %a, %b
54 ; icmp u/s (a ^ maxsignval), (b ^ maxsignval) --> icmp s/u' a, b
56 define i1 @slt_to_ugt(i8 %x, i8 %y) {
57 ; CHECK-LABEL: @slt_to_ugt(
58 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X:%.*]], [[Y:%.*]]
59 ; CHECK-NEXT: ret i1 [[CMP]]
63 %cmp = icmp slt i8 %a, %b
67 define <2 x i1> @slt_to_ugt_splat(<2 x i8> %x, <2 x i8> %y) {
68 ; CHECK-LABEL: @slt_to_ugt_splat(
69 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> [[X:%.*]], [[Y:%.*]]
70 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
72 %a = xor <2 x i8> %x, <i8 127, i8 127>
73 %b = xor <2 x i8> %y, <i8 127, i8 127>
74 %cmp = icmp slt <2 x i8> %a, %b
78 ; Make sure that unsigned -> signed works too.
80 define i1 @ult_to_sgt(i8 %x, i8 %y) {
81 ; CHECK-LABEL: @ult_to_sgt(
82 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], [[Y:%.*]]
83 ; CHECK-NEXT: ret i1 [[CMP]]
87 %cmp = icmp ult i8 %a, %b
91 define <2 x i1> @ult_to_sgt_splat(<2 x i8> %x, <2 x i8> %y) {
92 ; CHECK-LABEL: @ult_to_sgt_splat(
93 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], [[Y:%.*]]
94 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
96 %a = xor <2 x i8> %x, <i8 127, i8 127>
97 %b = xor <2 x i8> %y, <i8 127, i8 127>
98 %cmp = icmp ult <2 x i8> %a, %b
102 ; icmp u/s (a ^ signmask), C --> icmp s/u a, C'
104 define i1 @sge_to_ugt(i8 %x) {
105 ; CHECK-LABEL: @sge_to_ugt(
106 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X:%.*]], -114
107 ; CHECK-NEXT: ret i1 [[CMP]]
110 %cmp = icmp sge i8 %a, 15
114 define <2 x i1> @sge_to_ugt_splat(<2 x i8> %x) {
115 ; CHECK-LABEL: @sge_to_ugt_splat(
116 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 -114, i8 -114>
117 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
119 %a = xor <2 x i8> %x, <i8 128, i8 128>
120 %cmp = icmp sge <2 x i8> %a, <i8 15, i8 15>
124 ; Make sure that unsigned -> signed works too.
126 define i1 @uge_to_sgt(i8 %x) {
127 ; CHECK-LABEL: @uge_to_sgt(
128 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -114
129 ; CHECK-NEXT: ret i1 [[CMP]]
132 %cmp = icmp uge i8 %a, 15
136 define <2 x i1> @uge_to_sgt_splat(<2 x i8> %x) {
137 ; CHECK-LABEL: @uge_to_sgt_splat(
138 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 -114, i8 -114>
139 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
141 %a = xor <2 x i8> %x, <i8 128, i8 128>
142 %cmp = icmp uge <2 x i8> %a, <i8 15, i8 15>
146 ; icmp u/s (a ^ maxsignval), C --> icmp s/u' a, C'
148 define i1 @sge_to_ult(i8 %x) {
149 ; CHECK-LABEL: @sge_to_ult(
150 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[X:%.*]], 113
151 ; CHECK-NEXT: ret i1 [[CMP]]
154 %cmp = icmp sge i8 %a, 15
158 define <2 x i1> @sge_to_ult_splat(<2 x i8> %x) {
159 ; CHECK-LABEL: @sge_to_ult_splat(
160 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i8> [[X:%.*]], <i8 113, i8 113>
161 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
163 %a = xor <2 x i8> %x, <i8 127, i8 127>
164 %cmp = icmp sge <2 x i8> %a, <i8 15, i8 15>
168 ; Make sure that unsigned -> signed works too.
170 define i1 @uge_to_slt(i8 %x) {
171 ; CHECK-LABEL: @uge_to_slt(
172 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 113
173 ; CHECK-NEXT: ret i1 [[CMP]]
176 %cmp = icmp uge i8 %a, 15
180 define <2 x i1> @uge_to_slt_splat(<2 x i8> %x) {
181 ; CHECK-LABEL: @uge_to_slt_splat(
182 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], <i8 113, i8 113>
183 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
185 %a = xor <2 x i8> %x, <i8 127, i8 127>
186 %cmp = icmp uge <2 x i8> %a, <i8 15, i8 15>
190 ; PR33138, part 2: https://bugs.llvm.org/show_bug.cgi?id=33138
191 ; Bitcast canonicalization ensures that we recognize the signbit constant.
193 define <8 x i1> @sgt_to_ugt_bitcasted_splat(<2 x i32> %x, <2 x i32> %y) {
194 ; CHECK-LABEL: @sgt_to_ugt_bitcasted_splat(
195 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i32> [[X:%.*]] to <8 x i8>
196 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast <2 x i32> [[Y:%.*]] to <8 x i8>
197 ; CHECK-NEXT: [[E:%.*]] = icmp ugt <8 x i8> [[TMP1]], [[TMP2]]
198 ; CHECK-NEXT: ret <8 x i1> [[E]]
200 %a = xor <2 x i32> %x, <i32 2155905152, i32 2155905152> ; 0x80808080
201 %b = xor <2 x i32> %y, <i32 2155905152, i32 2155905152>
202 %c = bitcast <2 x i32> %a to <8 x i8>
203 %d = bitcast <2 x i32> %b to <8 x i8>
204 %e = icmp sgt <8 x i8> %c, %d
208 ; Bitcast canonicalization ensures that we recognize the signbit constant.
210 define <2 x i1> @negative_simplify_splat(<4 x i8> %x) {
211 ; CHECK-LABEL: @negative_simplify_splat(
212 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
214 %a = or <4 x i8> %x, <i8 0, i8 128, i8 0, i8 128>
215 %b = bitcast <4 x i8> %a to <2 x i16>
216 %c = icmp sgt <2 x i16> %b, zeroinitializer
220 define i1 @slt_zero_eq_i1(i32 %a, i1 %b) {
221 ; CHECK-LABEL: @slt_zero_eq_i1(
222 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[A:%.*]], -1
223 ; CHECK-NEXT: [[CMP21:%.*]] = xor i1 [[TMP1]], [[B:%.*]]
224 ; CHECK-NEXT: ret i1 [[CMP21]]
226 %conv = zext i1 %b to i32
227 %cmp1 = lshr i32 %a, 31
228 %cmp2 = icmp eq i32 %conv, %cmp1
232 define i1 @slt_zero_eq_i1_fail(i32 %a, i1 %b) {
233 ; CHECK-LABEL: @slt_zero_eq_i1_fail(
234 ; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[B:%.*]] to i32
235 ; CHECK-NEXT: [[CMP1:%.*]] = ashr i32 [[A:%.*]], 31
236 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[CMP1]], [[CONV]]
237 ; CHECK-NEXT: ret i1 [[CMP2]]
239 %conv = zext i1 %b to i32
240 %cmp1 = ashr i32 %a, 31
241 %cmp2 = icmp eq i32 %conv, %cmp1
245 define i1 @slt_zero_eq_ne_0(i32 %a) {
246 ; CHECK-LABEL: @slt_zero_eq_ne_0(
247 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[A:%.*]], 1
248 ; CHECK-NEXT: ret i1 [[TMP1]]
250 %cmp = icmp ne i32 %a, 0
251 %conv = zext i1 %cmp to i32
252 %cmp1 = lshr i32 %a, 31
253 %cmp2 = icmp eq i32 %conv, %cmp1
257 define i1 @slt_zero_ne_ne_0(i32 %a) {
258 ; CHECK-LABEL: @slt_zero_ne_ne_0(
259 ; CHECK-NEXT: [[CMP21:%.*]] = icmp sgt i32 [[A:%.*]], 0
260 ; CHECK-NEXT: ret i1 [[CMP21]]
262 %cmp = icmp ne i32 %a, 0
263 %conv = zext i1 %cmp to i32
264 %cmp1 = lshr i32 %a, 31
265 %cmp2 = icmp ne i32 %conv, %cmp1
269 define <4 x i1> @slt_zero_eq_ne_0_vec(<4 x i32> %a) {
270 ; CHECK-LABEL: @slt_zero_eq_ne_0_vec(
271 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <4 x i32> [[A:%.*]], <i32 1, i32 1, i32 1, i32 1>
272 ; CHECK-NEXT: ret <4 x i1> [[TMP1]]
274 %cmp = icmp ne <4 x i32> %a, zeroinitializer
275 %conv = zext <4 x i1> %cmp to <4 x i32>
276 %cmp1 = lshr <4 x i32> %a, <i32 31, i32 31, i32 31, i32 31>
277 %cmp2 = icmp eq <4 x i32> %conv, %cmp1
281 define i1 @slt_zero_ne_ne_b(i32 %a, i32 %b) {
282 ; CHECK-LABEL: @slt_zero_ne_ne_b(
283 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[A:%.*]], [[B:%.*]]
284 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[A]], 0
285 ; CHECK-NEXT: [[CMP21:%.*]] = xor i1 [[TMP1]], [[CMP]]
286 ; CHECK-NEXT: ret i1 [[CMP21]]
288 %cmp = icmp ne i32 %a, %b
289 %conv = zext i1 %cmp to i32
290 %cmp1 = lshr i32 %a, 31
291 %cmp2 = icmp ne i32 %conv, %cmp1
295 define i1 @slt_zero_eq_ne_0_fail1(i32 %a) {
296 ; CHECK-LABEL: @slt_zero_eq_ne_0_fail1(
297 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[A:%.*]], 0
298 ; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP]] to i32
299 ; CHECK-NEXT: [[CMP1:%.*]] = ashr i32 [[A]], 31
300 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[CMP1]], [[CONV]]
301 ; CHECK-NEXT: ret i1 [[CMP2]]
303 %cmp = icmp ne i32 %a, 0
304 %conv = zext i1 %cmp to i32
305 %cmp1 = ashr i32 %a, 31
306 %cmp2 = icmp eq i32 %conv, %cmp1
310 define i1 @slt_zero_eq_ne_0_fail2(i32 %a) {
311 ; CHECK-LABEL: @slt_zero_eq_ne_0_fail2(
312 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[A:%.*]], 0
313 ; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP]] to i32
314 ; CHECK-NEXT: [[CMP1:%.*]] = lshr i32 [[A]], 30
315 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[CMP1]], [[CONV]]
316 ; CHECK-NEXT: ret i1 [[CMP2]]
318 %cmp = icmp ne i32 %a, 0
319 %conv = zext i1 %cmp to i32
320 %cmp1 = lshr i32 %a, 30
321 %cmp2 = icmp eq i32 %conv, %cmp1