Fix alignment checks in MergeConsecutiveStores.
[oota-llvm.git] / test / CodeGen / X86 / MergeConsecutiveStores.ll
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
3
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"
6
7 %struct.A = type { i8, i8, i8, i8, i8, i8, i8, i8 }
8 %struct.B = type { i32, i32, i32, i32, i32, i32, i32, i32 }
9
10 ; CHECK: merge_const_store
11 ; save 1,2,3 ... as one big integer.
12 ; CHECK: movabsq $578437695752307201
13 ; CHECK: ret
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
17 .lr.ph:
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
40 ._crit_edge:
41   ret void
42 }
43
44 ; No vectors because we use noimplicitfloat
45 ; CHECK: merge_const_store_no_vec
46 ; CHECK-NOT: vmovups
47 ; CHECK: ret
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
51 .lr.ph:
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
74 ._crit_edge:
75   ret void
76 }
77
78 ; Move the constants using a single vector store.
79 ; CHECK: merge_const_store_vec
80 ; CHECK: vmovups
81 ; CHECK: ret
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
85 .lr.ph:
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
108 ._crit_edge:
109   ret void
110 }
111
112 ; Move the first 4 constants as a single vector. Move the rest as scalars.
113 ; CHECK: merge_nonconst_store
114 ; CHECK: movl $67305985
115 ; CHECK: movb
116 ; CHECK: movb
117 ; CHECK: movb
118 ; CHECK: movb
119 ; CHECK: ret
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
123 .lr.ph:
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
146 ._crit_edge:
147   ret void
148 }
149
150
151 ; CHECK-LABEL: merge_loads_i16:
152 ;  load:
153 ; CHECK: movw
154 ;  store:
155 ; CHECK: movw
156 ; CHECK: ret
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
160
161 .lr.ph:                                           ; preds = %0
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
164   br label %4
165
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
179
180 ._crit_edge:                                      ; preds = %4, %0
181   ret void
182 }
183
184 ; The loads and the stores are interleaved. Can't merge them.
185 ; CHECK-LABEL: no_merge_loads:
186 ; CHECK: movb
187 ; CHECK: movb
188 ; CHECK: movb
189 ; CHECK: movb
190 ; CHECK: ret
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
194
195 .lr.ph:                                           ; preds = %0
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
198   br label %a4
199
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
213
214 ._crit_edge:                                      ; preds = %4, %0
215   ret void
216 }
217
218
219 ; CHECK-LABEL: merge_loads_integer:
220 ;  load:
221 ; CHECK: movq
222 ;  store:
223 ; CHECK: movq
224 ; CHECK: ret
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
228
229 .lr.ph:                                           ; preds = %0
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
232   br label %4
233
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
247
248 ._crit_edge:                                      ; preds = %4, %0
249   ret void
250 }
251
252
253 ; CHECK-LABEL: merge_loads_vector:
254 ;  load:
255 ; CHECK: movups
256 ;  store:
257 ; CHECK: movups
258 ; CHECK: ret
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
262
263 .lr.ph:                                           ; preds = %0
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
268   br label %block4
269
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
289
290 ._crit_edge:                                      ; preds = %4, %0
291   ret void
292 }
293
294 ;; On x86, even unaligned copies can be merged to vector ops.
295 ; CHECK-LABEL: merge_loads_no_align:
296 ;  load:
297 ; CHECK: vmovups
298 ;  store:
299 ; CHECK: vmovups
300 ; CHECK: ret
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
304
305 .lr.ph:                                           ; preds = %0
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
310   br label %block4
311
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
331
332 ._crit_edge:                                      ; preds = %4, %0
333   ret void
334 }
335
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) {
342   br label %1
343
344 ; <label>:1
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
352   %6 = add i64 %3, 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
362
363 ; <label>:13
364   ret void
365 }
366
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
369 ; extensions.
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) {
374   br label %1
375
376 ; <label>:1
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
385   %7 = add i64 %4, 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
395
396 ; <label>:14
397   ret void
398 }
399
400 ; However, we can only merge ignore sign extensions when they are on all memory
401 ; computations;
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) {
406   br label %1
407
408 ; <label>:1
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
417   %7 = add i8 %3, 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
428
429 ; <label>:14
430   ret void
431 }
432
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
458   ret void
459
460 ; CHECK-LABEL: merge_vec_element_store
461 ; CHECK: vmovups
462 ; CHECK-NEXT: vzeroupper
463 ; CHECK-NEXT: retq
464 }
465
466 ; This is a minimized test based on real code that was failing.
467 ; We could merge stores (and loads) like this...
468
469 define void @merge_vec_element_and_scalar_load([6 x i64]* %array) {
470   %idx0 = getelementptr inbounds [6 x i64], [6 x i64]* %array, i64 0, i64 0
471   %idx1 = getelementptr inbounds [6 x i64], [6 x i64]* %array, i64 0, i64 1
472   %idx4 = getelementptr inbounds [6 x i64], [6 x i64]* %array, i64 0, i64 4
473   %idx5 = getelementptr inbounds [6 x i64], [6 x i64]* %array, i64 0, i64 5
474
475   %a0 = load i64, i64* %idx0, align 8
476   store i64 %a0, i64* %idx4, align 8
477
478   %b = bitcast i64* %idx1 to <2 x i64>*
479   %v = load <2 x i64>, <2 x i64>* %b, align 8
480   %a1 = extractelement <2 x i64> %v, i32 0
481   store i64 %a1, i64* %idx5, align 8
482   ret void
483
484 ; CHECK-LABEL: merge_vec_element_and_scalar_load
485 ; CHECK:      movq      (%rdi), %rax
486 ; CHECK-NEXT: movq      %rax, 32(%rdi)
487 ; CHECK-NEXT: movq      8(%rdi), %rax
488 ; CHECK-NEXT: movq      %rax, 40(%rdi)
489 ; CHECK-NEXT: retq
490 }