1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; Canonicalize vector ge/le comparisons with constants to gt/lt.
6 ; Normal types are ConstantDataVectors. Test the constant values adjacent to the
7 ; min/max values that we're not allowed to transform.
9 define <2 x i1> @sge(<2 x i8> %x) {
11 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 -128, i8 126>
12 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
14 %cmp = icmp sge <2 x i8> %x, <i8 -127, i8 -129>
18 define <2 x i1> @uge(<2 x i8> %x) {
20 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 -2, i8 0>
21 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
23 %cmp = icmp uge <2 x i8> %x, <i8 -1, i8 1>
27 define <2 x i1> @sle(<2 x i8> %x) {
29 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], <i8 127, i8 -127>
30 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
32 %cmp = icmp sle <2 x i8> %x, <i8 126, i8 128>
36 define <2 x i1> @ule(<2 x i8> %x) {
38 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i8> [[X:%.*]], <i8 -1, i8 1>
39 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
41 %cmp = icmp ule <2 x i8> %x, <i8 254, i8 0>
45 define <2 x i1> @ult_min_signed_value(<2 x i8> %x) {
46 ; CHECK-LABEL: @ult_min_signed_value(
47 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
48 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
50 %cmp = icmp ult <2 x i8> %x, <i8 128, i8 128>
54 ; Zeros are special: they're ConstantAggregateZero.
56 define <2 x i1> @sge_zero(<2 x i8> %x) {
57 ; CHECK-LABEL: @sge_zero(
58 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
59 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
61 %cmp = icmp sge <2 x i8> %x, <i8 0, i8 0>
65 define <2 x i1> @uge_zero(<2 x i8> %x) {
66 ; CHECK-LABEL: @uge_zero(
67 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
69 %cmp = icmp uge <2 x i8> %x, <i8 0, i8 0>
73 define <2 x i1> @sle_zero(<2 x i8> %x) {
74 ; CHECK-LABEL: @sle_zero(
75 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], <i8 1, i8 1>
76 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
78 %cmp = icmp sle <2 x i8> %x, <i8 0, i8 0>
82 define <2 x i1> @ule_zero(<2 x i8> %x) {
83 ; CHECK-LABEL: @ule_zero(
84 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[X:%.*]], zeroinitializer
85 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
87 %cmp = icmp ule <2 x i8> %x, <i8 0, i8 0>
91 ; Weird types are ConstantVectors, not ConstantDataVectors. For an i3 type:
97 define <3 x i1> @sge_weird(<3 x i3> %x) {
98 ; CHECK-LABEL: @sge_weird(
99 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <3 x i3> [[X:%.*]], <i3 -4, i3 2, i3 -1>
100 ; CHECK-NEXT: ret <3 x i1> [[CMP]]
102 %cmp = icmp sge <3 x i3> %x, <i3 -3, i3 -5, i3 0>
106 define <3 x i1> @uge_weird(<3 x i3> %x) {
107 ; CHECK-LABEL: @uge_weird(
108 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <3 x i3> [[X:%.*]], <i3 -2, i3 0, i3 1>
109 ; CHECK-NEXT: ret <3 x i1> [[CMP]]
111 %cmp = icmp uge <3 x i3> %x, <i3 -1, i3 1, i3 2>
115 define <3 x i1> @sle_weird(<3 x i3> %x) {
116 ; CHECK-LABEL: @sle_weird(
117 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <3 x i3> [[X:%.*]], <i3 3, i3 -3, i3 1>
118 ; CHECK-NEXT: ret <3 x i1> [[CMP]]
120 %cmp = icmp sle <3 x i3> %x, <i3 2, i3 4, i3 0>
124 define <3 x i1> @ule_weird(<3 x i3> %x) {
125 ; CHECK-LABEL: @ule_weird(
126 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <3 x i3> [[X:%.*]], <i3 -1, i3 1, i3 2>
127 ; CHECK-NEXT: ret <3 x i1> [[CMP]]
129 %cmp = icmp ule <3 x i3> %x, <i3 6, i3 0, i3 1>
133 ; We can't do the transform if any constants are already at the limits.
135 define <2 x i1> @sge_min(<2 x i3> %x) {
136 ; CHECK-LABEL: @sge_min(
137 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge <2 x i3> [[X:%.*]], <i3 -4, i3 1>
138 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
140 %cmp = icmp sge <2 x i3> %x, <i3 -4, i3 1>
144 define <2 x i1> @uge_min(<2 x i3> %x) {
145 ; CHECK-LABEL: @uge_min(
146 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge <2 x i3> [[X:%.*]], <i3 1, i3 0>
147 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
149 %cmp = icmp uge <2 x i3> %x, <i3 1, i3 0>
153 define <2 x i1> @sle_max(<2 x i3> %x) {
154 ; CHECK-LABEL: @sle_max(
155 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle <2 x i3> [[X:%.*]], <i3 1, i3 3>
156 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
158 %cmp = icmp sle <2 x i3> %x, <i3 1, i3 3>
162 define <2 x i1> @ule_max(<2 x i3> %x) {
163 ; CHECK-LABEL: @ule_max(
164 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule <2 x i3> [[X:%.*]], <i3 -1, i3 1>
165 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
167 %cmp = icmp ule <2 x i3> %x, <i3 7, i3 1>
171 define <2 x i1> @PR27756_1(<2 x i8> %a) {
172 ; CHECK-LABEL: @PR27756_1(
173 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[A:%.*]], <i8 34, i8 1>
174 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
176 %cmp = icmp sle <2 x i8> %a, <i8 bitcast (<2 x i4> <i4 1, i4 2> to i8), i8 0>
180 ; Undef elements don't prevent the transform of the comparison.
182 define <3 x i1> @PR27756_2(<3 x i8> %a) {
183 ; CHECK-LABEL: @PR27756_2(
184 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <3 x i8> [[A:%.*]], <i8 43, i8 43, i8 1>
185 ; CHECK-NEXT: ret <3 x i1> [[CMP]]
187 %cmp = icmp sle <3 x i8> %a, <i8 42, i8 undef, i8 0>
191 define <3 x i1> @PR27756_3(<3 x i8> %a) {
192 ; CHECK-LABEL: @PR27756_3(
193 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <3 x i8> [[A:%.*]], <i8 0, i8 0, i8 41>
194 ; CHECK-NEXT: ret <3 x i1> [[CMP]]
196 %cmp = icmp sge <3 x i8> %a, <i8 undef, i8 1, i8 42>
200 @someglobal = global i32 0
202 define <2 x i1> @PR27786(<2 x i8> %a) {
203 ; CHECK-LABEL: @PR27786(
204 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle <2 x i8> [[A:%.*]], bitcast (i16 ptrtoint (i32* @someglobal to i16) to <2 x i8>)
205 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
207 %cmp = icmp sle <2 x i8> %a, bitcast (i16 ptrtoint (i32* @someglobal to i16) to <2 x i8>)
211 ; This is similar to a transform for shuffled binops: compare first, shuffle after.
213 define <4 x i1> @same_shuffle_inputs_icmp(<4 x i8> %x, <4 x i8> %y) {
214 ; CHECK-LABEL: @same_shuffle_inputs_icmp(
215 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <4 x i8> [[X:%.*]], [[Y:%.*]]
216 ; CHECK-NEXT: [[CMP:%.*]] = shufflevector <4 x i1> [[TMP1]], <4 x i1> undef, <4 x i32> <i32 3, i32 3, i32 2, i32 0>
217 ; CHECK-NEXT: ret <4 x i1> [[CMP]]
219 %shufx = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> < i32 3, i32 3, i32 2, i32 0 >
220 %shufy = shufflevector <4 x i8> %y, <4 x i8> undef, <4 x i32> < i32 3, i32 3, i32 2, i32 0 >
221 %cmp = icmp sgt <4 x i8> %shufx, %shufy
225 ; fcmp and size-changing shuffles are ok too.
227 define <5 x i1> @same_shuffle_inputs_fcmp(<4 x float> %x, <4 x float> %y) {
228 ; CHECK-LABEL: @same_shuffle_inputs_fcmp(
229 ; CHECK-NEXT: [[TMP1:%.*]] = fcmp oeq <4 x float> [[X:%.*]], [[Y:%.*]]
230 ; CHECK-NEXT: [[CMP:%.*]] = shufflevector <4 x i1> [[TMP1]], <4 x i1> undef, <5 x i32> <i32 0, i32 1, i32 3, i32 2, i32 0>
231 ; CHECK-NEXT: ret <5 x i1> [[CMP]]
233 %shufx = shufflevector <4 x float> %x, <4 x float> undef, <5 x i32> < i32 0, i32 1, i32 3, i32 2, i32 0 >
234 %shufy = shufflevector <4 x float> %y, <4 x float> undef, <5 x i32> < i32 0, i32 1, i32 3, i32 2, i32 0 >
235 %cmp = fcmp oeq <5 x float> %shufx, %shufy
239 declare void @use_v4i8(<4 x i8>)
241 define <4 x i1> @same_shuffle_inputs_icmp_extra_use1(<4 x i8> %x, <4 x i8> %y) {
242 ; CHECK-LABEL: @same_shuffle_inputs_icmp_extra_use1(
243 ; CHECK-NEXT: [[SHUFX:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
244 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <4 x i8> [[X]], [[Y:%.*]]
245 ; CHECK-NEXT: [[CMP:%.*]] = shufflevector <4 x i1> [[TMP1]], <4 x i1> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
246 ; CHECK-NEXT: call void @use_v4i8(<4 x i8> [[SHUFX]])
247 ; CHECK-NEXT: ret <4 x i1> [[CMP]]
249 %shufx = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> < i32 3, i32 3, i32 3, i32 3 >
250 %shufy = shufflevector <4 x i8> %y, <4 x i8> undef, <4 x i32> < i32 3, i32 3, i32 3, i32 3 >
251 %cmp = icmp ugt <4 x i8> %shufx, %shufy
252 call void @use_v4i8(<4 x i8> %shufx)
256 declare void @use_v2i8(<2 x i8>)
258 define <2 x i1> @same_shuffle_inputs_icmp_extra_use2(<4 x i8> %x, <4 x i8> %y) {
259 ; CHECK-LABEL: @same_shuffle_inputs_icmp_extra_use2(
260 ; CHECK-NEXT: [[SHUFY:%.*]] = shufflevector <4 x i8> [[Y:%.*]], <4 x i8> undef, <2 x i32> <i32 3, i32 2>
261 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <4 x i8> [[X:%.*]], [[Y]]
262 ; CHECK-NEXT: [[CMP:%.*]] = shufflevector <4 x i1> [[TMP1]], <4 x i1> undef, <2 x i32> <i32 3, i32 2>
263 ; CHECK-NEXT: call void @use_v2i8(<2 x i8> [[SHUFY]])
264 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
266 %shufx = shufflevector <4 x i8> %x, <4 x i8> undef, <2 x i32> < i32 3, i32 2 >
267 %shufy = shufflevector <4 x i8> %y, <4 x i8> undef, <2 x i32> < i32 3, i32 2 >
268 %cmp = icmp eq <2 x i8> %shufx, %shufy
269 call void @use_v2i8(<2 x i8> %shufy)
273 ; Negative test: if both shuffles have extra uses, don't transform because that would increase instruction count.
275 define <2 x i1> @same_shuffle_inputs_icmp_extra_use3(<4 x i8> %x, <4 x i8> %y) {
276 ; CHECK-LABEL: @same_shuffle_inputs_icmp_extra_use3(
277 ; CHECK-NEXT: [[SHUFX:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> undef, <2 x i32> zeroinitializer
278 ; CHECK-NEXT: [[SHUFY:%.*]] = shufflevector <4 x i8> [[Y:%.*]], <4 x i8> undef, <2 x i32> zeroinitializer
279 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[SHUFX]], [[SHUFY]]
280 ; CHECK-NEXT: call void @use_v2i8(<2 x i8> [[SHUFX]])
281 ; CHECK-NEXT: call void @use_v2i8(<2 x i8> [[SHUFY]])
282 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
284 %shufx = shufflevector <4 x i8> %x, <4 x i8> undef, <2 x i32> < i32 0, i32 0 >
285 %shufy = shufflevector <4 x i8> %y, <4 x i8> undef, <2 x i32> < i32 0, i32 0 >
286 %cmp = icmp eq <2 x i8> %shufx, %shufy
287 call void @use_v2i8(<2 x i8> %shufx)
288 call void @use_v2i8(<2 x i8> %shufy)
292 define <4 x i1> @splat_icmp(<4 x i8> %x) {
293 ; CHECK-LABEL: @splat_icmp(
294 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <4 x i8> [[X:%.*]], <i8 42, i8 42, i8 42, i8 42>
295 ; CHECK-NEXT: [[CMP:%.*]] = shufflevector <4 x i1> [[TMP1]], <4 x i1> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
296 ; CHECK-NEXT: ret <4 x i1> [[CMP]]
298 %splatx = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
299 %cmp = icmp sgt <4 x i8> %splatx, <i8 42, i8 42, i8 42, i8 42>
303 define <4 x i1> @splat_icmp_undef(<4 x i8> %x) {
304 ; CHECK-LABEL: @splat_icmp_undef(
305 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <4 x i8> [[X:%.*]], <i8 42, i8 42, i8 42, i8 42>
306 ; CHECK-NEXT: [[CMP:%.*]] = shufflevector <4 x i1> [[TMP1]], <4 x i1> undef, <4 x i32> <i32 2, i32 2, i32 2, i32 2>
307 ; CHECK-NEXT: ret <4 x i1> [[CMP]]
309 %splatx = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> <i32 2, i32 undef, i32 undef, i32 2>
310 %cmp = icmp ult <4 x i8> %splatx, <i8 undef, i8 42, i8 undef, i8 42>
314 define <4 x i1> @splat_icmp_larger_size(<2 x i8> %x) {
315 ; CHECK-LABEL: @splat_icmp_larger_size(
316 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i8> [[X:%.*]], <i8 42, i8 42>
317 ; CHECK-NEXT: [[CMP:%.*]] = shufflevector <2 x i1> [[TMP1]], <2 x i1> undef, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
318 ; CHECK-NEXT: ret <4 x i1> [[CMP]]
320 %splatx = shufflevector <2 x i8> %x, <2 x i8> undef, <4 x i32> <i32 1, i32 undef, i32 1, i32 undef>
321 %cmp = icmp eq <4 x i8> %splatx, <i8 42, i8 42, i8 undef, i8 42>
325 define <4 x i1> @splat_fcmp_smaller_size(<5 x float> %x) {
326 ; CHECK-LABEL: @splat_fcmp_smaller_size(
327 ; CHECK-NEXT: [[TMP1:%.*]] = fcmp oeq <5 x float> [[X:%.*]], <float 4.200000e+01, float 4.200000e+01, float 4.200000e+01, float 4.200000e+01, float 4.200000e+01>
328 ; CHECK-NEXT: [[CMP:%.*]] = shufflevector <5 x i1> [[TMP1]], <5 x i1> undef, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
329 ; CHECK-NEXT: ret <4 x i1> [[CMP]]
331 %splatx = shufflevector <5 x float> %x, <5 x float> undef, <4 x i32> <i32 1, i32 undef, i32 1, i32 undef>
332 %cmp = fcmp oeq <4 x float> %splatx, <float 42.0, float 42.0, float undef, float 42.0>
338 define <4 x i1> @splat_icmp_extra_use(<4 x i8> %x) {
339 ; CHECK-LABEL: @splat_icmp_extra_use(
340 ; CHECK-NEXT: [[SPLATX:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
341 ; CHECK-NEXT: call void @use_v4i8(<4 x i8> [[SPLATX]])
342 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <4 x i8> [[SPLATX]], <i8 42, i8 42, i8 42, i8 42>
343 ; CHECK-NEXT: ret <4 x i1> [[CMP]]
345 %splatx = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
346 call void @use_v4i8(<4 x i8> %splatx)
347 %cmp = icmp sgt <4 x i8> %splatx, <i8 42, i8 42, i8 42, i8 42>
353 define <4 x i1> @not_splat_icmp(<4 x i8> %x) {
354 ; CHECK-LABEL: @not_splat_icmp(
355 ; CHECK-NEXT: [[SPLATX:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> undef, <4 x i32> <i32 3, i32 2, i32 3, i32 3>
356 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <4 x i8> [[SPLATX]], <i8 42, i8 42, i8 42, i8 42>
357 ; CHECK-NEXT: ret <4 x i1> [[CMP]]
359 %splatx = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> <i32 3, i32 2, i32 3, i32 3>
360 %cmp = icmp sgt <4 x i8> %splatx, <i8 42, i8 42, i8 42, i8 42>
366 define <4 x i1> @not_splat_icmp2(<4 x i8> %x) {
367 ; CHECK-LABEL: @not_splat_icmp2(
368 ; CHECK-NEXT: [[SPLATX:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> undef, <4 x i32> <i32 2, i32 2, i32 2, i32 2>
369 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <4 x i8> [[SPLATX]], <i8 43, i8 42, i8 42, i8 42>
370 ; CHECK-NEXT: ret <4 x i1> [[CMP]]
372 %splatx = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> <i32 2, i32 2, i32 2, i32 2>
373 %cmp = icmp sgt <4 x i8> %splatx, <i8 43, i8 42, i8 42, i8 42>
377 ; Check that we don't absorb the compare into the select, which is in the
378 ; canonical form of logical or.
379 define <2 x i1> @icmp_logical_or_vec(<2 x i64> %x, <2 x i64> %y, <2 x i1> %falseval) {
380 ; CHECK-LABEL: @icmp_logical_or_vec(
381 ; CHECK-NEXT: [[CMP_NE:%.*]] = icmp ne <2 x i64> [[X:%.*]], zeroinitializer
382 ; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[CMP_NE]], <2 x i1> <i1 true, i1 true>, <2 x i1> [[FALSEVAL:%.*]]
383 ; CHECK-NEXT: ret <2 x i1> [[SEL]]
385 %cmp.ne = icmp ne <2 x i64> %x, zeroinitializer
386 %sel = select <2 x i1> %cmp.ne, <2 x i1> shufflevector (<2 x i1> insertelement (<2 x i1> undef, i1 true, i32 0), <2 x i1> undef, <2 x i32> zeroinitializer), <2 x i1> %falseval
390 ; The above, but for scalable vectors. Absorbing the compare into the select
391 ; and breaking the canonical form led to an infinite loop.
392 define <vscale x 2 x i1> @icmp_logical_or_scalablevec(<vscale x 2 x i64> %x, <vscale x 2 x i64> %y, <vscale x 2 x i1> %falseval) {
393 ; CHECK-LABEL: @icmp_logical_or_scalablevec(
394 ; CHECK-NEXT: [[CMP_NE:%.*]] = icmp ne <vscale x 2 x i64> [[X:%.*]], zeroinitializer
395 ; CHECK-NEXT: [[SEL:%.*]] = select <vscale x 2 x i1> [[CMP_NE]], <vscale x 2 x i1> shufflevector (<vscale x 2 x i1> insertelement (<vscale x 2 x i1> undef, i1 true, i32 0), <vscale x 2 x i1> undef, <vscale x 2 x i32> zeroinitializer), <vscale x 2 x i1> [[FALSEVAL:%.*]]
396 ; CHECK-NEXT: ret <vscale x 2 x i1> [[SEL]]
398 %cmp.ne = icmp ne <vscale x 2 x i64> %x, zeroinitializer
399 %sel = select <vscale x 2 x i1> %cmp.ne, <vscale x 2 x i1> shufflevector (<vscale x 2 x i1> insertelement (<vscale x 2 x i1> undef, i1 true, i32 0), <vscale x 2 x i1> undef, <vscale x 2 x i32> zeroinitializer), <vscale x 2 x i1> %falseval
400 ret <vscale x 2 x i1> %sel
403 define i1 @eq_cast_eq-1(<2 x i4> %x, <2 x i4> %y) {
404 ; CHECK-LABEL: @eq_cast_eq-1(
405 ; CHECK-NEXT: [[IC:%.*]] = icmp ne <2 x i4> [[X:%.*]], [[Y:%.*]]
406 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i1> [[IC]] to i2
407 ; CHECK-NEXT: [[R:%.*]] = icmp eq i2 [[TMP1]], 0
408 ; CHECK-NEXT: ret i1 [[R]]
410 %ic = icmp eq <2 x i4> %x, %y
411 %b = bitcast <2 x i1> %ic to i2
412 %r = icmp eq i2 %b, -1
416 define i1 @ne_cast_eq-1(<3 x i7> %x, <3 x i7> %y) {
417 ; CHECK-LABEL: @ne_cast_eq-1(
418 ; CHECK-NEXT: [[IC:%.*]] = icmp eq <3 x i7> [[X:%.*]], [[Y:%.*]]
419 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <3 x i1> [[IC]] to i3
420 ; CHECK-NEXT: [[R:%.*]] = icmp eq i3 [[TMP1]], 0
421 ; CHECK-NEXT: ret i1 [[R]]
423 %ic = icmp ne <3 x i7> %x, %y
424 %b = bitcast <3 x i1> %ic to i3
425 %r = icmp eq i3 %b, -1
429 define i1 @eq_cast_ne-1(<2 x i7> %x, <2 x i7> %y) {
430 ; CHECK-LABEL: @eq_cast_ne-1(
431 ; CHECK-NEXT: [[IC:%.*]] = icmp ne <2 x i7> [[X:%.*]], [[Y:%.*]]
432 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i1> [[IC]] to i2
433 ; CHECK-NEXT: [[R:%.*]] = icmp ne i2 [[TMP1]], 0
434 ; CHECK-NEXT: ret i1 [[R]]
436 %ic = icmp eq <2 x i7> %x, %y
437 %b = bitcast <2 x i1> %ic to i2
438 %r = icmp ne i2 %b, -1
442 define i1 @ne_cast_ne-1(<3 x i5> %x, <3 x i5> %y) {
443 ; CHECK-LABEL: @ne_cast_ne-1(
444 ; CHECK-NEXT: [[IC:%.*]] = icmp eq <3 x i5> [[X:%.*]], [[Y:%.*]]
445 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <3 x i1> [[IC]] to i3
446 ; CHECK-NEXT: [[R:%.*]] = icmp ne i3 [[TMP1]], 0
447 ; CHECK-NEXT: ret i1 [[R]]
449 %ic = icmp ne <3 x i5> %x, %y
450 %b = bitcast <3 x i1> %ic to i3
451 %r = icmp ne i3 %b, -1
455 define i1 @ugt_cast_eq-1(<2 x i4> %x, <2 x i4> %y) {
456 ; CHECK-LABEL: @ugt_cast_eq-1(
457 ; CHECK-NEXT: [[IC:%.*]] = icmp ule <2 x i4> [[X:%.*]], [[Y:%.*]]
458 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i1> [[IC]] to i2
459 ; CHECK-NEXT: [[R:%.*]] = icmp eq i2 [[TMP1]], 0
460 ; CHECK-NEXT: ret i1 [[R]]
462 %ic = icmp ugt <2 x i4> %x, %y
463 %b = bitcast <2 x i1> %ic to i2
464 %r = icmp eq i2 %b, -1
468 define i1 @slt_cast_ne-1(<2 x i4> %x, <2 x i4> %y) {
469 ; CHECK-LABEL: @slt_cast_ne-1(
470 ; CHECK-NEXT: [[IC:%.*]] = icmp sge <2 x i4> [[X:%.*]], [[Y:%.*]]
471 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i1> [[IC]] to i2
472 ; CHECK-NEXT: [[R:%.*]] = icmp ne i2 [[TMP1]], 0
473 ; CHECK-NEXT: ret i1 [[R]]
475 %ic = icmp slt <2 x i4> %x, %y
476 %b = bitcast <2 x i1> %ic to i2
477 %r = icmp ne i2 %b, -1
481 define i1 @ueq_cast_eq-1(<3 x float> %x, <3 x float> %y) {
482 ; CHECK-LABEL: @ueq_cast_eq-1(
483 ; CHECK-NEXT: [[FC:%.*]] = fcmp one <3 x float> [[X:%.*]], [[Y:%.*]]
484 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <3 x i1> [[FC]] to i3
485 ; CHECK-NEXT: [[R:%.*]] = icmp eq i3 [[TMP1]], 0
486 ; CHECK-NEXT: ret i1 [[R]]
488 %fc = fcmp ueq <3 x float> %x, %y
489 %b = bitcast <3 x i1> %fc to i3
490 %r = icmp eq i3 %b, -1
494 define i1 @not_cast_ne-1(<3 x i1> %x) {
495 ; CHECK-LABEL: @not_cast_ne-1(
496 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <3 x i1> [[X:%.*]] to i3
497 ; CHECK-NEXT: [[R:%.*]] = icmp ne i3 [[TMP1]], 0
498 ; CHECK-NEXT: ret i1 [[R]]
500 %not = xor <3 x i1> %x, <i1 -1, i1 -1, i1 -1>
501 %b = bitcast <3 x i1> %not to i3
502 %r = icmp ne i3 %b, -1
506 define i1 @not_cast_ne-1_uses(<3 x i2> %x, <3 x i2>* %p) {
507 ; CHECK-LABEL: @not_cast_ne-1_uses(
508 ; CHECK-NEXT: [[NOT:%.*]] = xor <3 x i2> [[X:%.*]], <i2 -1, i2 -1, i2 -1>
509 ; CHECK-NEXT: store <3 x i2> [[NOT]], <3 x i2>* [[P:%.*]], align 1
510 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <3 x i2> [[X]] to i6
511 ; CHECK-NEXT: [[R:%.*]] = icmp ne i6 [[TMP1]], 0
512 ; CHECK-NEXT: ret i1 [[R]]
514 %not = xor <3 x i2> %x, <i2 -1, i2 -1, i2 -1>
515 store <3 x i2> %not, <3 x i2>* %p
516 %b = bitcast <3 x i2> %not to i6
517 %r = icmp ne i6 %b, -1
521 ; negative test - need equality pred on 2nd cmp
523 define i1 @eq_cast_sgt-1(<3 x i4> %x, <3 x i4> %y) {
524 ; CHECK-LABEL: @eq_cast_sgt-1(
525 ; CHECK-NEXT: [[IC:%.*]] = icmp eq <3 x i4> [[X:%.*]], [[Y:%.*]]
526 ; CHECK-NEXT: [[B:%.*]] = bitcast <3 x i1> [[IC]] to i3
527 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i3 [[B]], -1
528 ; CHECK-NEXT: ret i1 [[R]]
530 %ic = icmp eq <3 x i4> %x, %y
531 %b = bitcast <3 x i1> %ic to i3
532 %r = icmp sgt i3 %b, -1
536 ; negative test - need all-ones constant on 2nd cmp
538 define i1 @eq_cast_eq1(<2 x i4> %x, <2 x i4> %y) {
539 ; CHECK-LABEL: @eq_cast_eq1(
540 ; CHECK-NEXT: [[IC:%.*]] = icmp eq <2 x i4> [[X:%.*]], [[Y:%.*]]
541 ; CHECK-NEXT: [[B:%.*]] = bitcast <2 x i1> [[IC]] to i2
542 ; CHECK-NEXT: [[R:%.*]] = icmp eq i2 [[B]], 1
543 ; CHECK-NEXT: ret i1 [[R]]
545 %ic = icmp eq <2 x i4> %x, %y
546 %b = bitcast <2 x i1> %ic to i2
547 %r = icmp eq i2 %b, 1
551 ; negative test - extra use
553 define i1 @eq_cast_eq-1_use1(<2 x i4> %x, <2 x i4> %y, <2 x i1>* %p) {
554 ; CHECK-LABEL: @eq_cast_eq-1_use1(
555 ; CHECK-NEXT: [[IC:%.*]] = icmp sgt <2 x i4> [[X:%.*]], [[Y:%.*]]
556 ; CHECK-NEXT: store <2 x i1> [[IC]], <2 x i1>* [[P:%.*]], align 1
557 ; CHECK-NEXT: [[B:%.*]] = bitcast <2 x i1> [[IC]] to i2
558 ; CHECK-NEXT: [[R:%.*]] = icmp eq i2 [[B]], -1
559 ; CHECK-NEXT: ret i1 [[R]]
561 %ic = icmp sgt <2 x i4> %x, %y
562 store <2 x i1> %ic, <2 x i1>* %p
563 %b = bitcast <2 x i1> %ic to i2
564 %r = icmp eq i2 %b, -1
568 ; negative test - extra use
570 define i1 @eq_cast_eq-1_use2(<2 x i4> %x, <2 x i4> %y, i2* %p) {
571 ; CHECK-LABEL: @eq_cast_eq-1_use2(
572 ; CHECK-NEXT: [[IC:%.*]] = icmp sgt <2 x i4> [[X:%.*]], [[Y:%.*]]
573 ; CHECK-NEXT: [[B:%.*]] = bitcast <2 x i1> [[IC]] to i2
574 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast i2* [[P:%.*]] to <2 x i1>*
575 ; CHECK-NEXT: store <2 x i1> [[IC]], <2 x i1>* [[TMP1]], align 1
576 ; CHECK-NEXT: [[R:%.*]] = icmp eq i2 [[B]], -1
577 ; CHECK-NEXT: ret i1 [[R]]
579 %ic = icmp sgt <2 x i4> %x, %y
580 %b = bitcast <2 x i1> %ic to i2
582 %r = icmp eq i2 %b, -1
586 define i1 @ne_cast_sext(<3 x i1> %b) {
587 ; CHECK-LABEL: @ne_cast_sext(
588 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <3 x i1> [[B:%.*]] to i3
589 ; CHECK-NEXT: [[R:%.*]] = icmp ne i3 [[TMP1]], 0
590 ; CHECK-NEXT: ret i1 [[R]]
592 %e = sext <3 x i1> %b to <3 x i8>
593 %bc = bitcast <3 x i8> %e to i24
594 %r = icmp ne i24 %bc, 0
598 define i1 @eq_cast_sext(<8 x i3> %b) {
599 ; CHECK-LABEL: @eq_cast_sext(
600 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <8 x i3> [[B:%.*]] to i24
601 ; CHECK-NEXT: [[R:%.*]] = icmp eq i24 [[TMP1]], 0
602 ; CHECK-NEXT: ret i1 [[R]]
604 %e = sext <8 x i3> %b to <8 x i8>
605 %bc = bitcast <8 x i8> %e to i64
606 %r = icmp eq i64 %bc, 0
610 define i1 @ne_cast_zext(<4 x i1> %b) {
611 ; CHECK-LABEL: @ne_cast_zext(
612 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i1> [[B:%.*]] to i4
613 ; CHECK-NEXT: [[R:%.*]] = icmp ne i4 [[TMP1]], 0
614 ; CHECK-NEXT: ret i1 [[R]]
616 %e = zext <4 x i1> %b to <4 x i8>
617 %bc = bitcast <4 x i8> %e to i32
618 %r = icmp ne i32 %bc, 0
622 define i1 @eq_cast_zext(<5 x i3> %b) {
623 ; CHECK-LABEL: @eq_cast_zext(
624 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <5 x i3> [[B:%.*]] to i15
625 ; CHECK-NEXT: [[R:%.*]] = icmp eq i15 [[TMP1]], 0
626 ; CHECK-NEXT: ret i1 [[R]]
628 %e = zext <5 x i3> %b to <5 x i7>
629 %bc = bitcast <5 x i7> %e to i35
630 %r = icmp eq i35 %bc, 0
634 ; negative test - valid for eq/ne only
636 define i1 @sgt_cast_zext(<5 x i3> %b) {
637 ; CHECK-LABEL: @sgt_cast_zext(
638 ; CHECK-NEXT: [[E:%.*]] = zext <5 x i3> [[B:%.*]] to <5 x i7>
639 ; CHECK-NEXT: [[BC:%.*]] = bitcast <5 x i7> [[E]] to i35
640 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i35 [[BC]], 0
641 ; CHECK-NEXT: ret i1 [[R]]
643 %e = zext <5 x i3> %b to <5 x i7>
644 %bc = bitcast <5 x i7> %e to i35
645 %r = icmp sgt i35 %bc, 0
649 ; negative test - not valid with non-zero constants
650 ; TODO: We could handle some non-zero constants by checking for bit-loss after casts.
652 define i1 @eq7_cast_sext(<5 x i3> %b) {
653 ; CHECK-LABEL: @eq7_cast_sext(
654 ; CHECK-NEXT: [[E:%.*]] = sext <5 x i3> [[B:%.*]] to <5 x i7>
655 ; CHECK-NEXT: [[BC:%.*]] = bitcast <5 x i7> [[E]] to i35
656 ; CHECK-NEXT: [[R:%.*]] = icmp eq i35 [[BC]], 7
657 ; CHECK-NEXT: ret i1 [[R]]
659 %e = sext <5 x i3> %b to <5 x i7>
660 %bc = bitcast <5 x i7> %e to i35
661 %r = icmp eq i35 %bc, 7
665 ; extra use of extend is ok
667 define i1 @eq_cast_zext_use1(<5 x i3> %b, <5 x i7>* %p) {
668 ; CHECK-LABEL: @eq_cast_zext_use1(
669 ; CHECK-NEXT: [[E:%.*]] = zext <5 x i3> [[B:%.*]] to <5 x i7>
670 ; CHECK-NEXT: store <5 x i7> [[E]], <5 x i7>* [[P:%.*]], align 8
671 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <5 x i3> [[B]] to i15
672 ; CHECK-NEXT: [[R:%.*]] = icmp eq i15 [[TMP1]], 0
673 ; CHECK-NEXT: ret i1 [[R]]
675 %e = zext <5 x i3> %b to <5 x i7>
676 store <5 x i7> %e, <5 x i7>* %p
677 %bc = bitcast <5 x i7> %e to i35
678 %r = icmp eq i35 %bc, 0
682 ; negative test - don't create an extra cast
684 declare void @use35(i35)
686 define i1 @eq_cast_zext_use2(<5 x i3> %b) {
687 ; CHECK-LABEL: @eq_cast_zext_use2(
688 ; CHECK-NEXT: [[E:%.*]] = zext <5 x i3> [[B:%.*]] to <5 x i7>
689 ; CHECK-NEXT: [[BC:%.*]] = bitcast <5 x i7> [[E]] to i35
690 ; CHECK-NEXT: call void @use35(i35 [[BC]])
691 ; CHECK-NEXT: [[R:%.*]] = icmp eq i35 [[BC]], 0
692 ; CHECK-NEXT: ret i1 [[R]]
694 %e = zext <5 x i3> %b to <5 x i7>
695 %bc = bitcast <5 x i7> %e to i35
696 call void @use35(i35 %bc)
697 %r = icmp eq i35 %bc, 0