1 ; RUN: llc -march=x86-64 -mcpu=corei7 -mattr=+avx < %s | FileCheck %s
2 ; RUN: llc -march=x86-64 -mcpu=corei7 -mattr=+avx -addr-sink-using-gep=1 < %s | FileCheck %s
4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
5 target triple = "x86_64-apple-macosx10.8.0"
7 %struct.A = type { i8, i8, i8, i8, i8, i8, i8, i8 }
8 %struct.B = type { i32, i32, i32, i32, i32, i32, i32, i32 }
10 ; CHECK: merge_const_store
11 ; save 1,2,3 ... as one big integer.
12 ; CHECK: movabsq $578437695752307201
14 define void @merge_const_store(i32 %count, %struct.A* nocapture %p) nounwind uwtable noinline ssp {
15 %1 = icmp sgt i32 %count, 0
16 br i1 %1, label %.lr.ph, label %._crit_edge
18 %i.02 = phi i32 [ %10, %.lr.ph ], [ 0, %0 ]
19 %.01 = phi %struct.A* [ %11, %.lr.ph ], [ %p, %0 ]
20 %2 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 0
21 store i8 1, i8* %2, align 1
22 %3 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 1
23 store i8 2, i8* %3, align 1
24 %4 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 2
25 store i8 3, i8* %4, align 1
26 %5 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 3
27 store i8 4, i8* %5, align 1
28 %6 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 4
29 store i8 5, i8* %6, align 1
30 %7 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 5
31 store i8 6, i8* %7, align 1
32 %8 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 6
33 store i8 7, i8* %8, align 1
34 %9 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 7
35 store i8 8, i8* %9, align 1
36 %10 = add nsw i32 %i.02, 1
37 %11 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 1
38 %exitcond = icmp eq i32 %10, %count
39 br i1 %exitcond, label %._crit_edge, label %.lr.ph
44 ; No vectors because we use noimplicitfloat
45 ; CHECK: merge_const_store_no_vec
48 define void @merge_const_store_no_vec(i32 %count, %struct.B* nocapture %p) noimplicitfloat{
49 %1 = icmp sgt i32 %count, 0
50 br i1 %1, label %.lr.ph, label %._crit_edge
52 %i.02 = phi i32 [ %10, %.lr.ph ], [ 0, %0 ]
53 %.01 = phi %struct.B* [ %11, %.lr.ph ], [ %p, %0 ]
54 %2 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 0
55 store i32 0, i32* %2, align 4
56 %3 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 1
57 store i32 0, i32* %3, align 4
58 %4 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 2
59 store i32 0, i32* %4, align 4
60 %5 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 3
61 store i32 0, i32* %5, align 4
62 %6 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 4
63 store i32 0, i32* %6, align 4
64 %7 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 5
65 store i32 0, i32* %7, align 4
66 %8 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 6
67 store i32 0, i32* %8, align 4
68 %9 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 7
69 store i32 0, i32* %9, align 4
70 %10 = add nsw i32 %i.02, 1
71 %11 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 1
72 %exitcond = icmp eq i32 %10, %count
73 br i1 %exitcond, label %._crit_edge, label %.lr.ph
78 ; Move the constants using a single vector store.
79 ; CHECK: merge_const_store_vec
82 define void @merge_const_store_vec(i32 %count, %struct.B* nocapture %p) nounwind uwtable noinline ssp {
83 %1 = icmp sgt i32 %count, 0
84 br i1 %1, label %.lr.ph, label %._crit_edge
86 %i.02 = phi i32 [ %10, %.lr.ph ], [ 0, %0 ]
87 %.01 = phi %struct.B* [ %11, %.lr.ph ], [ %p, %0 ]
88 %2 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 0
89 store i32 0, i32* %2, align 4
90 %3 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 1
91 store i32 0, i32* %3, align 4
92 %4 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 2
93 store i32 0, i32* %4, align 4
94 %5 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 3
95 store i32 0, i32* %5, align 4
96 %6 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 4
97 store i32 0, i32* %6, align 4
98 %7 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 5
99 store i32 0, i32* %7, align 4
100 %8 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 6
101 store i32 0, i32* %8, align 4
102 %9 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 7
103 store i32 0, i32* %9, align 4
104 %10 = add nsw i32 %i.02, 1
105 %11 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 1
106 %exitcond = icmp eq i32 %10, %count
107 br i1 %exitcond, label %._crit_edge, label %.lr.ph
112 ; Move the first 4 constants as a single vector. Move the rest as scalars.
113 ; CHECK: merge_nonconst_store
114 ; CHECK: movl $67305985
120 define void @merge_nonconst_store(i32 %count, i8 %zz, %struct.A* nocapture %p) nounwind uwtable noinline ssp {
121 %1 = icmp sgt i32 %count, 0
122 br i1 %1, label %.lr.ph, label %._crit_edge
124 %i.02 = phi i32 [ %10, %.lr.ph ], [ 0, %0 ]
125 %.01 = phi %struct.A* [ %11, %.lr.ph ], [ %p, %0 ]
126 %2 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 0
127 store i8 1, i8* %2, align 1
128 %3 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 1
129 store i8 2, i8* %3, align 1
130 %4 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 2
131 store i8 3, i8* %4, align 1
132 %5 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 3
133 store i8 4, i8* %5, align 1
134 %6 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 4
135 store i8 %zz, i8* %6, align 1 ; <----------- Not a const;
136 %7 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 5
137 store i8 6, i8* %7, align 1
138 %8 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 6
139 store i8 7, i8* %8, align 1
140 %9 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 7
141 store i8 8, i8* %9, align 1
142 %10 = add nsw i32 %i.02, 1
143 %11 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 1
144 %exitcond = icmp eq i32 %10, %count
145 br i1 %exitcond, label %._crit_edge, label %.lr.ph
151 ; CHECK-LABEL: merge_loads_i16:
157 define void @merge_loads_i16(i32 %count, %struct.A* noalias nocapture %q, %struct.A* noalias nocapture %p) nounwind uwtable noinline ssp {
158 %1 = icmp sgt i32 %count, 0
159 br i1 %1, label %.lr.ph, label %._crit_edge
162 %2 = getelementptr inbounds %struct.A, %struct.A* %q, i64 0, i32 0
163 %3 = getelementptr inbounds %struct.A, %struct.A* %q, i64 0, i32 1
166 ; <label>:4 ; preds = %4, %.lr.ph
167 %i.02 = phi i32 [ 0, %.lr.ph ], [ %9, %4 ]
168 %.01 = phi %struct.A* [ %p, %.lr.ph ], [ %10, %4 ]
169 %5 = load i8, i8* %2, align 1
170 %6 = load i8, i8* %3, align 1
171 %7 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 0
172 store i8 %5, i8* %7, align 1
173 %8 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 1
174 store i8 %6, i8* %8, align 1
175 %9 = add nsw i32 %i.02, 1
176 %10 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 1
177 %exitcond = icmp eq i32 %9, %count
178 br i1 %exitcond, label %._crit_edge, label %4
180 ._crit_edge: ; preds = %4, %0
184 ; The loads and the stores are interleaved. Can't merge them.
185 ; CHECK-LABEL: no_merge_loads:
191 define void @no_merge_loads(i32 %count, %struct.A* noalias nocapture %q, %struct.A* noalias nocapture %p) nounwind uwtable noinline ssp {
192 %1 = icmp sgt i32 %count, 0
193 br i1 %1, label %.lr.ph, label %._crit_edge
196 %2 = getelementptr inbounds %struct.A, %struct.A* %q, i64 0, i32 0
197 %3 = getelementptr inbounds %struct.A, %struct.A* %q, i64 0, i32 1
200 a4: ; preds = %4, %.lr.ph
201 %i.02 = phi i32 [ 0, %.lr.ph ], [ %a9, %a4 ]
202 %.01 = phi %struct.A* [ %p, %.lr.ph ], [ %a10, %a4 ]
203 %a5 = load i8, i8* %2, align 1
204 %a7 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 0
205 store i8 %a5, i8* %a7, align 1
206 %a8 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 1
207 %a6 = load i8, i8* %3, align 1
208 store i8 %a6, i8* %a8, align 1
209 %a9 = add nsw i32 %i.02, 1
210 %a10 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 1
211 %exitcond = icmp eq i32 %a9, %count
212 br i1 %exitcond, label %._crit_edge, label %a4
214 ._crit_edge: ; preds = %4, %0
219 ; CHECK-LABEL: merge_loads_integer:
225 define void @merge_loads_integer(i32 %count, %struct.B* noalias nocapture %q, %struct.B* noalias nocapture %p) nounwind uwtable noinline ssp {
226 %1 = icmp sgt i32 %count, 0
227 br i1 %1, label %.lr.ph, label %._crit_edge
230 %2 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 0
231 %3 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 1
234 ; <label>:4 ; preds = %4, %.lr.ph
235 %i.02 = phi i32 [ 0, %.lr.ph ], [ %9, %4 ]
236 %.01 = phi %struct.B* [ %p, %.lr.ph ], [ %10, %4 ]
237 %5 = load i32, i32* %2
238 %6 = load i32, i32* %3
239 %7 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 0
240 store i32 %5, i32* %7
241 %8 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 1
242 store i32 %6, i32* %8
243 %9 = add nsw i32 %i.02, 1
244 %10 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 1
245 %exitcond = icmp eq i32 %9, %count
246 br i1 %exitcond, label %._crit_edge, label %4
248 ._crit_edge: ; preds = %4, %0
253 ; CHECK-LABEL: merge_loads_vector:
259 define void @merge_loads_vector(i32 %count, %struct.B* noalias nocapture %q, %struct.B* noalias nocapture %p) nounwind uwtable noinline ssp {
260 %a1 = icmp sgt i32 %count, 0
261 br i1 %a1, label %.lr.ph, label %._crit_edge
264 %a2 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 0
265 %a3 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 1
266 %a4 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 2
267 %a5 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 3
270 block4: ; preds = %4, %.lr.ph
271 %i.02 = phi i32 [ 0, %.lr.ph ], [ %c9, %block4 ]
272 %.01 = phi %struct.B* [ %p, %.lr.ph ], [ %c10, %block4 ]
273 %a7 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 0
274 %a8 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 1
275 %a9 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 2
276 %a10 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 3
277 %b1 = load i32, i32* %a2
278 %b2 = load i32, i32* %a3
279 %b3 = load i32, i32* %a4
280 %b4 = load i32, i32* %a5
281 store i32 %b1, i32* %a7
282 store i32 %b2, i32* %a8
283 store i32 %b3, i32* %a9
284 store i32 %b4, i32* %a10
285 %c9 = add nsw i32 %i.02, 1
286 %c10 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 1
287 %exitcond = icmp eq i32 %c9, %count
288 br i1 %exitcond, label %._crit_edge, label %block4
290 ._crit_edge: ; preds = %4, %0
294 ;; On x86, even unaligned copies can be merged to vector ops.
295 ; CHECK-LABEL: merge_loads_no_align:
301 define void @merge_loads_no_align(i32 %count, %struct.B* noalias nocapture %q, %struct.B* noalias nocapture %p) nounwind uwtable noinline ssp {
302 %a1 = icmp sgt i32 %count, 0
303 br i1 %a1, label %.lr.ph, label %._crit_edge
306 %a2 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 0
307 %a3 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 1
308 %a4 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 2
309 %a5 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 3
312 block4: ; preds = %4, %.lr.ph
313 %i.02 = phi i32 [ 0, %.lr.ph ], [ %c9, %block4 ]
314 %.01 = phi %struct.B* [ %p, %.lr.ph ], [ %c10, %block4 ]
315 %a7 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 0
316 %a8 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 1
317 %a9 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 2
318 %a10 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 3
319 %b1 = load i32, i32* %a2, align 1
320 %b2 = load i32, i32* %a3, align 1
321 %b3 = load i32, i32* %a4, align 1
322 %b4 = load i32, i32* %a5, align 1
323 store i32 %b1, i32* %a7, align 1
324 store i32 %b2, i32* %a8, align 1
325 store i32 %b3, i32* %a9, align 1
326 store i32 %b4, i32* %a10, align 1
327 %c9 = add nsw i32 %i.02, 1
328 %c10 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 1
329 %exitcond = icmp eq i32 %c9, %count
330 br i1 %exitcond, label %._crit_edge, label %block4
332 ._crit_edge: ; preds = %4, %0
336 ; Make sure that we merge the consecutive load/store sequence below and use a
337 ; word (16 bit) instead of a byte copy.
338 ; CHECK: MergeLoadStoreBaseIndexOffset
339 ; CHECK: movw (%{{.*}},%{{.*}}), [[REG:%[a-z]+]]
340 ; CHECK: movw [[REG]], (%{{.*}})
341 define void @MergeLoadStoreBaseIndexOffset(i64* %a, i8* %b, i8* %c, i32 %n) {
345 %.09 = phi i32 [ %n, %0 ], [ %11, %1 ]
346 %.08 = phi i8* [ %b, %0 ], [ %10, %1 ]
347 %.0 = phi i64* [ %a, %0 ], [ %2, %1 ]
348 %2 = getelementptr inbounds i64, i64* %.0, i64 1
349 %3 = load i64, i64* %.0, align 1
350 %4 = getelementptr inbounds i8, i8* %c, i64 %3
351 %5 = load i8, i8* %4, align 1
353 %7 = getelementptr inbounds i8, i8* %c, i64 %6
354 %8 = load i8, i8* %7, align 1
355 store i8 %5, i8* %.08, align 1
356 %9 = getelementptr inbounds i8, i8* %.08, i64 1
357 store i8 %8, i8* %9, align 1
358 %10 = getelementptr inbounds i8, i8* %.08, i64 2
359 %11 = add nsw i32 %.09, -1
360 %12 = icmp eq i32 %11, 0
361 br i1 %12, label %13, label %1
367 ; Make sure that we merge the consecutive load/store sequence below and use a
368 ; word (16 bit) instead of a byte copy even if there are intermediate sign
370 ; CHECK: MergeLoadStoreBaseIndexOffsetSext
371 ; CHECK: movw (%{{.*}},%{{.*}}), [[REG:%[a-z]+]]
372 ; CHECK: movw [[REG]], (%{{.*}})
373 define void @MergeLoadStoreBaseIndexOffsetSext(i8* %a, i8* %b, i8* %c, i32 %n) {
377 %.09 = phi i32 [ %n, %0 ], [ %12, %1 ]
378 %.08 = phi i8* [ %b, %0 ], [ %11, %1 ]
379 %.0 = phi i8* [ %a, %0 ], [ %2, %1 ]
380 %2 = getelementptr inbounds i8, i8* %.0, i64 1
381 %3 = load i8, i8* %.0, align 1
382 %4 = sext i8 %3 to i64
383 %5 = getelementptr inbounds i8, i8* %c, i64 %4
384 %6 = load i8, i8* %5, align 1
386 %8 = getelementptr inbounds i8, i8* %c, i64 %7
387 %9 = load i8, i8* %8, align 1
388 store i8 %6, i8* %.08, align 1
389 %10 = getelementptr inbounds i8, i8* %.08, i64 1
390 store i8 %9, i8* %10, align 1
391 %11 = getelementptr inbounds i8, i8* %.08, i64 2
392 %12 = add nsw i32 %.09, -1
393 %13 = icmp eq i32 %12, 0
394 br i1 %13, label %14, label %1
400 ; However, we can only merge ignore sign extensions when they are on all memory
402 ; CHECK: loadStoreBaseIndexOffsetSextNoSex
403 ; CHECK-NOT: movw (%{{.*}},%{{.*}}), [[REG:%[a-z]+]]
404 ; CHECK-NOT: movw [[REG]], (%{{.*}})
405 define void @loadStoreBaseIndexOffsetSextNoSex(i8* %a, i8* %b, i8* %c, i32 %n) {
409 %.09 = phi i32 [ %n, %0 ], [ %12, %1 ]
410 %.08 = phi i8* [ %b, %0 ], [ %11, %1 ]
411 %.0 = phi i8* [ %a, %0 ], [ %2, %1 ]
412 %2 = getelementptr inbounds i8, i8* %.0, i64 1
413 %3 = load i8, i8* %.0, align 1
414 %4 = sext i8 %3 to i64
415 %5 = getelementptr inbounds i8, i8* %c, i64 %4
416 %6 = load i8, i8* %5, align 1
418 %wrap.4 = sext i8 %7 to i64
419 %8 = getelementptr inbounds i8, i8* %c, i64 %wrap.4
420 %9 = load i8, i8* %8, align 1
421 store i8 %6, i8* %.08, align 1
422 %10 = getelementptr inbounds i8, i8* %.08, i64 1
423 store i8 %9, i8* %10, align 1
424 %11 = getelementptr inbounds i8, i8* %.08, i64 2
425 %12 = add nsw i32 %.09, -1
426 %13 = icmp eq i32 %12, 0
427 br i1 %13, label %14, label %1
433 ; PR21711 ( http://llvm.org/bugs/show_bug.cgi?id=21711 )
434 define void @merge_vec_element_store(<8 x float> %v, float* %ptr) {
435 %vecext0 = extractelement <8 x float> %v, i32 0
436 %vecext1 = extractelement <8 x float> %v, i32 1
437 %vecext2 = extractelement <8 x float> %v, i32 2
438 %vecext3 = extractelement <8 x float> %v, i32 3
439 %vecext4 = extractelement <8 x float> %v, i32 4
440 %vecext5 = extractelement <8 x float> %v, i32 5
441 %vecext6 = extractelement <8 x float> %v, i32 6
442 %vecext7 = extractelement <8 x float> %v, i32 7
443 %arrayidx1 = getelementptr inbounds float, float* %ptr, i64 1
444 %arrayidx2 = getelementptr inbounds float, float* %ptr, i64 2
445 %arrayidx3 = getelementptr inbounds float, float* %ptr, i64 3
446 %arrayidx4 = getelementptr inbounds float, float* %ptr, i64 4
447 %arrayidx5 = getelementptr inbounds float, float* %ptr, i64 5
448 %arrayidx6 = getelementptr inbounds float, float* %ptr, i64 6
449 %arrayidx7 = getelementptr inbounds float, float* %ptr, i64 7
450 store float %vecext0, float* %ptr, align 4
451 store float %vecext1, float* %arrayidx1, align 4
452 store float %vecext2, float* %arrayidx2, align 4
453 store float %vecext3, float* %arrayidx3, align 4
454 store float %vecext4, float* %arrayidx4, align 4
455 store float %vecext5, float* %arrayidx5, align 4
456 store float %vecext6, float* %arrayidx6, align 4
457 store float %vecext7, float* %arrayidx7, align 4
460 ; CHECK-LABEL: merge_vec_element_store
462 ; CHECK-NEXT: vzeroupper
466 ; PR21711 - Merge vector stores into wider vector stores.
467 ; These should be merged into 32-byte stores.
468 define void @merge_vec_extract_stores(<8 x float> %v1, <8 x float> %v2, <4 x float>* %ptr) {
469 %idx0 = getelementptr inbounds <4 x float>, <4 x float>* %ptr, i64 3
470 %idx1 = getelementptr inbounds <4 x float>, <4 x float>* %ptr, i64 4
471 %idx2 = getelementptr inbounds <4 x float>, <4 x float>* %ptr, i64 5
472 %idx3 = getelementptr inbounds <4 x float>, <4 x float>* %ptr, i64 6
473 %shuffle0 = shufflevector <8 x float> %v1, <8 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
474 %shuffle1 = shufflevector <8 x float> %v1, <8 x float> undef, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
475 %shuffle2 = shufflevector <8 x float> %v2, <8 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
476 %shuffle3 = shufflevector <8 x float> %v2, <8 x float> undef, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
477 store <4 x float> %shuffle0, <4 x float>* %idx0, align 16
478 store <4 x float> %shuffle1, <4 x float>* %idx1, align 16
479 store <4 x float> %shuffle2, <4 x float>* %idx2, align 16
480 store <4 x float> %shuffle3, <4 x float>* %idx3, align 16
483 ; CHECK-LABEL: merge_vec_extract_stores
484 ; CHECK: vmovaps %xmm0, 48(%rdi)
485 ; CHECK-NEXT: vextractf128 $1, %ymm0, 64(%rdi)
486 ; CHECK-NEXT: vmovaps %xmm1, 80(%rdi)
487 ; CHECK-NEXT: vextractf128 $1, %ymm1, 96(%rdi)
488 ; CHECK-NEXT: vzeroupper
492 ; Merging vector stores when sourced from vector loads is not currently handled.
493 define void @merge_vec_stores_from_loads(<4 x float>* %v, <4 x float>* %ptr) {
494 %load_idx0 = getelementptr inbounds <4 x float>, <4 x float>* %v, i64 0
495 %load_idx1 = getelementptr inbounds <4 x float>, <4 x float>* %v, i64 1
496 %v0 = load <4 x float>, <4 x float>* %load_idx0
497 %v1 = load <4 x float>, <4 x float>* %load_idx1
498 %store_idx0 = getelementptr inbounds <4 x float>, <4 x float>* %ptr, i64 0
499 %store_idx1 = getelementptr inbounds <4 x float>, <4 x float>* %ptr, i64 1
500 store <4 x float> %v0, <4 x float>* %store_idx0, align 16
501 store <4 x float> %v1, <4 x float>* %store_idx1, align 16
504 ; CHECK-LABEL: merge_vec_stores_from_loads
506 ; CHECK-NEXT: vmovaps
507 ; CHECK-NEXT: vmovaps
508 ; CHECK-NEXT: vmovaps
512 ; Merging vector stores when sourced from a constant vector is not currently handled.
513 define void @merge_vec_stores_of_constants(<4 x i32>* %ptr) {
514 %idx0 = getelementptr inbounds <4 x i32>, <4 x i32>* %ptr, i64 3
515 %idx1 = getelementptr inbounds <4 x i32>, <4 x i32>* %ptr, i64 4
516 store <4 x i32> <i32 0, i32 0, i32 0, i32 0>, <4 x i32>* %idx0, align 16
517 store <4 x i32> <i32 0, i32 0, i32 0, i32 0>, <4 x i32>* %idx1, align 16
520 ; CHECK-LABEL: merge_vec_stores_of_constants
522 ; CHECK-NEXT: vmovaps
523 ; CHECK-NEXT: vmovaps
527 ; This is a minimized test based on real code that was failing.
528 ; We could merge stores (and loads) like this...
530 define void @merge_vec_element_and_scalar_load([6 x i64]* %array) {
531 %idx0 = getelementptr inbounds [6 x i64], [6 x i64]* %array, i64 0, i64 0
532 %idx1 = getelementptr inbounds [6 x i64], [6 x i64]* %array, i64 0, i64 1
533 %idx4 = getelementptr inbounds [6 x i64], [6 x i64]* %array, i64 0, i64 4
534 %idx5 = getelementptr inbounds [6 x i64], [6 x i64]* %array, i64 0, i64 5
536 %a0 = load i64, i64* %idx0, align 8
537 store i64 %a0, i64* %idx4, align 8
539 %b = bitcast i64* %idx1 to <2 x i64>*
540 %v = load <2 x i64>, <2 x i64>* %b, align 8
541 %a1 = extractelement <2 x i64> %v, i32 0
542 store i64 %a1, i64* %idx5, align 8
545 ; CHECK-LABEL: merge_vec_element_and_scalar_load
546 ; CHECK: movq (%rdi), %rax
547 ; CHECK-NEXT: movq %rax, 32(%rdi)
548 ; CHECK-NEXT: movq 8(%rdi), %rax
549 ; CHECK-NEXT: movq %rax, 40(%rdi)