1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -vector-combine -S -mtriple=x86_64-- -mattr=sse2 | FileCheck %s
3; RUN: opt < %s -vector-combine -S -mtriple=x86_64-- -mattr=avx2 | FileCheck %s
4
5target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6
7define float @matching_fp_scalar(float* align 16 dereferenceable(16) %p) {
8; CHECK-LABEL: @matching_fp_scalar(
9; CHECK-NEXT:    [[R:%.*]] = load float, float* [[P:%.*]], align 16
10; CHECK-NEXT:    ret float [[R]]
11;
12  %r = load float, float* %p, align 16
13  ret float %r
14}
15
16define float @matching_fp_scalar_volatile(float* align 16 dereferenceable(16) %p) {
17; CHECK-LABEL: @matching_fp_scalar_volatile(
18; CHECK-NEXT:    [[R:%.*]] = load volatile float, float* [[P:%.*]], align 16
19; CHECK-NEXT:    ret float [[R]]
20;
21  %r = load volatile float, float* %p, align 16
22  ret float %r
23}
24
25define double @larger_fp_scalar(float* align 16 dereferenceable(16) %p) {
26; CHECK-LABEL: @larger_fp_scalar(
27; CHECK-NEXT:    [[BC:%.*]] = bitcast float* [[P:%.*]] to double*
28; CHECK-NEXT:    [[R:%.*]] = load double, double* [[BC]], align 16
29; CHECK-NEXT:    ret double [[R]]
30;
31  %bc = bitcast float* %p to double*
32  %r = load double, double* %bc, align 16
33  ret double %r
34}
35
36define float @smaller_fp_scalar(double* align 16 dereferenceable(16) %p) {
37; CHECK-LABEL: @smaller_fp_scalar(
38; CHECK-NEXT:    [[BC:%.*]] = bitcast double* [[P:%.*]] to float*
39; CHECK-NEXT:    [[R:%.*]] = load float, float* [[BC]], align 16
40; CHECK-NEXT:    ret float [[R]]
41;
42  %bc = bitcast double* %p to float*
43  %r = load float, float* %bc, align 16
44  ret float %r
45}
46
47define float @matching_fp_vector(<4 x float>* align 16 dereferenceable(16) %p) {
48; CHECK-LABEL: @matching_fp_vector(
49; CHECK-NEXT:    [[BC:%.*]] = bitcast <4 x float>* [[P:%.*]] to float*
50; CHECK-NEXT:    [[R:%.*]] = load float, float* [[BC]], align 16
51; CHECK-NEXT:    ret float [[R]]
52;
53  %bc = bitcast <4 x float>* %p to float*
54  %r = load float, float* %bc, align 16
55  ret float %r
56}
57
58define float @matching_fp_vector_gep00(<4 x float>* align 16 dereferenceable(16) %p) {
59; CHECK-LABEL: @matching_fp_vector_gep00(
60; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds <4 x float>, <4 x float>* [[P:%.*]], i64 0, i64 0
61; CHECK-NEXT:    [[R:%.*]] = load float, float* [[GEP]], align 16
62; CHECK-NEXT:    ret float [[R]]
63;
64  %gep = getelementptr inbounds <4 x float>, <4 x float>* %p, i64 0, i64 0
65  %r = load float, float* %gep, align 16
66  ret float %r
67}
68
69define float @matching_fp_vector_gep01(<4 x float>* align 16 dereferenceable(20) %p) {
70; CHECK-LABEL: @matching_fp_vector_gep01(
71; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds <4 x float>, <4 x float>* [[P:%.*]], i64 0, i64 1
72; CHECK-NEXT:    [[R:%.*]] = load float, float* [[GEP]], align 4
73; CHECK-NEXT:    ret float [[R]]
74;
75  %gep = getelementptr inbounds <4 x float>, <4 x float>* %p, i64 0, i64 1
76  %r = load float, float* %gep, align 4
77  ret float %r
78}
79
80define float @matching_fp_vector_gep01_deref(<4 x float>* align 16 dereferenceable(19) %p) {
81; CHECK-LABEL: @matching_fp_vector_gep01_deref(
82; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds <4 x float>, <4 x float>* [[P:%.*]], i64 0, i64 1
83; CHECK-NEXT:    [[R:%.*]] = load float, float* [[GEP]], align 4
84; CHECK-NEXT:    ret float [[R]]
85;
86  %gep = getelementptr inbounds <4 x float>, <4 x float>* %p, i64 0, i64 1
87  %r = load float, float* %gep, align 4
88  ret float %r
89}
90
91define float @matching_fp_vector_gep10(<4 x float>* align 16 dereferenceable(32) %p) {
92; CHECK-LABEL: @matching_fp_vector_gep10(
93; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds <4 x float>, <4 x float>* [[P:%.*]], i64 1, i64 0
94; CHECK-NEXT:    [[R:%.*]] = load float, float* [[GEP]], align 16
95; CHECK-NEXT:    ret float [[R]]
96;
97  %gep = getelementptr inbounds <4 x float>, <4 x float>* %p, i64 1, i64 0
98  %r = load float, float* %gep, align 16
99  ret float %r
100}
101
102define float @matching_fp_vector_gep10_deref(<4 x float>* align 16 dereferenceable(31) %p) {
103; CHECK-LABEL: @matching_fp_vector_gep10_deref(
104; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds <4 x float>, <4 x float>* [[P:%.*]], i64 1, i64 0
105; CHECK-NEXT:    [[R:%.*]] = load float, float* [[GEP]], align 16
106; CHECK-NEXT:    ret float [[R]]
107;
108  %gep = getelementptr inbounds <4 x float>, <4 x float>* %p, i64 1, i64 0
109  %r = load float, float* %gep, align 16
110  ret float %r
111}
112
113define float @nonmatching_int_vector(<2 x i64>* align 16 dereferenceable(16) %p) {
114; CHECK-LABEL: @nonmatching_int_vector(
115; CHECK-NEXT:    [[BC:%.*]] = bitcast <2 x i64>* [[P:%.*]] to float*
116; CHECK-NEXT:    [[R:%.*]] = load float, float* [[BC]], align 16
117; CHECK-NEXT:    ret float [[R]]
118;
119  %bc = bitcast <2 x i64>* %p to float*
120  %r = load float, float* %bc, align 16
121  ret float %r
122}
123
124define double @less_aligned(double* align 4 dereferenceable(16) %p) {
125; CHECK-LABEL: @less_aligned(
126; CHECK-NEXT:    [[R:%.*]] = load double, double* [[P:%.*]], align 4
127; CHECK-NEXT:    ret double [[R]]
128;
129  %r = load double, double* %p, align 4
130  ret double %r
131}
132
133define float @matching_fp_scalar_small_deref(float* align 16 dereferenceable(15) %p) {
134; CHECK-LABEL: @matching_fp_scalar_small_deref(
135; CHECK-NEXT:    [[R:%.*]] = load float, float* [[P:%.*]], align 16
136; CHECK-NEXT:    ret float [[R]]
137;
138  %r = load float, float* %p, align 16
139  ret float %r
140}
141
142define i64 @larger_int_scalar(<4 x float>* align 16 dereferenceable(16) %p) {
143; CHECK-LABEL: @larger_int_scalar(
144; CHECK-NEXT:    [[BC:%.*]] = bitcast <4 x float>* [[P:%.*]] to i64*
145; CHECK-NEXT:    [[R:%.*]] = load i64, i64* [[BC]], align 16
146; CHECK-NEXT:    ret i64 [[R]]
147;
148  %bc = bitcast <4 x float>* %p to i64*
149  %r = load i64, i64* %bc, align 16
150  ret i64 %r
151}
152
153define i8 @smaller_int_scalar(<4 x float>* align 16 dereferenceable(16) %p) {
154; CHECK-LABEL: @smaller_int_scalar(
155; CHECK-NEXT:    [[BC:%.*]] = bitcast <4 x float>* [[P:%.*]] to i8*
156; CHECK-NEXT:    [[R:%.*]] = load i8, i8* [[BC]], align 16
157; CHECK-NEXT:    ret i8 [[R]]
158;
159  %bc = bitcast <4 x float>* %p to i8*
160  %r = load i8, i8* %bc, align 16
161  ret i8 %r
162}
163
164define double @larger_fp_scalar_256bit_vec(<8 x float>* align 32 dereferenceable(32) %p) {
165; CHECK-LABEL: @larger_fp_scalar_256bit_vec(
166; CHECK-NEXT:    [[BC:%.*]] = bitcast <8 x float>* [[P:%.*]] to double*
167; CHECK-NEXT:    [[R:%.*]] = load double, double* [[BC]], align 32
168; CHECK-NEXT:    ret double [[R]]
169;
170  %bc = bitcast <8 x float>* %p to double*
171  %r = load double, double* %bc, align 32
172  ret double %r
173}
174
175define <4 x float> @load_f32_insert_v4f32(float* align 16 dereferenceable(16) %p) {
176; CHECK-LABEL: @load_f32_insert_v4f32(
177; CHECK-NEXT:    [[TMP1:%.*]] = bitcast float* [[P:%.*]] to <4 x float>*
178; CHECK-NEXT:    [[R:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4
179; CHECK-NEXT:    ret <4 x float> [[R]]
180;
181  %s = load float, float* %p, align 4
182  %r = insertelement <4 x float> undef, float %s, i32 0
183  ret <4 x float> %r
184}
185
186define <4 x float> @casted_load_f32_insert_v4f32(<4 x float>* align 4 dereferenceable(16) %p) {
187; CHECK-LABEL: @casted_load_f32_insert_v4f32(
188; CHECK-NEXT:    [[R:%.*]] = load <4 x float>, <4 x float>* [[P:%.*]], align 4
189; CHECK-NEXT:    ret <4 x float> [[R]]
190;
191  %b = bitcast <4 x float>* %p to float*
192  %s = load float, float* %b, align 4
193  %r = insertelement <4 x float> undef, float %s, i32 0
194  ret <4 x float> %r
195}
196
197; Element type does not change cost.
198
199define <4 x i32> @load_i32_insert_v4i32(i32* align 16 dereferenceable(16) %p) {
200; CHECK-LABEL: @load_i32_insert_v4i32(
201; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i32* [[P:%.*]] to <4 x i32>*
202; CHECK-NEXT:    [[R:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]], align 4
203; CHECK-NEXT:    ret <4 x i32> [[R]]
204;
205  %s = load i32, i32* %p, align 4
206  %r = insertelement <4 x i32> undef, i32 %s, i32 0
207  ret <4 x i32> %r
208}
209
210; Pointer type does not change cost.
211
212define <4 x i32> @casted_load_i32_insert_v4i32(<16 x i8>* align 4 dereferenceable(16) %p) {
213; CHECK-LABEL: @casted_load_i32_insert_v4i32(
214; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <16 x i8>* [[P:%.*]] to <4 x i32>*
215; CHECK-NEXT:    [[R:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]], align 4
216; CHECK-NEXT:    ret <4 x i32> [[R]]
217;
218  %b = bitcast <16 x i8>* %p to i32*
219  %s = load i32, i32* %b, align 4
220  %r = insertelement <4 x i32> undef, i32 %s, i32 0
221  ret <4 x i32> %r
222}
223
224; This is canonical form for vector element access.
225
226define <4 x float> @gep00_load_f32_insert_v4f32(<4 x float>* align 16 dereferenceable(16) %p) {
227; CHECK-LABEL: @gep00_load_f32_insert_v4f32(
228; CHECK-NEXT:    [[R:%.*]] = load <4 x float>, <4 x float>* [[P:%.*]], align 16
229; CHECK-NEXT:    ret <4 x float> [[R]]
230;
231  %gep = getelementptr inbounds <4 x float>, <4 x float>* %p, i64 0, i64 0
232  %s = load float, float* %gep, align 16
233  %r = insertelement <4 x float> undef, float %s, i64 0
234  ret <4 x float> %r
235}
236
237; Should work with addrspace as well.
238
239define <4 x float> @gep00_load_f32_insert_v4f32_addrspace(<4 x float> addrspace(44)* align 16 dereferenceable(16) %p) {
240; CHECK-LABEL: @gep00_load_f32_insert_v4f32_addrspace(
241; CHECK-NEXT:    [[R:%.*]] = load <4 x float>, <4 x float> addrspace(44)* [[P:%.*]], align 16
242; CHECK-NEXT:    ret <4 x float> [[R]]
243;
244  %gep = getelementptr inbounds <4 x float>, <4 x float> addrspace(44)* %p, i64 0, i64 0
245  %s = load float, float addrspace(44)* %gep, align 16
246  %r = insertelement <4 x float> undef, float %s, i64 0
247  ret <4 x float> %r
248}
249
250; If there are enough dereferenceable bytes, we can offset the vector load.
251
252define <8 x i16> @gep01_load_i16_insert_v8i16(<8 x i16>* align 16 dereferenceable(18) %p) {
253; CHECK-LABEL: @gep01_load_i16_insert_v8i16(
254; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds <8 x i16>, <8 x i16>* [[P:%.*]], i64 0, i64 1
255; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i16* [[GEP]] to <8 x i16>*
256; CHECK-NEXT:    [[R:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]], align 2
257; CHECK-NEXT:    ret <8 x i16> [[R]]
258;
259  %gep = getelementptr inbounds <8 x i16>, <8 x i16>* %p, i64 0, i64 1
260  %s = load i16, i16* %gep, align 2
261  %r = insertelement <8 x i16> undef, i16 %s, i64 0
262  ret <8 x i16> %r
263}
264
265; Negative test - can't safely load the offset vector, but could load+shuffle.
266
267define <8 x i16> @gep01_load_i16_insert_v8i16_deref(<8 x i16>* align 16 dereferenceable(17) %p) {
268; CHECK-LABEL: @gep01_load_i16_insert_v8i16_deref(
269; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds <8 x i16>, <8 x i16>* [[P:%.*]], i64 0, i64 1
270; CHECK-NEXT:    [[S:%.*]] = load i16, i16* [[GEP]], align 2
271; CHECK-NEXT:    [[R:%.*]] = insertelement <8 x i16> undef, i16 [[S]], i64 0
272; CHECK-NEXT:    ret <8 x i16> [[R]]
273;
274  %gep = getelementptr inbounds <8 x i16>, <8 x i16>* %p, i64 0, i64 1
275  %s = load i16, i16* %gep, align 2
276  %r = insertelement <8 x i16> undef, i16 %s, i64 0
277  ret <8 x i16> %r
278}
279
280; If there are enough dereferenceable bytes, we can offset the vector load.
281
282define <8 x i16> @gep10_load_i16_insert_v8i16(<8 x i16>* align 16 dereferenceable(32) %p) {
283; CHECK-LABEL: @gep10_load_i16_insert_v8i16(
284; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds <8 x i16>, <8 x i16>* [[P:%.*]], i64 1, i64 0
285; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i16* [[GEP]] to <8 x i16>*
286; CHECK-NEXT:    [[R:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]], align 16
287; CHECK-NEXT:    ret <8 x i16> [[R]]
288;
289  %gep = getelementptr inbounds <8 x i16>, <8 x i16>* %p, i64 1, i64 0
290  %s = load i16, i16* %gep, align 16
291  %r = insertelement <8 x i16> undef, i16 %s, i64 0
292  ret <8 x i16> %r
293}
294
295; Negative test - disable under asan because widened load can cause spurious
296; use-after-poison issues when __asan_poison_memory_region is used.
297
298define <8 x i16> @gep10_load_i16_insert_v8i16_asan(<8 x i16>* align 16 dereferenceable(32) %p) sanitize_address {
299; CHECK-LABEL: @gep10_load_i16_insert_v8i16_asan(
300; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds <8 x i16>, <8 x i16>* [[P:%.*]], i64 1, i64 0
301; CHECK-NEXT:    [[S:%.*]] = load i16, i16* [[GEP]], align 16
302; CHECK-NEXT:    [[R:%.*]] = insertelement <8 x i16> undef, i16 [[S]], i64 0
303; CHECK-NEXT:    ret <8 x i16> [[R]]
304;
305  %gep = getelementptr inbounds <8 x i16>, <8 x i16>* %p, i64 1, i64 0
306  %s = load i16, i16* %gep, align 16
307  %r = insertelement <8 x i16> undef, i16 %s, i64 0
308  ret <8 x i16> %r
309}
310
311; hwasan and memtag should be similarly suppressed.
312
313define <8 x i16> @gep10_load_i16_insert_v8i16_hwasan(<8 x i16>* align 16 dereferenceable(32) %p) sanitize_hwaddress {
314; CHECK-LABEL: @gep10_load_i16_insert_v8i16_hwasan(
315; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds <8 x i16>, <8 x i16>* [[P:%.*]], i64 1, i64 0
316; CHECK-NEXT:    [[S:%.*]] = load i16, i16* [[GEP]], align 16
317; CHECK-NEXT:    [[R:%.*]] = insertelement <8 x i16> undef, i16 [[S]], i64 0
318; CHECK-NEXT:    ret <8 x i16> [[R]]
319;
320  %gep = getelementptr inbounds <8 x i16>, <8 x i16>* %p, i64 1, i64 0
321  %s = load i16, i16* %gep, align 16
322  %r = insertelement <8 x i16> undef, i16 %s, i64 0
323  ret <8 x i16> %r
324}
325
326define <8 x i16> @gep10_load_i16_insert_v8i16_memtag(<8 x i16>* align 16 dereferenceable(32) %p) sanitize_memtag {
327; CHECK-LABEL: @gep10_load_i16_insert_v8i16_memtag(
328; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds <8 x i16>, <8 x i16>* [[P:%.*]], i64 1, i64 0
329; CHECK-NEXT:    [[S:%.*]] = load i16, i16* [[GEP]], align 16
330; CHECK-NEXT:    [[R:%.*]] = insertelement <8 x i16> undef, i16 [[S]], i64 0
331; CHECK-NEXT:    ret <8 x i16> [[R]]
332;
333  %gep = getelementptr inbounds <8 x i16>, <8 x i16>* %p, i64 1, i64 0
334  %s = load i16, i16* %gep, align 16
335  %r = insertelement <8 x i16> undef, i16 %s, i64 0
336  ret <8 x i16> %r
337}
338
339; Negative test - disable under tsan because widened load may overlap bytes
340; being concurrently modified. tsan does not know that some bytes are undef.
341
342define <8 x i16> @gep10_load_i16_insert_v8i16_tsan(<8 x i16>* align 16 dereferenceable(32) %p) sanitize_thread {
343; CHECK-LABEL: @gep10_load_i16_insert_v8i16_tsan(
344; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds <8 x i16>, <8 x i16>* [[P:%.*]], i64 1, i64 0
345; CHECK-NEXT:    [[S:%.*]] = load i16, i16* [[GEP]], align 16
346; CHECK-NEXT:    [[R:%.*]] = insertelement <8 x i16> undef, i16 [[S]], i64 0
347; CHECK-NEXT:    ret <8 x i16> [[R]]
348;
349  %gep = getelementptr inbounds <8 x i16>, <8 x i16>* %p, i64 1, i64 0
350  %s = load i16, i16* %gep, align 16
351  %r = insertelement <8 x i16> undef, i16 %s, i64 0
352  ret <8 x i16> %r
353}
354
355; Negative test - can't safely load the offset vector, but could load+shuffle.
356
357define <8 x i16> @gep10_load_i16_insert_v8i16_deref(<8 x i16>* align 16 dereferenceable(31) %p) {
358; CHECK-LABEL: @gep10_load_i16_insert_v8i16_deref(
359; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds <8 x i16>, <8 x i16>* [[P:%.*]], i64 1, i64 0
360; CHECK-NEXT:    [[S:%.*]] = load i16, i16* [[GEP]], align 16
361; CHECK-NEXT:    [[R:%.*]] = insertelement <8 x i16> undef, i16 [[S]], i64 0
362; CHECK-NEXT:    ret <8 x i16> [[R]]
363;
364  %gep = getelementptr inbounds <8 x i16>, <8 x i16>* %p, i64 1, i64 0
365  %s = load i16, i16* %gep, align 16
366  %r = insertelement <8 x i16> undef, i16 %s, i64 0
367  ret <8 x i16> %r
368}
369
370; Negative test - do not alter volatile.
371
372define <4 x float> @load_f32_insert_v4f32_volatile(float* align 16 dereferenceable(16) %p) {
373; CHECK-LABEL: @load_f32_insert_v4f32_volatile(
374; CHECK-NEXT:    [[S:%.*]] = load volatile float, float* [[P:%.*]], align 4
375; CHECK-NEXT:    [[R:%.*]] = insertelement <4 x float> undef, float [[S]], i32 0
376; CHECK-NEXT:    ret <4 x float> [[R]]
377;
378  %s = load volatile float, float* %p, align 4
379  %r = insertelement <4 x float> undef, float %s, i32 0
380  ret <4 x float> %r
381}
382
383; Negative test? - pointer is not as aligned as load.
384
385define <4 x float> @load_f32_insert_v4f32_align(float* align 1 dereferenceable(16) %p) {
386; CHECK-LABEL: @load_f32_insert_v4f32_align(
387; CHECK-NEXT:    [[S:%.*]] = load float, float* [[P:%.*]], align 4
388; CHECK-NEXT:    [[R:%.*]] = insertelement <4 x float> undef, float [[S]], i32 0
389; CHECK-NEXT:    ret <4 x float> [[R]]
390;
391  %s = load float, float* %p, align 4
392  %r = insertelement <4 x float> undef, float %s, i32 0
393  ret <4 x float> %r
394}
395
396; Negative test - not enough bytes.
397
398define <4 x float> @load_f32_insert_v4f32_deref(float* align 4 dereferenceable(15) %p) {
399; CHECK-LABEL: @load_f32_insert_v4f32_deref(
400; CHECK-NEXT:    [[S:%.*]] = load float, float* [[P:%.*]], align 4
401; CHECK-NEXT:    [[R:%.*]] = insertelement <4 x float> undef, float [[S]], i32 0
402; CHECK-NEXT:    ret <4 x float> [[R]]
403;
404  %s = load float, float* %p, align 4
405  %r = insertelement <4 x float> undef, float %s, i32 0
406  ret <4 x float> %r
407}
408
409define <8 x i32> @load_i32_insert_v8i32(i32* align 16 dereferenceable(16) %p) {
410; CHECK-LABEL: @load_i32_insert_v8i32(
411; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i32* [[P:%.*]] to <4 x i32>*
412; CHECK-NEXT:    [[TMP2:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]], align 4
413; CHECK-NEXT:    [[R:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef>
414; CHECK-NEXT:    ret <8 x i32> [[R]]
415;
416  %s = load i32, i32* %p, align 4
417  %r = insertelement <8 x i32> undef, i32 %s, i32 0
418  ret <8 x i32> %r
419}
420
421define <8 x i32> @casted_load_i32_insert_v8i32(<4 x i32>* align 4 dereferenceable(16) %p) {
422; CHECK-LABEL: @casted_load_i32_insert_v8i32(
423; CHECK-NEXT:    [[TMP1:%.*]] = load <4 x i32>, <4 x i32>* [[P:%.*]], align 4
424; CHECK-NEXT:    [[R:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef>
425; CHECK-NEXT:    ret <8 x i32> [[R]]
426;
427  %b = bitcast <4 x i32>* %p to i32*
428  %s = load i32, i32* %b, align 4
429  %r = insertelement <8 x i32> undef, i32 %s, i32 0
430  ret <8 x i32> %r
431}
432
433define <16 x float> @load_f32_insert_v16f32(float* align 16 dereferenceable(16) %p) {
434; CHECK-LABEL: @load_f32_insert_v16f32(
435; CHECK-NEXT:    [[TMP1:%.*]] = bitcast float* [[P:%.*]] to <4 x float>*
436; CHECK-NEXT:    [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4
437; CHECK-NEXT:    [[R:%.*]] = shufflevector <4 x float> [[TMP2]], <4 x float> undef, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
438; CHECK-NEXT:    ret <16 x float> [[R]]
439;
440  %s = load float, float* %p, align 4
441  %r = insertelement <16 x float> undef, float %s, i32 0
442  ret <16 x float> %r
443}
444
445define <2 x float> @load_f32_insert_v2f32(float* align 16 dereferenceable(16) %p) {
446; CHECK-LABEL: @load_f32_insert_v2f32(
447; CHECK-NEXT:    [[TMP1:%.*]] = bitcast float* [[P:%.*]] to <4 x float>*
448; CHECK-NEXT:    [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4
449; CHECK-NEXT:    [[R:%.*]] = shufflevector <4 x float> [[TMP2]], <4 x float> undef, <2 x i32> <i32 0, i32 1>
450; CHECK-NEXT:    ret <2 x float> [[R]]
451;
452  %s = load float, float* %p, align 4
453  %r = insertelement <2 x float> undef, float %s, i32 0
454  ret <2 x float> %r
455}
456
457; Negative test - suppress load widening for asan/hwasan/memtag/tsan.
458
459define <2 x float> @load_f32_insert_v2f32_asan(float* align 16 dereferenceable(16) %p) sanitize_address {
460; CHECK-LABEL: @load_f32_insert_v2f32_asan(
461; CHECK-NEXT:    [[S:%.*]] = load float, float* [[P:%.*]], align 4
462; CHECK-NEXT:    [[R:%.*]] = insertelement <2 x float> undef, float [[S]], i32 0
463; CHECK-NEXT:    ret <2 x float> [[R]]
464;
465  %s = load float, float* %p, align 4
466  %r = insertelement <2 x float> undef, float %s, i32 0
467  ret <2 x float> %r
468}
469
470declare float* @getscaleptr()
471define void @PR47558_multiple_use_load(<2 x float>* nocapture nonnull %resultptr, <2 x float>* nocapture nonnull readonly %opptr) {
472; CHECK-LABEL: @PR47558_multiple_use_load(
473; CHECK-NEXT:    [[SCALEPTR:%.*]] = tail call nonnull align 16 dereferenceable(64) float* @getscaleptr()
474; CHECK-NEXT:    [[OP:%.*]] = load <2 x float>, <2 x float>* [[OPPTR:%.*]], align 4
475; CHECK-NEXT:    [[SCALE:%.*]] = load float, float* [[SCALEPTR]], align 16
476; CHECK-NEXT:    [[T1:%.*]] = insertelement <2 x float> undef, float [[SCALE]], i32 0
477; CHECK-NEXT:    [[T2:%.*]] = insertelement <2 x float> [[T1]], float [[SCALE]], i32 1
478; CHECK-NEXT:    [[T3:%.*]] = fmul <2 x float> [[OP]], [[T2]]
479; CHECK-NEXT:    [[T4:%.*]] = extractelement <2 x float> [[T3]], i32 0
480; CHECK-NEXT:    [[RESULT0:%.*]] = insertelement <2 x float> undef, float [[T4]], i32 0
481; CHECK-NEXT:    [[T5:%.*]] = extractelement <2 x float> [[T3]], i32 1
482; CHECK-NEXT:    [[RESULT1:%.*]] = insertelement <2 x float> [[RESULT0]], float [[T5]], i32 1
483; CHECK-NEXT:    store <2 x float> [[RESULT1]], <2 x float>* [[RESULTPTR:%.*]], align 8
484; CHECK-NEXT:    ret void
485;
486  %scaleptr = tail call nonnull align 16 dereferenceable(64) float* @getscaleptr()
487  %op = load <2 x float>, <2 x float>* %opptr, align 4
488  %scale = load float, float* %scaleptr, align 16
489  %t1 = insertelement <2 x float> undef, float %scale, i32 0
490  %t2 = insertelement <2 x float> %t1, float %scale, i32 1
491  %t3 = fmul <2 x float> %op, %t2
492  %t4 = extractelement <2 x float> %t3, i32 0
493  %result0 = insertelement <2 x float> undef, float %t4, i32 0
494  %t5 = extractelement <2 x float> %t3, i32 1
495  %result1 = insertelement <2 x float> %result0, float %t5, i32 1
496  store <2 x float> %result1, <2 x float>* %resultptr, align 8
497  ret void
498}
499