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 <2 x i1> @PR27756_2(<2 x i8> %a) {
183 ; CHECK-LABEL: @PR27756_2(
184 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[A:%.*]], <i8 undef, i8 1>
185 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
187 %cmp = icmp sle <2 x i8> %a, <i8 undef, i8 0>
191 @someglobal = global i32 0
193 define <2 x i1> @PR27786(<2 x i8> %a) {
194 ; CHECK-LABEL: @PR27786(
195 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle <2 x i8> [[A:%.*]], bitcast (i16 ptrtoint (i32* @someglobal to i16) to <2 x i8>)
196 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
198 %cmp = icmp sle <2 x i8> %a, bitcast (i16 ptrtoint (i32* @someglobal to i16) to <2 x i8>)
202 ; This is similar to a transform for shuffled binops: compare first, shuffle after.
204 define <4 x i1> @same_shuffle_inputs_icmp(<4 x i8> %x, <4 x i8> %y) {
205 ; CHECK-LABEL: @same_shuffle_inputs_icmp(
206 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <4 x i8> [[X:%.*]], [[Y:%.*]]
207 ; CHECK-NEXT: [[CMP:%.*]] = shufflevector <4 x i1> [[TMP1]], <4 x i1> undef, <4 x i32> <i32 3, i32 3, i32 2, i32 0>
208 ; CHECK-NEXT: ret <4 x i1> [[CMP]]
210 %shufx = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> < i32 3, i32 3, i32 2, i32 0 >
211 %shufy = shufflevector <4 x i8> %y, <4 x i8> undef, <4 x i32> < i32 3, i32 3, i32 2, i32 0 >
212 %cmp = icmp sgt <4 x i8> %shufx, %shufy
216 ; fcmp and size-changing shuffles are ok too.
218 define <5 x i1> @same_shuffle_inputs_fcmp(<4 x float> %x, <4 x float> %y) {
219 ; CHECK-LABEL: @same_shuffle_inputs_fcmp(
220 ; CHECK-NEXT: [[TMP1:%.*]] = fcmp oeq <4 x float> [[X:%.*]], [[Y:%.*]]
221 ; 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>
222 ; CHECK-NEXT: ret <5 x i1> [[CMP]]
224 %shufx = shufflevector <4 x float> %x, <4 x float> undef, <5 x i32> < i32 0, i32 1, i32 3, i32 2, i32 0 >
225 %shufy = shufflevector <4 x float> %y, <4 x float> undef, <5 x i32> < i32 0, i32 1, i32 3, i32 2, i32 0 >
226 %cmp = fcmp oeq <5 x float> %shufx, %shufy
230 declare void @use_v4i8(<4 x i8>)
232 define <4 x i1> @same_shuffle_inputs_icmp_extra_use1(<4 x i8> %x, <4 x i8> %y) {
233 ; CHECK-LABEL: @same_shuffle_inputs_icmp_extra_use1(
234 ; CHECK-NEXT: [[SHUFX:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
235 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <4 x i8> [[X]], [[Y:%.*]]
236 ; CHECK-NEXT: [[CMP:%.*]] = shufflevector <4 x i1> [[TMP1]], <4 x i1> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
237 ; CHECK-NEXT: call void @use_v4i8(<4 x i8> [[SHUFX]])
238 ; CHECK-NEXT: ret <4 x i1> [[CMP]]
240 %shufx = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> < i32 3, i32 3, i32 3, i32 3 >
241 %shufy = shufflevector <4 x i8> %y, <4 x i8> undef, <4 x i32> < i32 3, i32 3, i32 3, i32 3 >
242 %cmp = icmp ugt <4 x i8> %shufx, %shufy
243 call void @use_v4i8(<4 x i8> %shufx)
247 declare void @use_v2i8(<2 x i8>)
249 define <2 x i1> @same_shuffle_inputs_icmp_extra_use2(<4 x i8> %x, <4 x i8> %y) {
250 ; CHECK-LABEL: @same_shuffle_inputs_icmp_extra_use2(
251 ; CHECK-NEXT: [[SHUFY:%.*]] = shufflevector <4 x i8> [[Y:%.*]], <4 x i8> undef, <2 x i32> <i32 3, i32 2>
252 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <4 x i8> [[X:%.*]], [[Y]]
253 ; CHECK-NEXT: [[CMP:%.*]] = shufflevector <4 x i1> [[TMP1]], <4 x i1> undef, <2 x i32> <i32 3, i32 2>
254 ; CHECK-NEXT: call void @use_v2i8(<2 x i8> [[SHUFY]])
255 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
257 %shufx = shufflevector <4 x i8> %x, <4 x i8> undef, <2 x i32> < i32 3, i32 2 >
258 %shufy = shufflevector <4 x i8> %y, <4 x i8> undef, <2 x i32> < i32 3, i32 2 >
259 %cmp = icmp eq <2 x i8> %shufx, %shufy
260 call void @use_v2i8(<2 x i8> %shufy)
264 ; Negative test: if both shuffles have extra uses, don't transform because that would increase instruction count.
266 define <2 x i1> @same_shuffle_inputs_icmp_extra_use3(<4 x i8> %x, <4 x i8> %y) {
267 ; CHECK-LABEL: @same_shuffle_inputs_icmp_extra_use3(
268 ; CHECK-NEXT: [[SHUFX:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> undef, <2 x i32> zeroinitializer
269 ; CHECK-NEXT: [[SHUFY:%.*]] = shufflevector <4 x i8> [[Y:%.*]], <4 x i8> undef, <2 x i32> zeroinitializer
270 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[SHUFX]], [[SHUFY]]
271 ; CHECK-NEXT: call void @use_v2i8(<2 x i8> [[SHUFX]])
272 ; CHECK-NEXT: call void @use_v2i8(<2 x i8> [[SHUFY]])
273 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
275 %shufx = shufflevector <4 x i8> %x, <4 x i8> undef, <2 x i32> < i32 0, i32 0 >
276 %shufy = shufflevector <4 x i8> %y, <4 x i8> undef, <2 x i32> < i32 0, i32 0 >
277 %cmp = icmp eq <2 x i8> %shufx, %shufy
278 call void @use_v2i8(<2 x i8> %shufx)
279 call void @use_v2i8(<2 x i8> %shufy)