1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 define i32 @test2(float %f) {
7 ; CHECK-NEXT: [[T5:%.*]] = fmul float [[F:%.*]], [[F]]
8 ; CHECK-NEXT: [[T21:%.*]] = bitcast float [[T5]] to i32
9 ; CHECK-NEXT: ret i32 [[T21]]
11 %t5 = fmul float %f, %f
12 %t9 = insertelement <4 x float> poison, float %t5, i32 0
13 %t10 = insertelement <4 x float> %t9, float 0.000000e+00, i32 1
14 %t11 = insertelement <4 x float> %t10, float 0.000000e+00, i32 2
15 %t12 = insertelement <4 x float> %t11, float 0.000000e+00, i32 3
16 %t19 = bitcast <4 x float> %t12 to <4 x i32>
17 %t21 = extractelement <4 x i32> %t19, i32 0
21 define void @get_image() nounwind {
22 ; CHECK-LABEL: @get_image(
24 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 @fgetc(i8* null) #[[ATTR0:[0-9]+]]
25 ; CHECK-NEXT: br i1 false, label [[BB2:%.*]], label [[BB3:%.*]]
27 ; CHECK-NEXT: br label [[BB3]]
29 ; CHECK-NEXT: unreachable
32 %0 = call i32 @fgetc(i8* null) nounwind
33 %1 = trunc i32 %0 to i8
34 %t2 = insertelement <100 x i8> zeroinitializer, i8 %1, i32 1
35 %t1 = extractelement <100 x i8> %t2, i32 0
36 %2 = icmp eq i8 %t1, 80
37 br i1 %2, label %bb2, label %bb3
42 bb3: ; preds = %bb2, %entry
47 define void @vac(<4 x float>* nocapture %a) nounwind {
50 ; CHECK-NEXT: store <4 x float> zeroinitializer, <4 x float>* [[A:%.*]], align 16
51 ; CHECK-NEXT: ret void
54 %t1 = load <4 x float>, <4 x float>* %a ; <<4 x float>> [#uses=1]
55 %vecins = insertelement <4 x float> %t1, float 0.000000e+00, i32 0 ; <<4 x float>> [#uses=1]
56 %vecins4 = insertelement <4 x float> %vecins, float 0.000000e+00, i32 1; <<4 x float>> [#uses=1]
57 %vecins6 = insertelement <4 x float> %vecins4, float 0.000000e+00, i32 2; <<4 x float>> [#uses=1]
58 %vecins8 = insertelement <4 x float> %vecins6, float 0.000000e+00, i32 3; <<4 x float>> [#uses=1]
59 store <4 x float> %vecins8, <4 x float>* %a
63 declare i32 @fgetc(i8*)
65 define <4 x float> @dead_shuffle_elt(<4 x float> %x, <2 x float> %y) nounwind {
66 ; CHECK-LABEL: @dead_shuffle_elt(
67 ; CHECK-NEXT: [[SHUFFLE_I:%.*]] = shufflevector <2 x float> [[Y:%.*]], <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
68 ; CHECK-NEXT: [[SHUFFLE9_I:%.*]] = shufflevector <4 x float> [[SHUFFLE_I]], <4 x float> [[X:%.*]], <4 x i32> <i32 0, i32 1, i32 6, i32 7>
69 ; CHECK-NEXT: ret <4 x float> [[SHUFFLE9_I]]
71 %shuffle.i = shufflevector <2 x float> %y, <2 x float> %y, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
72 %shuffle9.i = shufflevector <4 x float> %x, <4 x float> %shuffle.i, <4 x i32> <i32 4, i32 5, i32 2, i32 3>
73 ret <4 x float> %shuffle9.i
76 define <2 x float> @test_fptrunc(double %f) {
77 ; CHECK-LABEL: @test_fptrunc(
78 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x double> <double poison, double 0.000000e+00>, double [[F:%.*]], i32 0
79 ; CHECK-NEXT: [[TMP2:%.*]] = fptrunc <2 x double> [[TMP1]] to <2 x float>
80 ; CHECK-NEXT: ret <2 x float> [[TMP2]]
82 %t9 = insertelement <4 x double> poison, double %f, i32 0
83 %t10 = insertelement <4 x double> %t9, double 0.000000e+00, i32 1
84 %t11 = insertelement <4 x double> %t10, double 0.000000e+00, i32 2
85 %t12 = insertelement <4 x double> %t11, double 0.000000e+00, i32 3
86 %t5 = fptrunc <4 x double> %t12 to <4 x float>
87 %ret = shufflevector <4 x float> %t5, <4 x float> poison, <2 x i32> <i32 0, i32 1>
91 define <2 x double> @test_fpext(float %f) {
92 ; CHECK-LABEL: @test_fpext(
93 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x float> <float poison, float 0.000000e+00>, float [[F:%.*]], i32 0
94 ; CHECK-NEXT: [[TMP2:%.*]] = fpext <2 x float> [[TMP1]] to <2 x double>
95 ; CHECK-NEXT: ret <2 x double> [[TMP2]]
97 %t9 = insertelement <4 x float> poison, float %f, i32 0
98 %t10 = insertelement <4 x float> %t9, float 0.000000e+00, i32 1
99 %t11 = insertelement <4 x float> %t10, float 0.000000e+00, i32 2
100 %t12 = insertelement <4 x float> %t11, float 0.000000e+00, i32 3
101 %t5 = fpext <4 x float> %t12 to <4 x double>
102 %ret = shufflevector <4 x double> %t5, <4 x double> poison, <2 x i32> <i32 0, i32 1>
103 ret <2 x double> %ret
106 define <4 x double> @test_shuffle(<4 x double> %f) {
107 ; CHECK-LABEL: @test_shuffle(
108 ; CHECK-NEXT: [[RET1:%.*]] = insertelement <4 x double> [[F:%.*]], double 1.000000e+00, i32 3
109 ; CHECK-NEXT: ret <4 x double> [[RET1]]
111 %ret = shufflevector <4 x double> %f, <4 x double> <double undef, double 1.0, double undef, double undef>, <4 x i32> <i32 0, i32 1, i32 2, i32 5>
112 ret <4 x double> %ret
115 define <4 x float> @test_select(float %f, float %g) {
116 ; CHECK-LABEL: @test_select(
117 ; CHECK-NEXT: [[A3:%.*]] = insertelement <4 x float> <float poison, float poison, float poison, float 3.000000e+00>, float [[F:%.*]], i32 0
118 ; CHECK-NEXT: [[RET:%.*]] = shufflevector <4 x float> [[A3]], <4 x float> <float poison, float 4.000000e+00, float 5.000000e+00, float poison>, <4 x i32> <i32 0, i32 5, i32 6, i32 3>
119 ; CHECK-NEXT: ret <4 x float> [[RET]]
121 %a0 = insertelement <4 x float> poison, float %f, i32 0
122 %a1 = insertelement <4 x float> %a0, float 1.000000e+00, i32 1
123 %a2 = insertelement <4 x float> %a1, float 2.000000e+00, i32 2
124 %a3 = insertelement <4 x float> %a2, float 3.000000e+00, i32 3
125 %b0 = insertelement <4 x float> poison, float %g, i32 0
126 %b1 = insertelement <4 x float> %b0, float 4.000000e+00, i32 1
127 %b2 = insertelement <4 x float> %b1, float 5.000000e+00, i32 2
128 %b3 = insertelement <4 x float> %b2, float 6.000000e+00, i32 3
129 %ret = select <4 x i1> <i1 true, i1 false, i1 false, i1 true>, <4 x float> %a3, <4 x float> %b3
133 ; Check that instcombine doesn't wrongly fold away the select completely.
135 define <2 x i64> @PR24922(<2 x i64> %v) {
136 ; CHECK-LABEL: @PR24922(
137 ; CHECK-NEXT: [[RESULT1:%.*]] = insertelement <2 x i64> [[V:%.*]], i64 0, i32 0
138 ; CHECK-NEXT: ret <2 x i64> [[RESULT1]]
140 %result = select <2 x i1> <i1 icmp eq (i64 extractelement (<2 x i64> bitcast (<4 x i32> <i32 15, i32 15, i32 15, i32 15> to <2 x i64>), i64 0), i64 0), i1 true>, <2 x i64> %v, <2 x i64> zeroinitializer
141 ret <2 x i64> %result
144 ; The shuffle only demands the 0th (undef) element of 'out123', so everything should fold away.
146 define <4 x float> @inselt_shuf_no_demand(float %a1, float %a2, float %a3) {
147 ; CHECK-LABEL: @inselt_shuf_no_demand(
148 ; CHECK-NEXT: ret <4 x float> undef
150 %out1 = insertelement <4 x float> poison, float %a1, i32 1
151 %out12 = insertelement <4 x float> %out1, float %a2, i32 2
152 %out123 = insertelement <4 x float> %out12, float %a3, i32 3
153 %shuffle = shufflevector <4 x float> %out123, <4 x float> poison, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
154 ret <4 x float> %shuffle
157 ; The shuffle only demands the 0th (undef) element of 'out123', so everything should fold away.
159 define <4 x float> @inselt_shuf_no_demand_commute(float %a1, float %a2, float %a3) {
160 ; CHECK-LABEL: @inselt_shuf_no_demand_commute(
161 ; CHECK-NEXT: ret <4 x float> undef
163 %out1 = insertelement <4 x float> poison, float %a1, i32 1
164 %out12 = insertelement <4 x float> %out1, float %a2, i32 2
165 %out123 = insertelement <4 x float> %out12, float %a3, i32 3
166 %shuffle = shufflevector <4 x float> undef, <4 x float> %out123, <4 x i32> <i32 4, i32 undef, i32 undef, i32 undef>
167 ret <4 x float> %shuffle
170 ; The add uses 'out012' giving it multiple uses after the shuffle is transformed to also
171 ; use 'out012'. The analysis should be able to see past that.
173 define <4 x i32> @inselt_shuf_no_demand_multiuse(i32 %a0, i32 %a1, <4 x i32> %b) {
174 ; CHECK-LABEL: @inselt_shuf_no_demand_multiuse(
175 ; CHECK-NEXT: [[OUT0:%.*]] = insertelement <4 x i32> poison, i32 [[A0:%.*]], i32 0
176 ; CHECK-NEXT: [[OUT01:%.*]] = insertelement <4 x i32> [[OUT0]], i32 [[A1:%.*]], i32 1
177 ; CHECK-NEXT: [[FOO:%.*]] = add <4 x i32> [[OUT01]], [[B:%.*]]
178 ; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x i32> [[FOO]], <4 x i32> poison, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
179 ; CHECK-NEXT: ret <4 x i32> [[SHUFFLE]]
181 %out0 = insertelement <4 x i32> poison, i32 %a0, i32 0
182 %out01 = insertelement <4 x i32> %out0, i32 %a1, i32 1
183 %out012 = insertelement <4 x i32> %out01, i32 %a0, i32 2
184 %foo = add <4 x i32> %out012, %b
185 %out0123 = insertelement <4 x i32> %foo, i32 %a1, i32 3
186 %shuffle = shufflevector <4 x i32> %out0123, <4 x i32> poison, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
187 ret <4 x i32> %shuffle
190 define <4 x float> @inselt_shuf_no_demand_bogus_insert_index_in_chain(float %a1, float %a2, float %a3, i32 %variable_index) {
191 ; CHECK-LABEL: @inselt_shuf_no_demand_bogus_insert_index_in_chain(
192 ; CHECK-NEXT: [[OUT12:%.*]] = insertelement <4 x float> poison, float [[A2:%.*]], i32 [[VARIABLE_INDEX:%.*]]
193 ; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x float> [[OUT12]], <4 x float> poison, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
194 ; CHECK-NEXT: ret <4 x float> [[SHUFFLE]]
196 %out1 = insertelement <4 x float> poison, float %a1, i32 1
197 %out12 = insertelement <4 x float> %out1, float %a2, i32 %variable_index ; something unexpected
198 %out123 = insertelement <4 x float> %out12, float %a3, i32 3
199 %shuffle = shufflevector <4 x float> %out123, <4 x float> poison, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
200 ret <4 x float> %shuffle
203 ; Test undef replacement in constant vector elements with binops.
205 define <3 x i8> @shuf_add(<3 x i8> %x) {
206 ; CHECK-LABEL: @shuf_add(
207 ; CHECK-NEXT: [[BO:%.*]] = add <3 x i8> [[X:%.*]], <i8 poison, i8 2, i8 3>
208 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 1, i32 undef, i32 2>
209 ; CHECK-NEXT: ret <3 x i8> [[R]]
211 %bo = add nsw <3 x i8> %x, <i8 1, i8 2, i8 3>
212 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 1, i32 undef, i32 2>
216 define <3 x i8> @shuf_sub(<3 x i8> %x) {
217 ; CHECK-LABEL: @shuf_sub(
218 ; CHECK-NEXT: [[BO:%.*]] = sub <3 x i8> <i8 1, i8 poison, i8 3>, [[X:%.*]]
219 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 0, i32 undef, i32 2>
220 ; CHECK-NEXT: ret <3 x i8> [[R]]
222 %bo = sub nuw <3 x i8> <i8 1, i8 2, i8 3>, %x
223 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 0, i32 undef, i32 2>
227 define <3 x i8> @shuf_mul(<3 x i8> %x) {
228 ; CHECK-LABEL: @shuf_mul(
229 ; CHECK-NEXT: [[BO:%.*]] = mul <3 x i8> [[X:%.*]], <i8 1, i8 poison, i8 3>
230 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 0, i32 2, i32 0>
231 ; CHECK-NEXT: ret <3 x i8> [[R]]
233 %bo = mul nsw <3 x i8> %x, <i8 1, i8 2, i8 3>
234 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 0, i32 2, i32 0>
238 define <3 x i8> @shuf_and(<3 x i8> %x) {
239 ; CHECK-LABEL: @shuf_and(
240 ; CHECK-NEXT: [[BO:%.*]] = and <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 poison>
241 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 1, i32 1, i32 0>
242 ; CHECK-NEXT: ret <3 x i8> [[R]]
244 %bo = and <3 x i8> %x, <i8 1, i8 2, i8 3>
245 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 1, i32 1, i32 0>
249 define <3 x i8> @shuf_or(<3 x i8> %x) {
250 ; CHECK-LABEL: @shuf_or(
251 ; CHECK-NEXT: [[BO:%.*]] = or <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 poison>
252 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 1, i32 undef, i32 0>
253 ; CHECK-NEXT: ret <3 x i8> [[R]]
255 %bo = or <3 x i8> %x, <i8 1, i8 2, i8 3>
256 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 1, i32 undef, i32 0>
260 define <3 x i8> @shuf_xor(<3 x i8> %x) {
261 ; CHECK-LABEL: @shuf_xor(
262 ; CHECK-NEXT: [[BO:%.*]] = xor <3 x i8> [[X:%.*]], <i8 1, i8 poison, i8 3>
263 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 undef, i32 0>
264 ; CHECK-NEXT: ret <3 x i8> [[R]]
266 %bo = xor <3 x i8> %x, <i8 1, i8 2, i8 3>
267 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 2, i32 undef, i32 0>
271 define <3 x i8> @shuf_lshr_const_op0(<3 x i8> %x) {
272 ; CHECK-LABEL: @shuf_lshr_const_op0(
273 ; CHECK-NEXT: [[BO:%.*]] = lshr <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]
274 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 1, i32 undef>
275 ; CHECK-NEXT: ret <3 x i8> [[R]]
277 %bo = lshr <3 x i8> <i8 1, i8 2, i8 3>, %x
278 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 2, i32 1, i32 undef>
282 define <3 x i8> @shuf_lshr_const_op1(<3 x i8> %x) {
283 ; CHECK-LABEL: @shuf_lshr_const_op1(
284 ; CHECK-NEXT: [[BO:%.*]] = lshr exact <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>
285 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 1, i32 undef>
286 ; CHECK-NEXT: ret <3 x i8> [[R]]
288 %bo = lshr exact <3 x i8> %x, <i8 1, i8 2, i8 3>
289 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 2, i32 1, i32 undef>
293 define <3 x i8> @shuf_ashr_const_op0(<3 x i8> %x) {
294 ; CHECK-LABEL: @shuf_ashr_const_op0(
295 ; CHECK-NEXT: [[BO:%.*]] = lshr <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]
296 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 0, i32 undef, i32 1>
297 ; CHECK-NEXT: ret <3 x i8> [[R]]
299 %bo = ashr <3 x i8> <i8 1, i8 2, i8 3>, %x
300 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 0, i32 undef, i32 1>
304 define <3 x i8> @shuf_ashr_const_op1(<3 x i8> %x) {
305 ; CHECK-LABEL: @shuf_ashr_const_op1(
306 ; CHECK-NEXT: [[BO:%.*]] = ashr exact <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>
307 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 0, i32 undef, i32 1>
308 ; CHECK-NEXT: ret <3 x i8> [[R]]
310 %bo = ashr exact <3 x i8> %x, <i8 1, i8 2, i8 3>
311 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 0, i32 undef, i32 1>
315 define <3 x i8> @shuf_shl_const_op0(<3 x i8> %x) {
316 ; CHECK-LABEL: @shuf_shl_const_op0(
317 ; CHECK-NEXT: [[BO:%.*]] = shl nsw <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]
318 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 undef, i32 0>
319 ; CHECK-NEXT: ret <3 x i8> [[R]]
321 %bo = shl nsw <3 x i8> <i8 1, i8 2, i8 3>, %x
322 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 2, i32 undef, i32 0>
326 define <3 x i8> @shuf_shl_const_op1(<3 x i8> %x) {
327 ; CHECK-LABEL: @shuf_shl_const_op1(
328 ; CHECK-NEXT: [[BO:%.*]] = shl nuw <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>
329 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 undef, i32 0>
330 ; CHECK-NEXT: ret <3 x i8> [[R]]
332 %bo = shl nuw <3 x i8> %x, <i8 1, i8 2, i8 3>
333 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 2, i32 undef, i32 0>
337 define <3 x i8> @shuf_sdiv_const_op0(<3 x i8> %x) {
338 ; CHECK-LABEL: @shuf_sdiv_const_op0(
339 ; CHECK-NEXT: [[BO:%.*]] = sdiv exact <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]
340 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 0, i32 undef, i32 1>
341 ; CHECK-NEXT: ret <3 x i8> [[R]]
343 %bo = sdiv exact <3 x i8> <i8 1, i8 2, i8 3>, %x
344 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 0, i32 undef, i32 1>
348 define <3 x i8> @shuf_sdiv_const_op1(<3 x i8> %x) {
349 ; CHECK-LABEL: @shuf_sdiv_const_op1(
350 ; CHECK-NEXT: [[BO:%.*]] = sdiv <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>
351 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 1, i32 undef, i32 0>
352 ; CHECK-NEXT: ret <3 x i8> [[R]]
354 %bo = sdiv <3 x i8> %x, <i8 1, i8 2, i8 3>
355 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 1, i32 undef, i32 0>
359 define <3 x i8> @shuf_srem_const_op0(<3 x i8> %x) {
360 ; CHECK-LABEL: @shuf_srem_const_op0(
361 ; CHECK-NEXT: [[BO:%.*]] = srem <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]
362 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 1, i32 undef, i32 2>
363 ; CHECK-NEXT: ret <3 x i8> [[R]]
365 %bo = srem <3 x i8> <i8 1, i8 2, i8 3>, %x
366 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 1, i32 undef, i32 2>
370 define <3 x i8> @shuf_srem_const_op1(<3 x i8> %x) {
371 ; CHECK-LABEL: @shuf_srem_const_op1(
372 ; CHECK-NEXT: [[BO:%.*]] = srem <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>
373 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 undef, i32 1>
374 ; CHECK-NEXT: ret <3 x i8> [[R]]
376 %bo = srem <3 x i8> %x, <i8 1, i8 2, i8 3>
377 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 2, i32 undef, i32 1>
381 define <3 x i8> @shuf_udiv_const_op0(<3 x i8> %x) {
382 ; CHECK-LABEL: @shuf_udiv_const_op0(
383 ; CHECK-NEXT: [[BO:%.*]] = udiv exact <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]
384 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 undef, i32 0>
385 ; CHECK-NEXT: ret <3 x i8> [[R]]
387 %bo = udiv exact <3 x i8> <i8 1, i8 2, i8 3>, %x
388 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 2, i32 undef, i32 0>
392 define <3 x i8> @shuf_udiv_const_op1(<3 x i8> %x) {
393 ; CHECK-LABEL: @shuf_udiv_const_op1(
394 ; CHECK-NEXT: [[BO:%.*]] = udiv <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>
395 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 undef, i32 0>
396 ; CHECK-NEXT: ret <3 x i8> [[R]]
398 %bo = udiv <3 x i8> %x, <i8 1, i8 2, i8 3>
399 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 2, i32 undef, i32 0>
403 define <3 x i8> @shuf_urem_const_op0(<3 x i8> %x) {
404 ; CHECK-LABEL: @shuf_urem_const_op0(
405 ; CHECK-NEXT: [[BO:%.*]] = urem <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]
406 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 1, i32 undef>
407 ; CHECK-NEXT: ret <3 x i8> [[R]]
409 %bo = urem <3 x i8> <i8 1, i8 2, i8 3>, %x
410 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 2, i32 1, i32 undef>
414 define <3 x i8> @shuf_urem_const_op1(<3 x i8> %x) {
415 ; CHECK-LABEL: @shuf_urem_const_op1(
416 ; CHECK-NEXT: [[BO:%.*]] = urem <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>
417 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 undef, i32 1, i32 0>
418 ; CHECK-NEXT: ret <3 x i8> [[R]]
420 %bo = urem <3 x i8> %x, <i8 1, i8 2, i8 3>
421 %r = shufflevector <3 x i8> %bo, <3 x i8> poison, <3 x i32> <i32 undef, i32 1, i32 0>
425 define <3 x float> @shuf_fadd(<3 x float> %x) {
426 ; CHECK-LABEL: @shuf_fadd(
427 ; CHECK-NEXT: [[BO:%.*]] = fadd <3 x float> [[X:%.*]], <float 1.000000e+00, float 2.000000e+00, float poison>
428 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 undef, i32 1, i32 0>
429 ; CHECK-NEXT: ret <3 x float> [[R]]
431 %bo = fadd <3 x float> %x, <float 1.0, float 2.0, float 3.0>
432 %r = shufflevector <3 x float> %bo, <3 x float> poison, <3 x i32> <i32 undef, i32 1, i32 0>
436 define <3 x float> @shuf_fsub(<3 x float> %x) {
437 ; CHECK-LABEL: @shuf_fsub(
438 ; CHECK-NEXT: [[BO:%.*]] = fsub fast <3 x float> <float 1.000000e+00, float poison, float 3.000000e+00>, [[X:%.*]]
439 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 undef, i32 0, i32 2>
440 ; CHECK-NEXT: ret <3 x float> [[R]]
442 %bo = fsub fast <3 x float> <float 1.0, float 2.0, float 3.0>, %x
443 %r = shufflevector <3 x float> %bo, <3 x float> poison, <3 x i32> <i32 undef, i32 0, i32 2>
447 define <3 x float> @shuf_fmul(<3 x float> %x) {
448 ; CHECK-LABEL: @shuf_fmul(
449 ; CHECK-NEXT: [[BO:%.*]] = fmul reassoc <3 x float> [[X:%.*]], <float 1.000000e+00, float 2.000000e+00, float poison>
450 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 undef, i32 1, i32 0>
451 ; CHECK-NEXT: ret <3 x float> [[R]]
453 %bo = fmul reassoc <3 x float> %x, <float 1.0, float 2.0, float 3.0>
454 %r = shufflevector <3 x float> %bo, <3 x float> poison, <3 x i32> <i32 undef, i32 1, i32 0>
458 define <3 x float> @shuf_fdiv_const_op0(<3 x float> %x) {
459 ; CHECK-LABEL: @shuf_fdiv_const_op0(
460 ; CHECK-NEXT: [[BO:%.*]] = fdiv reassoc ninf <3 x float> <float 1.000000e+00, float poison, float 3.000000e+00>, [[X:%.*]]
461 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 undef, i32 0, i32 2>
462 ; CHECK-NEXT: ret <3 x float> [[R]]
464 %bo = fdiv ninf reassoc <3 x float> <float 1.0, float 2.0, float 3.0>, %x
465 %r = shufflevector <3 x float> %bo, <3 x float> poison, <3 x i32> <i32 undef, i32 0, i32 2>
469 define <3 x float> @shuf_fdiv_const_op1(<3 x float> %x) {
470 ; CHECK-LABEL: @shuf_fdiv_const_op1(
471 ; CHECK-NEXT: [[BO:%.*]] = fdiv nnan ninf <3 x float> [[X:%.*]], <float 1.000000e+00, float 2.000000e+00, float poison>
472 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 undef, i32 1, i32 0>
473 ; CHECK-NEXT: ret <3 x float> [[R]]
475 %bo = fdiv ninf nnan <3 x float> %x, <float 1.0, float 2.0, float 3.0>
476 %r = shufflevector <3 x float> %bo, <3 x float> poison, <3 x i32> <i32 undef, i32 1, i32 0>
480 define <3 x float> @shuf_frem_const_op0(<3 x float> %x) {
481 ; CHECK-LABEL: @shuf_frem_const_op0(
482 ; CHECK-NEXT: [[BO:%.*]] = frem nnan <3 x float> <float 1.000000e+00, float poison, float 3.000000e+00>, [[X:%.*]]
483 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 undef, i32 2, i32 0>
484 ; CHECK-NEXT: ret <3 x float> [[R]]
486 %bo = frem nnan <3 x float> <float 1.0, float 2.0, float 3.0>, %x
487 %r = shufflevector <3 x float> %bo, <3 x float> poison, <3 x i32> <i32 undef, i32 2, i32 0>
491 define <3 x float> @shuf_frem_const_op1(<3 x float> %x) {
492 ; CHECK-LABEL: @shuf_frem_const_op1(
493 ; CHECK-NEXT: [[BO:%.*]] = frem reassoc ninf <3 x float> [[X:%.*]], <float poison, float 2.000000e+00, float 3.000000e+00>
494 ; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 1, i32 undef, i32 2>
495 ; CHECK-NEXT: ret <3 x float> [[R]]
497 %bo = frem ninf reassoc <3 x float> %x, <float 1.0, float 2.0, float 3.0>
498 %r = shufflevector <3 x float> %bo, <3 x float> poison, <3 x i32> <i32 1, i32 undef, i32 2>
502 define i32* @gep_vbase_w_s_idx(<2 x i32*> %base, i64 %index) {
503 ; CHECK-LABEL: @gep_vbase_w_s_idx(
504 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <2 x i32*> [[BASE:%.*]], i32 1
505 ; CHECK-NEXT: [[EE:%.*]] = getelementptr i32, i32* [[TMP1]], i64 %index
506 ; CHECK-NEXT: ret i32* [[EE]]
508 %gep = getelementptr i32, <2 x i32*> %base, i64 %index
509 %ee = extractelement <2 x i32*> %gep, i32 1
513 define i32* @gep_splat_base_w_s_idx(i32* %base) {
514 ; CHECK-LABEL: @gep_splat_base_w_s_idx(
515 ; CHECK-NEXT: [[EE:%.*]] = getelementptr i32, i32* [[BASE:%.*]], i64 1
516 ; CHECK-NEXT: ret i32* [[EE]]
518 %basevec1 = insertelement <2 x i32*> poison, i32* %base, i32 0
519 %basevec2 = shufflevector <2 x i32*> %basevec1, <2 x i32*> poison, <2 x i32> zeroinitializer
520 %gep = getelementptr i32, <2 x i32*> %basevec2, i64 1
521 %ee = extractelement <2 x i32*> %gep, i32 1
526 define i32* @gep_splat_base_w_cv_idx(i32* %base) {
527 ; CHECK-LABEL: @gep_splat_base_w_cv_idx(
528 ; CHECK-NEXT: [[BASEVEC2:%.*]] = insertelement <2 x i32*> poison, i32* [[BASE:%.*]], i32 1
529 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, <2 x i32*> [[BASEVEC2]], <2 x i64> <i64 poison, i64 1>
530 ; CHECK-NEXT: [[EE:%.*]] = extractelement <2 x i32*> [[GEP]], i32 1
531 ; CHECK-NEXT: ret i32* [[EE]]
533 %basevec1 = insertelement <2 x i32*> poison, i32* %base, i32 0
534 %basevec2 = shufflevector <2 x i32*> %basevec1, <2 x i32*> poison, <2 x i32> zeroinitializer
535 %gep = getelementptr i32, <2 x i32*> %basevec2, <2 x i64> <i64 0, i64 1>
536 %ee = extractelement <2 x i32*> %gep, i32 1
540 define i32* @gep_splat_base_w_vidx(i32* %base, <2 x i64> %idxvec) {
541 ; CHECK-LABEL: @gep_splat_base_w_vidx(
542 ; CHECK-NEXT: [[BASEVEC2:%.*]] = insertelement <2 x i32*> poison, i32* [[BASE:%.*]], i32 1
543 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, <2 x i32*> [[BASEVEC2]], <2 x i64> [[IDXVEC:%.*]]
544 ; CHECK-NEXT: [[EE:%.*]] = extractelement <2 x i32*> [[GEP]], i32 1
545 ; CHECK-NEXT: ret i32* [[EE]]
547 %basevec1 = insertelement <2 x i32*> poison, i32* %base, i32 0
548 %basevec2 = shufflevector <2 x i32*> %basevec1, <2 x i32*> poison, <2 x i32> zeroinitializer
549 %gep = getelementptr i32, <2 x i32*> %basevec2, <2 x i64> %idxvec
550 %ee = extractelement <2 x i32*> %gep, i32 1
555 @GLOBAL = internal global i32 zeroinitializer
557 define i32* @gep_cvbase_w_s_idx(<2 x i32*> %base, i64 %raw_addr) {
558 ; CHECK-LABEL: @gep_cvbase_w_s_idx(
559 ; CHECK-NEXT: [[EE:%.*]] = getelementptr i32, i32* @GLOBAL, i64 [[RAW_ADDR:%.*]]
560 ; CHECK-NEXT: ret i32* [[EE]]
562 %gep = getelementptr i32, <2 x i32*> <i32* @GLOBAL, i32* @GLOBAL>, i64 %raw_addr
563 %ee = extractelement <2 x i32*> %gep, i32 1
567 define i32* @gep_cvbase_w_cv_idx(<2 x i32*> %base, i64 %raw_addr) {
568 ; CHECK-LABEL: @gep_cvbase_w_cv_idx(
569 ; CHECK-NEXT: ret i32* getelementptr inbounds (i32, i32* @GLOBAL, i64 1)
571 %gep = getelementptr i32, <2 x i32*> <i32* @GLOBAL, i32* @GLOBAL>, <2 x i64> <i64 0, i64 1>
572 %ee = extractelement <2 x i32*> %gep, i32 1
577 define i32* @gep_sbase_w_cv_idx(i32* %base) {
578 ; CHECK-LABEL: @gep_sbase_w_cv_idx(
579 ; CHECK-NEXT: [[EE:%.*]] = getelementptr i32, i32* [[BASE:%.*]], i64 1
580 ; CHECK-NEXT: ret i32* [[EE]]
582 %gep = getelementptr i32, i32* %base, <2 x i64> <i64 0, i64 1>
583 %ee = extractelement <2 x i32*> %gep, i32 1
587 define i32* @gep_sbase_w_splat_idx(i32* %base, i64 %idx) {
588 ; CHECK-LABEL: @gep_sbase_w_splat_idx(
589 ; CHECK-NEXT: [[EE:%.*]] = getelementptr i32, i32* [[BASE:%.*]], i64 [[IDX:%.*]]
590 ; CHECK-NEXT: ret i32* [[EE]]
592 %idxvec1 = insertelement <2 x i64> poison, i64 %idx, i32 0
593 %idxvec2 = shufflevector <2 x i64> %idxvec1, <2 x i64> poison, <2 x i32> zeroinitializer
594 %gep = getelementptr i32, i32* %base, <2 x i64> %idxvec2
595 %ee = extractelement <2 x i32*> %gep, i32 1
598 define i32* @gep_splat_both(i32* %base, i64 %idx) {
599 ; CHECK-LABEL: @gep_splat_both(
600 ; CHECK-NEXT: [[BASEVEC2:%.*]] = insertelement <2 x i32*> poison, i32* [[BASE:%.*]], i32 1
601 ; CHECK-NEXT: [[IDXVEC2:%.*]] = insertelement <2 x i64> poison, i64 [[IDX:%.*]], i32 1
602 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, <2 x i32*> [[BASEVEC2]], <2 x i64> [[IDXVEC2]]
603 ; CHECK-NEXT: [[EE:%.*]] = extractelement <2 x i32*> [[GEP]], i32 1
604 ; CHECK-NEXT: ret i32* [[EE]]
606 %basevec1 = insertelement <2 x i32*> poison, i32* %base, i32 0
607 %basevec2 = shufflevector <2 x i32*> %basevec1, <2 x i32*> poison, <2 x i32> zeroinitializer
608 %idxvec1 = insertelement <2 x i64> poison, i64 %idx, i32 0
609 %idxvec2 = shufflevector <2 x i64> %idxvec1, <2 x i64> poison, <2 x i32> zeroinitializer
610 %gep = getelementptr i32, <2 x i32*> %basevec2, <2 x i64> %idxvec2
611 %ee = extractelement <2 x i32*> %gep, i32 1
615 define <2 x i32*> @gep_all_lanes_undef(i32* %base, i64 %idx) {;
616 ; CHECK-LABEL: @gep_all_lanes_undef(
617 ; CHECK-NEXT: ret <2 x i32*> undef
619 %basevec = insertelement <2 x i32*> poison, i32* %base, i32 0
620 %idxvec = insertelement <2 x i64> poison, i64 %idx, i32 1
621 %gep = getelementptr i32, <2 x i32*> %basevec, <2 x i64> %idxvec
625 define i32* @gep_demanded_lane_undef(i32* %base, i64 %idx) {
626 ; CHECK-LABEL: @gep_demanded_lane_undef(
627 ; CHECK-NEXT: ret i32* undef
629 %basevec = insertelement <2 x i32*> poison, i32* %base, i32 0
630 %idxvec = insertelement <2 x i64> poison, i64 %idx, i32 1
631 %gep = getelementptr i32, <2 x i32*> %basevec, <2 x i64> %idxvec
632 %ee = extractelement <2 x i32*> %gep, i32 1
637 ;; LangRef has an odd quirk around FCAs which make it illegal to use undef
639 define i32* @PR41624(<2 x { i32, i32 }*> %a) {
640 ; CHECK-LABEL: @PR41624(
641 ; CHECK-NEXT: [[W:%.*]] = getelementptr { i32, i32 }, <2 x { i32, i32 }*> [[A:%.*]], <2 x i64> <i64 5, i64 5>, <2 x i32> zeroinitializer
642 ; CHECK-NEXT: [[R:%.*]] = extractelement <2 x i32*> [[W]], i32 0
643 ; CHECK-NEXT: ret i32* [[R]]
645 %w = getelementptr { i32, i32 }, <2 x { i32, i32 }*> %a, <2 x i64> <i64 5, i64 5>, <2 x i32> zeroinitializer
646 %r = extractelement <2 x i32*> %w, i32 0
650 @global = external global [0 x i32], align 4
652 ; Make sure we don't get stuck in a loop turning the zeroinitializer into
653 ; <0, undef, undef, undef> and then changing it back.
654 define i32* @zero_sized_type_extract(<4 x i64> %arg, i64 %arg1) {
655 ; CHECK-LABEL: @zero_sized_type_extract(
657 ; CHECK-NEXT: [[T:%.*]] = getelementptr inbounds [0 x i32], <4 x [0 x i32]*> <[0 x i32]* @global, [0 x i32]* poison, [0 x i32]* poison, [0 x i32]* poison>, <4 x i64> <i64 0, i64 poison, i64 poison, i64 poison>, <4 x i64> [[ARG:%.*]]
658 ; CHECK-NEXT: [[T2:%.*]] = extractelement <4 x i32*> [[T]], i64 0
659 ; CHECK-NEXT: ret i32* [[T2]]
662 %t = getelementptr inbounds [0 x i32], <4 x [0 x i32]*> <[0 x i32]* @global, [0 x i32]* @global, [0 x i32]* @global, [0 x i32]* @global>, <4 x i64> zeroinitializer, <4 x i64> %arg
663 %t2 = extractelement <4 x i32*> %t, i64 0
667 ; The non-zero elements of the result are always 'y', so the splat is unnecessary.
669 define <4 x i8> @select_cond_with_eq_true_false_elts(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) {
670 ; CHECK-LABEL: @select_cond_with_eq_true_false_elts(
671 ; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]]
672 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[SEL]], <4 x i8> [[Y]], <4 x i32> <i32 0, i32 5, i32 6, i32 7>
673 ; CHECK-NEXT: ret <4 x i8> [[R]]
675 %tval = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> <i32 0, i32 5, i32 6, i32 7>
676 %splat = shufflevector <4 x i1> %cmp, <4 x i1> poison, <4 x i32> zeroinitializer
677 %r = select <4 x i1> %splat, <4 x i8> %tval, <4 x i8> %y
681 ; First element of the result is always x[0], so first element of select condition is unnecessary.
683 define <4 x i8> @select_cond_with_eq_true_false_elts2(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) {
684 ; CHECK-LABEL: @select_cond_with_eq_true_false_elts2(
685 ; CHECK-NEXT: [[COND:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> poison, <4 x i32> <i32 undef, i32 1, i32 0, i32 1>
686 ; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> [[COND]], <4 x i8> [[Y:%.*]], <4 x i8> [[X:%.*]]
687 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[X]], <4 x i8> [[SEL]], <4 x i32> <i32 0, i32 5, i32 6, i32 7>
688 ; CHECK-NEXT: ret <4 x i8> [[R]]
690 %tval = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> <i32 0, i32 5, i32 6, i32 7>
691 %cond = shufflevector <4 x i1> %cmp, <4 x i1> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
692 %r = select <4 x i1> %cond, <4 x i8> %tval, <4 x i8> %x
696 ; Second element of the result is always x[3], so second element of select condition is unnecessary.
697 ; Fourth element of the result is always undef, so fourth element of select condition is unnecessary.
699 define <4 x float> @select_cond_with_eq_true_false_elts3(<4 x float> %x, <4 x float> %y, <4 x i1> %cmp) {
700 ; CHECK-LABEL: @select_cond_with_eq_true_false_elts3(
701 ; CHECK-NEXT: [[TVAL:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> [[Y:%.*]], <4 x i32> <i32 1, i32 3, i32 5, i32 undef>
702 ; CHECK-NEXT: [[FVAL:%.*]] = shufflevector <4 x float> [[Y]], <4 x float> [[X]], <4 x i32> <i32 0, i32 7, i32 6, i32 undef>
703 ; CHECK-NEXT: [[COND:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> poison, <4 x i32> <i32 undef, i32 1, i32 2, i32 3>
704 ; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[COND]], <4 x float> [[TVAL]], <4 x float> [[FVAL]]
705 ; CHECK-NEXT: ret <4 x float> [[R]]
707 %tval = shufflevector <4 x float> %x, <4 x float> %y, <4 x i32> <i32 1, i32 3, i32 5, i32 undef>
708 %fval = shufflevector <4 x float> %y, <4 x float> %x, <4 x i32> <i32 0, i32 7, i32 6, i32 undef>
709 %cond = shufflevector <4 x i1> %cmp, <4 x i1> poison, <4 x i32> <i32 undef, i32 1, i32 2, i32 3>
710 %r = select <4 x i1> %cond, <4 x float> %tval, <4 x float> %fval
714 define <4 x i8> @select_cond_with_undef_true_false_elts(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) {
715 ; CHECK-LABEL: @select_cond_with_undef_true_false_elts(
716 ; CHECK-NEXT: [[TVAL:%.*]] = shufflevector <4 x i8> [[Y:%.*]], <4 x i8> poison, <4 x i32> <i32 undef, i32 1, i32 2, i32 3>
717 ; CHECK-NEXT: [[COND:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
718 ; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[COND]], <4 x i8> [[TVAL]], <4 x i8> [[X:%.*]]
719 ; CHECK-NEXT: ret <4 x i8> [[R]]
721 %tval = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> <i32 undef, i32 5, i32 6, i32 7>
722 %cond = shufflevector <4 x i1> %cmp, <4 x i1> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
723 %r = select <4 x i1> %cond, <4 x i8> %tval, <4 x i8> %x
727 ; The insert can be safely eliminated because the shuffle blocks poison from cmp[0].
729 define <4 x i8> @select_cond_(<4 x i8> %x, <4 x i8> %min, <4 x i1> %cmp, i1 %poison_blocker) {
730 ; CHECK-LABEL: @select_cond_(
731 ; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i8> [[MIN:%.*]], <4 x i8> [[X:%.*]]
732 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[X]], <4 x i8> [[SEL]], <4 x i32> <i32 0, i32 5, i32 6, i32 7>
733 ; CHECK-NEXT: ret <4 x i8> [[R]]
735 %ins = insertelement <4 x i1> %cmp, i1 %poison_blocker, i32 0
736 %vecins = shufflevector <4 x i8> %x, <4 x i8> %min, <4 x i32> <i32 0, i32 5, i32 6, i32 7>
737 %r = select <4 x i1> %ins, <4 x i8> %vecins, <4 x i8> %x
741 define <4 x float> @ins_of_ext(<4 x float> %x, float %y) {
742 ; CHECK-LABEL: @ins_of_ext(
743 ; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x float> [[X:%.*]], float [[Y:%.*]], i32 1
744 ; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[I1]], float [[Y]], i32 2
745 ; CHECK-NEXT: [[I3:%.*]] = insertelement <4 x float> [[I2]], float [[Y]], i32 3
746 ; CHECK-NEXT: ret <4 x float> [[I3]]
748 %e0 = extractelement <4 x float> %x, i32 0
749 %i0 = insertelement <4 x float> poison, float %e0, i32 0
750 %i1 = insertelement <4 x float> %i0, float %y, i32 1
751 %i2 = insertelement <4 x float> %i1, float %y, i32 2
752 %i3 = insertelement <4 x float> %i2, float %y, i32 3
756 define <4 x float> @ins_of_ext_twice(<4 x float> %x, float %y) {
757 ; CHECK-LABEL: @ins_of_ext_twice(
758 ; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[X:%.*]], float [[Y:%.*]], i32 2
759 ; CHECK-NEXT: [[I3:%.*]] = insertelement <4 x float> [[I2]], float [[Y]], i32 3
760 ; CHECK-NEXT: ret <4 x float> [[I3]]
762 %e0 = extractelement <4 x float> %x, i32 0
763 %i0 = insertelement <4 x float> poison, float %e0, i32 0
764 %e1 = extractelement <4 x float> %x, i32 1
765 %i1 = insertelement <4 x float> %i0, float %e1, i32 1
766 %i2 = insertelement <4 x float> %i1, float %y, i32 2
767 %i3 = insertelement <4 x float> %i2, float %y, i32 3
771 ; Negative test - element 3 of the result must be undef to be poison safe.
772 ; TODO: Could convert insert/extract to identity shuffle with undef mask elements.
774 define <4 x float> @ins_of_ext_wrong_demand(<4 x float> %x, float %y) {
775 ; CHECK-LABEL: @ins_of_ext_wrong_demand(
776 ; CHECK-NEXT: [[E0:%.*]] = extractelement <4 x float> [[X:%.*]], i32 0
777 ; CHECK-NEXT: [[I0:%.*]] = insertelement <4 x float> poison, float [[E0]], i32 0
778 ; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x float> [[I0]], float [[Y:%.*]], i32 1
779 ; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[I1]], float [[Y]], i32 2
780 ; CHECK-NEXT: ret <4 x float> [[I2]]
782 %e0 = extractelement <4 x float> %x, i32 0
783 %i0 = insertelement <4 x float> poison, float %e0, i32 0
784 %i1 = insertelement <4 x float> %i0, float %y, i32 1
785 %i2 = insertelement <4 x float> %i1, float %y, i32 2
789 ; Negative test - can't replace i0 with x.
790 ; TODO: Could convert insert/extract to identity shuffle with undef mask elements.
792 define <4 x float> @ins_of_ext_wrong_type(<5 x float> %x, float %y) {
793 ; CHECK-LABEL: @ins_of_ext_wrong_type(
794 ; CHECK-NEXT: [[E0:%.*]] = extractelement <5 x float> [[X:%.*]], i32 0
795 ; CHECK-NEXT: [[I0:%.*]] = insertelement <4 x float> poison, float [[E0]], i32 0
796 ; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x float> [[I0]], float [[Y:%.*]], i32 1
797 ; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[I1]], float [[Y]], i32 2
798 ; CHECK-NEXT: [[I3:%.*]] = insertelement <4 x float> [[I2]], float [[Y]], i32 3
799 ; CHECK-NEXT: ret <4 x float> [[I3]]
801 %e0 = extractelement <5 x float> %x, i32 0
802 %i0 = insertelement <4 x float> poison, float %e0, i32 0
803 %i1 = insertelement <4 x float> %i0, float %y, i32 1
804 %i2 = insertelement <4 x float> %i1, float %y, i32 2
805 %i3 = insertelement <4 x float> %i2, float %y, i32 3
809 ; This should reduce, but the shuffle mask must remain as-is (no extra undef).
811 define <4 x i4> @ins_of_ext_undef_elts_propagation(<4 x i4> %v, <4 x i4> %v2, i4 %x) {
812 ; CHECK-LABEL: @ins_of_ext_undef_elts_propagation(
813 ; CHECK-NEXT: [[T2:%.*]] = insertelement <4 x i4> [[V:%.*]], i4 [[X:%.*]], i32 2
814 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i4> [[T2]], <4 x i4> [[V2:%.*]], <4 x i32> <i32 0, i32 6, i32 2, i32 7>
815 ; CHECK-NEXT: ret <4 x i4> [[R]]
817 %v0 = extractelement <4 x i4> %v, i32 0
818 %t0 = insertelement <4 x i4> poison, i4 %v0, i32 0
819 %t2 = insertelement <4 x i4> %t0, i4 %x, i32 2
820 %r = shufflevector <4 x i4> %t2, <4 x i4> %v2, <4 x i32> <i32 0, i32 6, i32 2, i32 7>
824 ; Similar to above, but more ops/uses to verify things work in more complicated cases.
826 define <8 x i4> @ins_of_ext_undef_elts_propagation2(<8 x i4> %v, <8 x i4> %v2, i4 %x) {
827 ; CHECK-LABEL: @ins_of_ext_undef_elts_propagation2(
828 ; CHECK-NEXT: [[I19:%.*]] = insertelement <8 x i4> [[V:%.*]], i4 [[X:%.*]], i32 2
829 ; CHECK-NEXT: [[I20:%.*]] = shufflevector <8 x i4> [[I19]], <8 x i4> [[V2:%.*]], <8 x i32> <i32 0, i32 1, i32 2, i32 11, i32 10, i32 9, i32 8, i32 undef>
830 ; CHECK-NEXT: [[I21:%.*]] = shufflevector <8 x i4> [[I20]], <8 x i4> [[V]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 15>
831 ; CHECK-NEXT: ret <8 x i4> [[I21]]
833 %i15 = extractelement <8 x i4> %v, i32 0
834 %i16 = insertelement <8 x i4> poison, i4 %i15, i32 0
835 %i17 = extractelement <8 x i4> %v, i32 1
836 %i18 = insertelement <8 x i4> %i16, i4 %i17, i32 1
837 %i19 = insertelement <8 x i4> %i18, i4 %x, i32 2
838 %i20 = shufflevector <8 x i4> %i19, <8 x i4> %v2, <8 x i32> <i32 0, i32 1, i32 2, i32 11, i32 10, i32 9, i32 8, i32 undef>
839 %i21 = shufflevector <8 x i4> %i20, <8 x i4> %v, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 15>