1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 declare void @use32(i32)
6 ; Widen a select of constants to eliminate an extend.
8 define i16 @sel_sext_constants(i1 %cmp) {
9 ; CHECK-LABEL: @sel_sext_constants(
10 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], i16 -1, i16 42
11 ; CHECK-NEXT: ret i16 [[EXT]]
13 %sel = select i1 %cmp, i8 255, i8 42
14 %ext = sext i8 %sel to i16
18 define i16 @sel_zext_constants(i1 %cmp) {
19 ; CHECK-LABEL: @sel_zext_constants(
20 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], i16 255, i16 42
21 ; CHECK-NEXT: ret i16 [[EXT]]
23 %sel = select i1 %cmp, i8 255, i8 42
24 %ext = zext i8 %sel to i16
28 define double @sel_fpext_constants(i1 %cmp) {
29 ; CHECK-LABEL: @sel_fpext_constants(
30 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], double -2.550000e+02, double 4.200000e+01
31 ; CHECK-NEXT: ret double [[EXT]]
33 %sel = select i1 %cmp, float -255.0, float 42.0
34 %ext = fpext float %sel to double
38 ; FIXME: We should not grow the size of the select in the next 4 cases.
40 define i64 @sel_sext(i32 %a, i1 %cmp) {
41 ; CHECK-LABEL: @sel_sext(
42 ; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[A:%.*]] to i64
43 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], i64 [[TMP1]], i64 42
44 ; CHECK-NEXT: ret i64 [[EXT]]
46 %sel = select i1 %cmp, i32 %a, i32 42
47 %ext = sext i32 %sel to i64
51 define <4 x i64> @sel_sext_vec(<4 x i32> %a, <4 x i1> %cmp) {
52 ; CHECK-LABEL: @sel_sext_vec(
53 ; CHECK-NEXT: [[TMP1:%.*]] = sext <4 x i32> [[A:%.*]] to <4 x i64>
54 ; CHECK-NEXT: [[EXT:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i64> [[TMP1]], <4 x i64> <i64 42, i64 42, i64 42, i64 42>
55 ; CHECK-NEXT: ret <4 x i64> [[EXT]]
57 %sel = select <4 x i1> %cmp, <4 x i32> %a, <4 x i32> <i32 42, i32 42, i32 42, i32 42>
58 %ext = sext <4 x i32> %sel to <4 x i64>
62 define i64 @sel_zext(i32 %a, i1 %cmp) {
63 ; CHECK-LABEL: @sel_zext(
64 ; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[A:%.*]] to i64
65 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], i64 [[TMP1]], i64 42
66 ; CHECK-NEXT: ret i64 [[EXT]]
68 %sel = select i1 %cmp, i32 %a, i32 42
69 %ext = zext i32 %sel to i64
73 define <4 x i64> @sel_zext_vec(<4 x i32> %a, <4 x i1> %cmp) {
74 ; CHECK-LABEL: @sel_zext_vec(
75 ; CHECK-NEXT: [[TMP1:%.*]] = zext <4 x i32> [[A:%.*]] to <4 x i64>
76 ; CHECK-NEXT: [[EXT:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i64> [[TMP1]], <4 x i64> <i64 42, i64 42, i64 42, i64 42>
77 ; CHECK-NEXT: ret <4 x i64> [[EXT]]
79 %sel = select <4 x i1> %cmp, <4 x i32> %a, <4 x i32> <i32 42, i32 42, i32 42, i32 42>
80 %ext = zext <4 x i32> %sel to <4 x i64>
84 ; FIXME: The next 18 tests cycle through trunc+select and {larger,smaller,equal} {sext,zext,fpext} {scalar,vector}.
85 ; The only cases where we eliminate an instruction are equal zext with scalar/vector, so that's probably the only
86 ; way to justify widening the select.
88 define i64 @trunc_sel_larger_sext(i32 %a, i1 %cmp) {
89 ; CHECK-LABEL: @trunc_sel_larger_sext(
90 ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 [[A:%.*]] to i16
91 ; CHECK-NEXT: [[TMP1:%.*]] = sext i16 [[TRUNC]] to i64
92 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], i64 [[TMP1]], i64 42
93 ; CHECK-NEXT: ret i64 [[EXT]]
95 %trunc = trunc i32 %a to i16
96 %sel = select i1 %cmp, i16 %trunc, i16 42
97 %ext = sext i16 %sel to i64
101 define <2 x i64> @trunc_sel_larger_sext_vec(<2 x i32> %a, <2 x i1> %cmp) {
102 ; CHECK-LABEL: @trunc_sel_larger_sext_vec(
103 ; CHECK-NEXT: [[TRUNC:%.*]] = trunc <2 x i32> [[A:%.*]] to <2 x i16>
104 ; CHECK-NEXT: [[TMP1:%.*]] = sext <2 x i16> [[TRUNC]] to <2 x i64>
105 ; CHECK-NEXT: [[EXT:%.*]] = select <2 x i1> [[CMP:%.*]], <2 x i64> [[TMP1]], <2 x i64> <i64 42, i64 43>
106 ; CHECK-NEXT: ret <2 x i64> [[EXT]]
108 %trunc = trunc <2 x i32> %a to <2 x i16>
109 %sel = select <2 x i1> %cmp, <2 x i16> %trunc, <2 x i16> <i16 42, i16 43>
110 %ext = sext <2 x i16> %sel to <2 x i64>
114 define i32 @trunc_sel_smaller_sext(i64 %a, i1 %cmp) {
115 ; CHECK-LABEL: @trunc_sel_smaller_sext(
116 ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 [[A:%.*]] to i16
117 ; CHECK-NEXT: [[TMP1:%.*]] = sext i16 [[TRUNC]] to i32
118 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], i32 [[TMP1]], i32 42
119 ; CHECK-NEXT: ret i32 [[EXT]]
121 %trunc = trunc i64 %a to i16
122 %sel = select i1 %cmp, i16 %trunc, i16 42
123 %ext = sext i16 %sel to i32
127 define <2 x i32> @trunc_sel_smaller_sext_vec(<2 x i64> %a, <2 x i1> %cmp) {
128 ; CHECK-LABEL: @trunc_sel_smaller_sext_vec(
129 ; CHECK-NEXT: [[TRUNC:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i16>
130 ; CHECK-NEXT: [[TMP1:%.*]] = sext <2 x i16> [[TRUNC]] to <2 x i32>
131 ; CHECK-NEXT: [[EXT:%.*]] = select <2 x i1> [[CMP:%.*]], <2 x i32> [[TMP1]], <2 x i32> <i32 42, i32 43>
132 ; CHECK-NEXT: ret <2 x i32> [[EXT]]
134 %trunc = trunc <2 x i64> %a to <2 x i16>
135 %sel = select <2 x i1> %cmp, <2 x i16> %trunc, <2 x i16> <i16 42, i16 43>
136 %ext = sext <2 x i16> %sel to <2 x i32>
140 define i32 @trunc_sel_equal_sext(i32 %a, i1 %cmp) {
141 ; CHECK-LABEL: @trunc_sel_equal_sext(
142 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[A:%.*]], 16
143 ; CHECK-NEXT: [[TMP2:%.*]] = ashr exact i32 [[TMP1]], 16
144 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], i32 [[TMP2]], i32 42
145 ; CHECK-NEXT: ret i32 [[EXT]]
147 %trunc = trunc i32 %a to i16
148 %sel = select i1 %cmp, i16 %trunc, i16 42
149 %ext = sext i16 %sel to i32
153 define <2 x i32> @trunc_sel_equal_sext_vec(<2 x i32> %a, <2 x i1> %cmp) {
154 ; CHECK-LABEL: @trunc_sel_equal_sext_vec(
155 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[A:%.*]], <i32 16, i32 16>
156 ; CHECK-NEXT: [[TMP2:%.*]] = ashr exact <2 x i32> [[TMP1]], <i32 16, i32 16>
157 ; CHECK-NEXT: [[EXT:%.*]] = select <2 x i1> [[CMP:%.*]], <2 x i32> [[TMP2]], <2 x i32> <i32 42, i32 43>
158 ; CHECK-NEXT: ret <2 x i32> [[EXT]]
160 %trunc = trunc <2 x i32> %a to <2 x i16>
161 %sel = select <2 x i1> %cmp, <2 x i16> %trunc, <2 x i16> <i16 42, i16 43>
162 %ext = sext <2 x i16> %sel to <2 x i32>
166 define i64 @trunc_sel_larger_zext(i32 %a, i1 %cmp) {
167 ; CHECK-LABEL: @trunc_sel_larger_zext(
168 ; CHECK-NEXT: [[TRUNC_MASK:%.*]] = and i32 [[A:%.*]], 65535
169 ; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[TRUNC_MASK]] to i64
170 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], i64 [[TMP1]], i64 42
171 ; CHECK-NEXT: ret i64 [[EXT]]
173 %trunc = trunc i32 %a to i16
174 %sel = select i1 %cmp, i16 %trunc, i16 42
175 %ext = zext i16 %sel to i64
179 define <2 x i64> @trunc_sel_larger_zext_vec(<2 x i32> %a, <2 x i1> %cmp) {
180 ; CHECK-LABEL: @trunc_sel_larger_zext_vec(
181 ; CHECK-NEXT: [[TRUNC_MASK:%.*]] = and <2 x i32> [[A:%.*]], <i32 65535, i32 65535>
182 ; CHECK-NEXT: [[TMP1:%.*]] = zext <2 x i32> [[TRUNC_MASK]] to <2 x i64>
183 ; CHECK-NEXT: [[EXT:%.*]] = select <2 x i1> [[CMP:%.*]], <2 x i64> [[TMP1]], <2 x i64> <i64 42, i64 43>
184 ; CHECK-NEXT: ret <2 x i64> [[EXT]]
186 %trunc = trunc <2 x i32> %a to <2 x i16>
187 %sel = select <2 x i1> %cmp, <2 x i16> %trunc, <2 x i16> <i16 42, i16 43>
188 %ext = zext <2 x i16> %sel to <2 x i64>
192 define i32 @trunc_sel_smaller_zext(i64 %a, i1 %cmp) {
193 ; CHECK-LABEL: @trunc_sel_smaller_zext(
194 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[A:%.*]] to i32
195 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 65535
196 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], i32 [[TMP2]], i32 42
197 ; CHECK-NEXT: ret i32 [[EXT]]
199 %trunc = trunc i64 %a to i16
200 %sel = select i1 %cmp, i16 %trunc, i16 42
201 %ext = zext i16 %sel to i32
205 define <2 x i32> @trunc_sel_smaller_zext_vec(<2 x i64> %a, <2 x i1> %cmp) {
206 ; CHECK-LABEL: @trunc_sel_smaller_zext_vec(
207 ; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
208 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], <i32 65535, i32 65535>
209 ; CHECK-NEXT: [[EXT:%.*]] = select <2 x i1> [[CMP:%.*]], <2 x i32> [[TMP2]], <2 x i32> <i32 42, i32 43>
210 ; CHECK-NEXT: ret <2 x i32> [[EXT]]
212 %trunc = trunc <2 x i64> %a to <2 x i16>
213 %sel = select <2 x i1> %cmp, <2 x i16> %trunc, <2 x i16> <i16 42, i16 43>
214 %ext = zext <2 x i16> %sel to <2 x i32>
218 define i32 @trunc_sel_equal_zext(i32 %a, i1 %cmp) {
219 ; CHECK-LABEL: @trunc_sel_equal_zext(
220 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 65535
221 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], i32 [[TMP1]], i32 42
222 ; CHECK-NEXT: ret i32 [[EXT]]
224 %trunc = trunc i32 %a to i16
225 %sel = select i1 %cmp, i16 %trunc, i16 42
226 %ext = zext i16 %sel to i32
230 define <2 x i32> @trunc_sel_equal_zext_vec(<2 x i32> %a, <2 x i1> %cmp) {
231 ; CHECK-LABEL: @trunc_sel_equal_zext_vec(
232 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[A:%.*]], <i32 65535, i32 65535>
233 ; CHECK-NEXT: [[EXT:%.*]] = select <2 x i1> [[CMP:%.*]], <2 x i32> [[TMP1]], <2 x i32> <i32 42, i32 43>
234 ; CHECK-NEXT: ret <2 x i32> [[EXT]]
236 %trunc = trunc <2 x i32> %a to <2 x i16>
237 %sel = select <2 x i1> %cmp, <2 x i16> %trunc, <2 x i16> <i16 42, i16 43>
238 %ext = zext <2 x i16> %sel to <2 x i32>
242 define double @trunc_sel_larger_fpext(float %a, i1 %cmp) {
243 ; CHECK-LABEL: @trunc_sel_larger_fpext(
244 ; CHECK-NEXT: [[TRUNC:%.*]] = fptrunc float [[A:%.*]] to half
245 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[TRUNC]] to double
246 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], double [[TMP1]], double 4.200000e+01
247 ; CHECK-NEXT: ret double [[EXT]]
249 %trunc = fptrunc float %a to half
250 %sel = select i1 %cmp, half %trunc, half 42.0
251 %ext = fpext half %sel to double
255 define <2 x double> @trunc_sel_larger_fpext_vec(<2 x float> %a, <2 x i1> %cmp) {
256 ; CHECK-LABEL: @trunc_sel_larger_fpext_vec(
257 ; CHECK-NEXT: [[TRUNC:%.*]] = fptrunc <2 x float> [[A:%.*]] to <2 x half>
258 ; CHECK-NEXT: [[TMP1:%.*]] = fpext <2 x half> [[TRUNC]] to <2 x double>
259 ; CHECK-NEXT: [[EXT:%.*]] = select <2 x i1> [[CMP:%.*]], <2 x double> [[TMP1]], <2 x double> <double 4.200000e+01, double 4.300000e+01>
260 ; CHECK-NEXT: ret <2 x double> [[EXT]]
262 %trunc = fptrunc <2 x float> %a to <2 x half>
263 %sel = select <2 x i1> %cmp, <2 x half> %trunc, <2 x half> <half 42.0, half 43.0>
264 %ext = fpext <2 x half> %sel to <2 x double>
265 ret <2 x double> %ext
268 define float @trunc_sel_smaller_fpext(double %a, i1 %cmp) {
269 ; CHECK-LABEL: @trunc_sel_smaller_fpext(
270 ; CHECK-NEXT: [[TRUNC:%.*]] = fptrunc double [[A:%.*]] to half
271 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[TRUNC]] to float
272 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], float [[TMP1]], float 4.200000e+01
273 ; CHECK-NEXT: ret float [[EXT]]
275 %trunc = fptrunc double %a to half
276 %sel = select i1 %cmp, half %trunc, half 42.0
277 %ext = fpext half %sel to float
281 define <2 x float> @trunc_sel_smaller_fpext_vec(<2 x double> %a, <2 x i1> %cmp) {
282 ; CHECK-LABEL: @trunc_sel_smaller_fpext_vec(
283 ; CHECK-NEXT: [[TRUNC:%.*]] = fptrunc <2 x double> [[A:%.*]] to <2 x half>
284 ; CHECK-NEXT: [[TMP1:%.*]] = fpext <2 x half> [[TRUNC]] to <2 x float>
285 ; CHECK-NEXT: [[EXT:%.*]] = select <2 x i1> [[CMP:%.*]], <2 x float> [[TMP1]], <2 x float> <float 4.200000e+01, float 4.300000e+01>
286 ; CHECK-NEXT: ret <2 x float> [[EXT]]
288 %trunc = fptrunc <2 x double> %a to <2 x half>
289 %sel = select <2 x i1> %cmp, <2 x half> %trunc, <2 x half> <half 42.0, half 43.0>
290 %ext = fpext <2 x half> %sel to <2 x float>
294 define float @trunc_sel_equal_fpext(float %a, i1 %cmp) {
295 ; CHECK-LABEL: @trunc_sel_equal_fpext(
296 ; CHECK-NEXT: [[TRUNC:%.*]] = fptrunc float [[A:%.*]] to half
297 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[TRUNC]] to float
298 ; CHECK-NEXT: [[EXT:%.*]] = select i1 [[CMP:%.*]], float [[TMP1]], float 4.200000e+01
299 ; CHECK-NEXT: ret float [[EXT]]
301 %trunc = fptrunc float %a to half
302 %sel = select i1 %cmp, half %trunc, half 42.0
303 %ext = fpext half %sel to float
307 define <2 x float> @trunc_sel_equal_fpext_vec(<2 x float> %a, <2 x i1> %cmp) {
308 ; CHECK-LABEL: @trunc_sel_equal_fpext_vec(
309 ; CHECK-NEXT: [[TRUNC:%.*]] = fptrunc <2 x float> [[A:%.*]] to <2 x half>
310 ; CHECK-NEXT: [[TMP1:%.*]] = fpext <2 x half> [[TRUNC]] to <2 x float>
311 ; CHECK-NEXT: [[EXT:%.*]] = select <2 x i1> [[CMP:%.*]], <2 x float> [[TMP1]], <2 x float> <float 4.200000e+01, float 4.300000e+01>
312 ; CHECK-NEXT: ret <2 x float> [[EXT]]
314 %trunc = fptrunc <2 x float> %a to <2 x half>
315 %sel = select <2 x i1> %cmp, <2 x half> %trunc, <2 x half> <half 42.0, half 43.0>
316 %ext = fpext <2 x half> %sel to <2 x float>
320 define i32 @test_sext1(i1 %cca, i1 %ccb) {
321 ; CHECK-LABEL: @test_sext1(
322 ; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[CCB:%.*]], i1 [[CCA:%.*]], i1 false
323 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[NARROW]] to i32
324 ; CHECK-NEXT: ret i32 [[R]]
326 %ccax = sext i1 %cca to i32
327 %r = select i1 %ccb, i32 %ccax, i32 0
331 define i32 @test_sext2(i1 %cca, i1 %ccb) {
332 ; CHECK-LABEL: @test_sext2(
333 ; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[CCB:%.*]], i1 true, i1 [[CCA:%.*]]
334 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[NARROW]] to i32
335 ; CHECK-NEXT: ret i32 [[R]]
337 %ccax = sext i1 %cca to i32
338 %r = select i1 %ccb, i32 -1, i32 %ccax
342 define i32 @test_sext3(i1 %cca, i1 %ccb) {
343 ; CHECK-LABEL: @test_sext3(
344 ; CHECK-NEXT: [[NOT_CCB:%.*]] = xor i1 [[CCB:%.*]], true
345 ; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[NOT_CCB]], i1 [[CCA:%.*]], i1 false
346 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[NARROW]] to i32
347 ; CHECK-NEXT: ret i32 [[R]]
349 %ccax = sext i1 %cca to i32
350 %r = select i1 %ccb, i32 0, i32 %ccax
354 define i32 @test_sext4(i1 %cca, i1 %ccb) {
355 ; CHECK-LABEL: @test_sext4(
356 ; CHECK-NEXT: [[NOT_CCB:%.*]] = xor i1 [[CCB:%.*]], true
357 ; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[NOT_CCB]], i1 true, i1 [[CCA:%.*]]
358 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[NARROW]] to i32
359 ; CHECK-NEXT: ret i32 [[R]]
361 %ccax = sext i1 %cca to i32
362 %r = select i1 %ccb, i32 %ccax, i32 -1
366 define i32 @test_zext1(i1 %cca, i1 %ccb) {
367 ; CHECK-LABEL: @test_zext1(
368 ; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[CCB:%.*]], i1 [[CCA:%.*]], i1 false
369 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[NARROW]] to i32
370 ; CHECK-NEXT: ret i32 [[R]]
372 %ccax = zext i1 %cca to i32
373 %r = select i1 %ccb, i32 %ccax, i32 0
377 define i32 @test_zext2(i1 %cca, i1 %ccb) {
378 ; CHECK-LABEL: @test_zext2(
379 ; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[CCB:%.*]], i1 true, i1 [[CCA:%.*]]
380 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[NARROW]] to i32
381 ; CHECK-NEXT: ret i32 [[R]]
383 %ccax = zext i1 %cca to i32
384 %r = select i1 %ccb, i32 1, i32 %ccax
388 define i32 @test_zext3(i1 %cca, i1 %ccb) {
389 ; CHECK-LABEL: @test_zext3(
390 ; CHECK-NEXT: [[NOT_CCB:%.*]] = xor i1 [[CCB:%.*]], true
391 ; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[NOT_CCB]], i1 [[CCA:%.*]], i1 false
392 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[NARROW]] to i32
393 ; CHECK-NEXT: ret i32 [[R]]
395 %ccax = zext i1 %cca to i32
396 %r = select i1 %ccb, i32 0, i32 %ccax
400 define i32 @test_zext4(i1 %cca, i1 %ccb) {
401 ; CHECK-LABEL: @test_zext4(
402 ; CHECK-NEXT: [[NOT_CCB:%.*]] = xor i1 [[CCB:%.*]], true
403 ; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[NOT_CCB]], i1 true, i1 [[CCA:%.*]]
404 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[NARROW]] to i32
405 ; CHECK-NEXT: ret i32 [[R]]
407 %ccax = zext i1 %cca to i32
408 %r = select i1 %ccb, i32 %ccax, i32 1
412 define i32 @test_negative_sext(i1 %a, i1 %cc) {
413 ; CHECK-LABEL: @test_negative_sext(
414 ; CHECK-NEXT: [[A_EXT:%.*]] = sext i1 [[A:%.*]] to i32
415 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CC:%.*]], i32 [[A_EXT]], i32 1
416 ; CHECK-NEXT: ret i32 [[R]]
418 %a.ext = sext i1 %a to i32
419 %r = select i1 %cc, i32 %a.ext, i32 1
423 define i32 @test_negative_zext(i1 %a, i1 %cc) {
424 ; CHECK-LABEL: @test_negative_zext(
425 ; CHECK-NEXT: [[A_EXT:%.*]] = zext i1 [[A:%.*]] to i32
426 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CC:%.*]], i32 [[A_EXT]], i32 -1
427 ; CHECK-NEXT: ret i32 [[R]]
429 %a.ext = zext i1 %a to i32
430 %r = select i1 %cc, i32 %a.ext, i32 -1
434 define i32 @test_bits_sext(i8 %a, i1 %cc) {
435 ; CHECK-LABEL: @test_bits_sext(
436 ; CHECK-NEXT: [[A_EXT:%.*]] = sext i8 [[A:%.*]] to i32
437 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CC:%.*]], i32 [[A_EXT]], i32 -128
438 ; CHECK-NEXT: ret i32 [[R]]
440 %a.ext = sext i8 %a to i32
441 %r = select i1 %cc, i32 %a.ext, i32 -128
445 define i32 @test_bits_zext(i8 %a, i1 %cc) {
446 ; CHECK-LABEL: @test_bits_zext(
447 ; CHECK-NEXT: [[A_EXT:%.*]] = zext i8 [[A:%.*]] to i32
448 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CC:%.*]], i32 [[A_EXT]], i32 255
449 ; CHECK-NEXT: ret i32 [[R]]
451 %a.ext = zext i8 %a to i32
452 %r = select i1 %cc, i32 %a.ext, i32 255
456 define i32 @sel_sext_const_uses(i8 %a, i8 %x) {
457 ; CHECK-LABEL: @sel_sext_const_uses(
458 ; CHECK-NEXT: [[COND:%.*]] = icmp ugt i8 [[X:%.*]], 15
459 ; CHECK-NEXT: [[A_EXT:%.*]] = sext i8 [[A:%.*]] to i32
460 ; CHECK-NEXT: call void @use32(i32 [[A_EXT]])
461 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND]], i32 [[A_EXT]], i32 127
462 ; CHECK-NEXT: ret i32 [[R]]
464 %cond = icmp ugt i8 %x, 15
465 %a.ext = sext i8 %a to i32
466 call void @use32(i32 %a.ext)
467 %r = select i1 %cond, i32 %a.ext, i32 127
471 define i32 @sel_zext_const_uses(i8 %a, i8 %x) {
472 ; CHECK-LABEL: @sel_zext_const_uses(
473 ; CHECK-NEXT: [[COND:%.*]] = icmp sgt i8 [[X:%.*]], 15
474 ; CHECK-NEXT: [[A_EXT:%.*]] = zext i8 [[A:%.*]] to i32
475 ; CHECK-NEXT: call void @use32(i32 [[A_EXT]])
476 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND]], i32 255, i32 [[A_EXT]]
477 ; CHECK-NEXT: ret i32 [[R]]
479 %cond = icmp sgt i8 %x, 15
480 %a.ext = zext i8 %a to i32
481 call void @use32(i32 %a.ext)
482 %r = select i1 %cond, i32 255, i32 %a.ext
486 define i32 @test_op_op(i32 %a, i32 %b, i32 %c) {
487 ; CHECK-LABEL: @test_op_op(
488 ; CHECK-NEXT: [[CCA:%.*]] = icmp sgt i32 [[A:%.*]], 0
489 ; CHECK-NEXT: [[CCB:%.*]] = icmp sgt i32 [[B:%.*]], 0
490 ; CHECK-NEXT: [[CCC:%.*]] = icmp sgt i32 [[C:%.*]], 0
491 ; CHECK-NEXT: [[R_V:%.*]] = select i1 [[CCC]], i1 [[CCA]], i1 [[CCB]]
492 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[R_V]] to i32
493 ; CHECK-NEXT: ret i32 [[R]]
495 %cca = icmp sgt i32 %a, 0
496 %ccax = sext i1 %cca to i32
497 %ccb = icmp sgt i32 %b, 0
498 %ccbx = sext i1 %ccb to i32
499 %ccc = icmp sgt i32 %c, 0
500 %r = select i1 %ccc, i32 %ccax, i32 %ccbx
504 define <2 x i32> @test_vectors_sext(<2 x i1> %cca, <2 x i1> %ccb) {
505 ; CHECK-LABEL: @test_vectors_sext(
506 ; CHECK-NEXT: [[NARROW:%.*]] = select <2 x i1> [[CCB:%.*]], <2 x i1> [[CCA:%.*]], <2 x i1> zeroinitializer
507 ; CHECK-NEXT: [[R:%.*]] = sext <2 x i1> [[NARROW]] to <2 x i32>
508 ; CHECK-NEXT: ret <2 x i32> [[R]]
510 %ccax = sext <2 x i1> %cca to <2 x i32>
511 %r = select <2 x i1> %ccb, <2 x i32> %ccax, <2 x i32> <i32 0, i32 0>
515 define <2 x i32> @test_vectors_sext_nonsplat(<2 x i1> %cca, <2 x i1> %ccb) {
516 ; CHECK-LABEL: @test_vectors_sext_nonsplat(
517 ; CHECK-NEXT: [[NARROW:%.*]] = select <2 x i1> [[CCB:%.*]], <2 x i1> [[CCA:%.*]], <2 x i1> <i1 false, i1 true>
518 ; CHECK-NEXT: [[R:%.*]] = sext <2 x i1> [[NARROW]] to <2 x i32>
519 ; CHECK-NEXT: ret <2 x i32> [[R]]
521 %ccax = sext <2 x i1> %cca to <2 x i32>
522 %r = select <2 x i1> %ccb, <2 x i32> %ccax, <2 x i32> <i32 0, i32 -1>
526 define <2 x i32> @test_vectors_zext(<2 x i1> %cca, <2 x i1> %ccb) {
527 ; CHECK-LABEL: @test_vectors_zext(
528 ; CHECK-NEXT: [[NARROW:%.*]] = select <2 x i1> [[CCB:%.*]], <2 x i1> [[CCA:%.*]], <2 x i1> zeroinitializer
529 ; CHECK-NEXT: [[R:%.*]] = zext <2 x i1> [[NARROW]] to <2 x i32>
530 ; CHECK-NEXT: ret <2 x i32> [[R]]
532 %ccax = zext <2 x i1> %cca to <2 x i32>
533 %r = select <2 x i1> %ccb, <2 x i32> %ccax, <2 x i32> <i32 0, i32 0>
537 define <2 x i32> @test_vectors_zext_nonsplat(<2 x i1> %cca, <2 x i1> %ccb) {
538 ; CHECK-LABEL: @test_vectors_zext_nonsplat(
539 ; CHECK-NEXT: [[NARROW:%.*]] = select <2 x i1> [[CCB:%.*]], <2 x i1> [[CCA:%.*]], <2 x i1> <i1 true, i1 false>
540 ; CHECK-NEXT: [[R:%.*]] = zext <2 x i1> [[NARROW]] to <2 x i32>
541 ; CHECK-NEXT: ret <2 x i32> [[R]]
543 %ccax = zext <2 x i1> %cca to <2 x i32>
544 %r = select <2 x i1> %ccb, <2 x i32> %ccax, <2 x i32> <i32 1, i32 0>
548 define <2 x i32> @scalar_select_of_vectors_sext(<2 x i1> %cca, i1 %ccb) {
549 ; CHECK-LABEL: @scalar_select_of_vectors_sext(
550 ; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[CCB:%.*]], <2 x i1> [[CCA:%.*]], <2 x i1> zeroinitializer
551 ; CHECK-NEXT: [[R:%.*]] = sext <2 x i1> [[NARROW]] to <2 x i32>
552 ; CHECK-NEXT: ret <2 x i32> [[R]]
554 %ccax = sext <2 x i1> %cca to <2 x i32>
555 %r = select i1 %ccb, <2 x i32> %ccax, <2 x i32> <i32 0, i32 0>
559 define <2 x i32> @scalar_select_of_vectors_zext(<2 x i1> %cca, i1 %ccb) {
560 ; CHECK-LABEL: @scalar_select_of_vectors_zext(
561 ; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[CCB:%.*]], <2 x i1> [[CCA:%.*]], <2 x i1> zeroinitializer
562 ; CHECK-NEXT: [[R:%.*]] = zext <2 x i1> [[NARROW]] to <2 x i32>
563 ; CHECK-NEXT: ret <2 x i32> [[R]]
565 %ccax = zext <2 x i1> %cca to <2 x i32>
566 %r = select i1 %ccb, <2 x i32> %ccax, <2 x i32> <i32 0, i32 0>
570 define i32 @sext_true_val_must_be_all_ones(i1 %x) {
571 ; CHECK-LABEL: @sext_true_val_must_be_all_ones(
572 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i32 -1, i32 42, !prof !0
573 ; CHECK-NEXT: ret i32 [[SEL]]
575 %ext = sext i1 %x to i32
576 %sel = select i1 %x, i32 %ext, i32 42, !prof !0
580 define <2 x i32> @sext_true_val_must_be_all_ones_vec(<2 x i1> %x) {
581 ; CHECK-LABEL: @sext_true_val_must_be_all_ones_vec(
582 ; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[X:%.*]], <2 x i32> <i32 -1, i32 -1>, <2 x i32> <i32 42, i32 12>, !prof !0
583 ; CHECK-NEXT: ret <2 x i32> [[SEL]]
585 %ext = sext <2 x i1> %x to <2 x i32>
586 %sel = select <2 x i1> %x, <2 x i32> %ext, <2 x i32> <i32 42, i32 12>, !prof !0
590 define i32 @zext_true_val_must_be_one(i1 %x) {
591 ; CHECK-LABEL: @zext_true_val_must_be_one(
592 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i32 1, i32 42, !prof !0
593 ; CHECK-NEXT: ret i32 [[SEL]]
595 %ext = zext i1 %x to i32
596 %sel = select i1 %x, i32 %ext, i32 42, !prof !0
600 define <2 x i32> @zext_true_val_must_be_one_vec(<2 x i1> %x) {
601 ; CHECK-LABEL: @zext_true_val_must_be_one_vec(
602 ; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[X:%.*]], <2 x i32> <i32 1, i32 1>, <2 x i32> <i32 42, i32 12>, !prof !0
603 ; CHECK-NEXT: ret <2 x i32> [[SEL]]
605 %ext = zext <2 x i1> %x to <2 x i32>
606 %sel = select <2 x i1> %x, <2 x i32> %ext, <2 x i32> <i32 42, i32 12>, !prof !0
610 define i32 @sext_false_val_must_be_zero(i1 %x) {
611 ; CHECK-LABEL: @sext_false_val_must_be_zero(
612 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i32 42, i32 0, !prof !0
613 ; CHECK-NEXT: ret i32 [[SEL]]
615 %ext = sext i1 %x to i32
616 %sel = select i1 %x, i32 42, i32 %ext, !prof !0
620 define <2 x i32> @sext_false_val_must_be_zero_vec(<2 x i1> %x) {
621 ; CHECK-LABEL: @sext_false_val_must_be_zero_vec(
622 ; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[X:%.*]], <2 x i32> <i32 42, i32 12>, <2 x i32> zeroinitializer, !prof !0
623 ; CHECK-NEXT: ret <2 x i32> [[SEL]]
625 %ext = sext <2 x i1> %x to <2 x i32>
626 %sel = select <2 x i1> %x, <2 x i32> <i32 42, i32 12>, <2 x i32> %ext, !prof !0
630 define i32 @zext_false_val_must_be_zero(i1 %x) {
631 ; CHECK-LABEL: @zext_false_val_must_be_zero(
632 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i32 42, i32 0, !prof !0
633 ; CHECK-NEXT: ret i32 [[SEL]]
635 %ext = zext i1 %x to i32
636 %sel = select i1 %x, i32 42, i32 %ext, !prof !0
640 define <2 x i32> @zext_false_val_must_be_zero_vec(<2 x i1> %x) {
641 ; CHECK-LABEL: @zext_false_val_must_be_zero_vec(
642 ; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[X:%.*]], <2 x i32> <i32 42, i32 12>, <2 x i32> zeroinitializer, !prof !0
643 ; CHECK-NEXT: ret <2 x i32> [[SEL]]
645 %ext = zext <2 x i1> %x to <2 x i32>
646 %sel = select <2 x i1> %x, <2 x i32> <i32 42, i32 12>, <2 x i32> %ext, !prof !0
650 !0 = !{!"branch_weights", i32 3, i32 5}