1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -basicaa -slp-vectorizer -slp-threshold=-100 -instcombine -dce -S -mtriple=i386-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s
3
4target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32-S128"
5
6; Make sure we order the operands of commutative operations so that we get
7; bigger vectorizable trees.
8
9define void @shuffle_operands1(double * noalias %from, double * noalias %to, double %v1, double %v2) {
10; CHECK-LABEL: @shuffle_operands1(
11; CHECK-NEXT:    [[TMP1:%.*]] = bitcast double* [[FROM:%.*]] to <2 x double>*
12; CHECK-NEXT:    [[TMP2:%.*]] = load <2 x double>, <2 x double>* [[TMP1]], align 4
13; CHECK-NEXT:    [[TMP3:%.*]] = insertelement <2 x double> undef, double [[V1:%.*]], i32 0
14; CHECK-NEXT:    [[TMP4:%.*]] = insertelement <2 x double> [[TMP3]], double [[V2:%.*]], i32 1
15; CHECK-NEXT:    [[TMP5:%.*]] = fadd <2 x double> [[TMP2]], [[TMP4]]
16; CHECK-NEXT:    [[TMP6:%.*]] = bitcast double* [[TO:%.*]] to <2 x double>*
17; CHECK-NEXT:    store <2 x double> [[TMP5]], <2 x double>* [[TMP6]], align 4
18; CHECK-NEXT:    ret void
19;
20  %from_1 = getelementptr double, double *%from, i64 1
21  %v0_1 = load double , double * %from
22  %v0_2 = load double , double * %from_1
23  %v1_1 = fadd double %v0_1, %v1
24  %v1_2 = fadd double %v2, %v0_2
25  %to_2 = getelementptr double, double * %to, i64 1
26  store double %v1_1, double *%to
27  store double %v1_2, double *%to_2
28  ret void
29}
30
31define void @vecload_vs_broadcast(double * noalias %from, double * noalias %to, double %v1, double %v2) {
32; CHECK-LABEL: @vecload_vs_broadcast(
33; CHECK-NEXT:  entry:
34; CHECK-NEXT:    br label [[LP:%.*]]
35; CHECK:       lp:
36; CHECK-NEXT:    [[P:%.*]] = phi double [ 1.000000e+00, [[LP]] ], [ 0.000000e+00, [[ENTRY:%.*]] ]
37; CHECK-NEXT:    [[TMP0:%.*]] = bitcast double* [[FROM:%.*]] to <2 x double>*
38; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x double>, <2 x double>* [[TMP0]], align 4
39; CHECK-NEXT:    [[TMP2:%.*]] = insertelement <2 x double> undef, double [[P]], i32 0
40; CHECK-NEXT:    [[TMP3:%.*]] = shufflevector <2 x double> [[TMP2]], <2 x double> [[TMP1]], <2 x i32> <i32 0, i32 2>
41; CHECK-NEXT:    [[TMP4:%.*]] = fadd <2 x double> [[TMP1]], [[TMP3]]
42; CHECK-NEXT:    [[TMP5:%.*]] = bitcast double* [[TO:%.*]] to <2 x double>*
43; CHECK-NEXT:    store <2 x double> [[TMP4]], <2 x double>* [[TMP5]], align 4
44; CHECK-NEXT:    br i1 undef, label [[LP]], label [[EXT:%.*]]
45; CHECK:       ext:
46; CHECK-NEXT:    ret void
47;
48entry:
49br label %lp
50
51lp:
52  %p = phi double [ 1.000000e+00, %lp ], [ 0.000000e+00, %entry ]
53  %from_1 = getelementptr double, double *%from, i64 1
54  %v0_1 = load double , double * %from
55  %v0_2 = load double , double * %from_1
56  %v1_1 = fadd double %v0_1, %p
57  %v1_2 = fadd double %v0_1, %v0_2
58  %to_2 = getelementptr double, double * %to, i64 1
59  store double %v1_1, double *%to
60  store double %v1_2, double *%to_2
61br i1 undef, label %lp, label %ext
62
63ext:
64  ret void
65}
66
67define void @vecload_vs_broadcast2(double * noalias %from, double * noalias %to, double %v1, double %v2) {
68; CHECK-LABEL: @vecload_vs_broadcast2(
69; CHECK-NEXT:  entry:
70; CHECK-NEXT:    br label [[LP:%.*]]
71; CHECK:       lp:
72; CHECK-NEXT:    [[P:%.*]] = phi double [ 1.000000e+00, [[LP]] ], [ 0.000000e+00, [[ENTRY:%.*]] ]
73; CHECK-NEXT:    [[TMP0:%.*]] = bitcast double* [[FROM:%.*]] to <2 x double>*
74; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x double>, <2 x double>* [[TMP0]], align 4
75; CHECK-NEXT:    [[TMP2:%.*]] = insertelement <2 x double> undef, double [[P]], i32 0
76; CHECK-NEXT:    [[TMP3:%.*]] = shufflevector <2 x double> [[TMP2]], <2 x double> [[TMP1]], <2 x i32> <i32 0, i32 2>
77; CHECK-NEXT:    [[TMP4:%.*]] = fadd <2 x double> [[TMP3]], [[TMP1]]
78; CHECK-NEXT:    [[TMP5:%.*]] = bitcast double* [[TO:%.*]] to <2 x double>*
79; CHECK-NEXT:    store <2 x double> [[TMP4]], <2 x double>* [[TMP5]], align 4
80; CHECK-NEXT:    br i1 undef, label [[LP]], label [[EXT:%.*]]
81; CHECK:       ext:
82; CHECK-NEXT:    ret void
83;
84entry:
85br label %lp
86
87lp:
88  %p = phi double [ 1.000000e+00, %lp ], [ 0.000000e+00, %entry ]
89  %from_1 = getelementptr double, double *%from, i64 1
90  %v0_1 = load double , double * %from
91  %v0_2 = load double , double * %from_1
92  %v1_1 = fadd double %p, %v0_1
93  %v1_2 = fadd double %v0_2, %v0_1
94  %to_2 = getelementptr double, double * %to, i64 1
95  store double %v1_1, double *%to
96  store double %v1_2, double *%to_2
97br i1 undef, label %lp, label %ext
98
99ext:
100  ret void
101}
102
103define void @vecload_vs_broadcast3(double * noalias %from, double * noalias %to, double %v1, double %v2) {
104; CHECK-LABEL: @vecload_vs_broadcast3(
105; CHECK-NEXT:  entry:
106; CHECK-NEXT:    br label [[LP:%.*]]
107; CHECK:       lp:
108; CHECK-NEXT:    [[P:%.*]] = phi double [ 1.000000e+00, [[LP]] ], [ 0.000000e+00, [[ENTRY:%.*]] ]
109; CHECK-NEXT:    [[TMP0:%.*]] = bitcast double* [[FROM:%.*]] to <2 x double>*
110; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x double>, <2 x double>* [[TMP0]], align 4
111; CHECK-NEXT:    [[TMP2:%.*]] = insertelement <2 x double> undef, double [[P]], i32 0
112; CHECK-NEXT:    [[TMP3:%.*]] = shufflevector <2 x double> [[TMP2]], <2 x double> [[TMP1]], <2 x i32> <i32 0, i32 2>
113; CHECK-NEXT:    [[TMP4:%.*]] = fadd <2 x double> [[TMP3]], [[TMP1]]
114; CHECK-NEXT:    [[TMP5:%.*]] = bitcast double* [[TO:%.*]] to <2 x double>*
115; CHECK-NEXT:    store <2 x double> [[TMP4]], <2 x double>* [[TMP5]], align 4
116; CHECK-NEXT:    br i1 undef, label [[LP]], label [[EXT:%.*]]
117; CHECK:       ext:
118; CHECK-NEXT:    ret void
119;
120entry:
121br label %lp
122
123lp:
124  %p = phi double [ 1.000000e+00, %lp ], [ 0.000000e+00, %entry ]
125  %from_1 = getelementptr double, double *%from, i64 1
126  %v0_1 = load double , double * %from
127  %v0_2 = load double , double * %from_1
128  %v1_1 = fadd double %p, %v0_1
129  %v1_2 = fadd double %v0_1, %v0_2
130  %to_2 = getelementptr double, double * %to, i64 1
131  store double %v1_1, double *%to
132  store double %v1_2, double *%to_2
133br i1 undef, label %lp, label %ext
134
135ext:
136  ret void
137}
138
139define void @shuffle_preserve_broadcast4(double * noalias %from, double * noalias %to, double %v1, double %v2) {
140; CHECK-LABEL: @shuffle_preserve_broadcast4(
141; CHECK-NEXT:  entry:
142; CHECK-NEXT:    br label [[LP:%.*]]
143; CHECK:       lp:
144; CHECK-NEXT:    [[P:%.*]] = phi double [ 1.000000e+00, [[LP]] ], [ 0.000000e+00, [[ENTRY:%.*]] ]
145; CHECK-NEXT:    [[FROM_1:%.*]] = getelementptr double, double* [[FROM:%.*]], i32 1
146; CHECK-NEXT:    [[V0_1:%.*]] = load double, double* [[FROM]], align 4
147; CHECK-NEXT:    [[V0_2:%.*]] = load double, double* [[FROM_1]], align 4
148; CHECK-NEXT:    [[TMP0:%.*]] = insertelement <2 x double> undef, double [[V0_2]], i32 0
149; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <2 x double> [[TMP0]], double [[P]], i32 1
150; CHECK-NEXT:    [[TMP2:%.*]] = insertelement <2 x double> undef, double [[V0_1]], i32 0
151; CHECK-NEXT:    [[TMP3:%.*]] = shufflevector <2 x double> [[TMP2]], <2 x double> undef, <2 x i32> zeroinitializer
152; CHECK-NEXT:    [[TMP4:%.*]] = fadd <2 x double> [[TMP1]], [[TMP3]]
153; CHECK-NEXT:    [[TMP5:%.*]] = bitcast double* [[TO:%.*]] to <2 x double>*
154; CHECK-NEXT:    store <2 x double> [[TMP4]], <2 x double>* [[TMP5]], align 4
155; CHECK-NEXT:    br i1 undef, label [[LP]], label [[EXT:%.*]]
156; CHECK:       ext:
157; CHECK-NEXT:    ret void
158;
159entry:
160br label %lp
161
162lp:
163  %p = phi double [ 1.000000e+00, %lp ], [ 0.000000e+00, %entry ]
164  %from_1 = getelementptr double, double *%from, i64 1
165  %v0_1 = load double , double * %from
166  %v0_2 = load double , double * %from_1
167  %v1_1 = fadd double %v0_2, %v0_1
168  %v1_2 = fadd double %p, %v0_1
169  %to_2 = getelementptr double, double * %to, i64 1
170  store double %v1_1, double *%to
171  store double %v1_2, double *%to_2
172br i1 undef, label %lp, label %ext
173
174ext:
175  ret void
176}
177
178define void @vecload_vs_broadcast5(double * noalias %from, double * noalias %to, double %v1, double %v2) {
179; CHECK-LABEL: @vecload_vs_broadcast5(
180; CHECK-NEXT:  entry:
181; CHECK-NEXT:    br label [[LP:%.*]]
182; CHECK:       lp:
183; CHECK-NEXT:    [[P:%.*]] = phi double [ 1.000000e+00, [[LP]] ], [ 0.000000e+00, [[ENTRY:%.*]] ]
184; CHECK-NEXT:    [[TMP0:%.*]] = bitcast double* [[FROM:%.*]] to <2 x double>*
185; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x double>, <2 x double>* [[TMP0]], align 4
186; CHECK-NEXT:    [[TMP2:%.*]] = extractelement <2 x double> [[TMP1]], i32 0
187; CHECK-NEXT:    [[TMP3:%.*]] = insertelement <2 x double> undef, double [[TMP2]], i32 0
188; CHECK-NEXT:    [[TMP4:%.*]] = insertelement <2 x double> [[TMP3]], double [[P]], i32 1
189; CHECK-NEXT:    [[TMP5:%.*]] = shufflevector <2 x double> [[TMP1]], <2 x double> undef, <2 x i32> <i32 1, i32 0>
190; CHECK-NEXT:    [[TMP6:%.*]] = fadd <2 x double> [[TMP4]], [[TMP5]]
191; CHECK-NEXT:    [[TMP7:%.*]] = bitcast double* [[TO:%.*]] to <2 x double>*
192; CHECK-NEXT:    store <2 x double> [[TMP6]], <2 x double>* [[TMP7]], align 4
193; CHECK-NEXT:    br i1 undef, label [[LP]], label [[EXT:%.*]]
194; CHECK:       ext:
195; CHECK-NEXT:    ret void
196;
197entry:
198br label %lp
199
200lp:
201  %p = phi double [ 1.000000e+00, %lp ], [ 0.000000e+00, %entry ]
202  %from_1 = getelementptr double, double *%from, i64 1
203  %v0_1 = load double , double * %from
204  %v0_2 = load double , double * %from_1
205  %v1_1 = fadd double %v0_1, %v0_2
206  %v1_2 = fadd double %p, %v0_1
207  %to_2 = getelementptr double, double * %to, i64 1
208  store double %v1_1, double *%to
209  store double %v1_2, double *%to_2
210br i1 undef, label %lp, label %ext
211
212ext:
213  ret void
214}
215
216
217define void @shuffle_preserve_broadcast6(double * noalias %from, double * noalias %to, double %v1, double %v2) {
218; CHECK-LABEL: @shuffle_preserve_broadcast6(
219; CHECK-NEXT:  entry:
220; CHECK-NEXT:    br label [[LP:%.*]]
221; CHECK:       lp:
222; CHECK-NEXT:    [[P:%.*]] = phi double [ 1.000000e+00, [[LP]] ], [ 0.000000e+00, [[ENTRY:%.*]] ]
223; CHECK-NEXT:    [[FROM_1:%.*]] = getelementptr double, double* [[FROM:%.*]], i32 1
224; CHECK-NEXT:    [[V0_1:%.*]] = load double, double* [[FROM]], align 4
225; CHECK-NEXT:    [[V0_2:%.*]] = load double, double* [[FROM_1]], align 4
226; CHECK-NEXT:    [[TMP0:%.*]] = insertelement <2 x double> undef, double [[V0_1]], i32 0
227; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <2 x double> [[TMP0]], <2 x double> undef, <2 x i32> zeroinitializer
228; CHECK-NEXT:    [[TMP2:%.*]] = insertelement <2 x double> undef, double [[V0_2]], i32 0
229; CHECK-NEXT:    [[TMP3:%.*]] = insertelement <2 x double> [[TMP2]], double [[P]], i32 1
230; CHECK-NEXT:    [[TMP4:%.*]] = fadd <2 x double> [[TMP1]], [[TMP3]]
231; CHECK-NEXT:    [[TMP5:%.*]] = bitcast double* [[TO:%.*]] to <2 x double>*
232; CHECK-NEXT:    store <2 x double> [[TMP4]], <2 x double>* [[TMP5]], align 4
233; CHECK-NEXT:    br i1 undef, label [[LP]], label [[EXT:%.*]]
234; CHECK:       ext:
235; CHECK-NEXT:    ret void
236;
237entry:
238br label %lp
239
240lp:
241  %p = phi double [ 1.000000e+00, %lp ], [ 0.000000e+00, %entry ]
242  %from_1 = getelementptr double, double *%from, i64 1
243  %v0_1 = load double , double * %from
244  %v0_2 = load double , double * %from_1
245  %v1_1 = fadd double %v0_1, %v0_2
246  %v1_2 = fadd double %v0_1, %p
247  %to_2 = getelementptr double, double * %to, i64 1
248  store double %v1_1, double *%to
249  store double %v1_2, double *%to_2
250br i1 undef, label %lp, label %ext
251
252ext:
253  ret void
254}
255
256; Make sure we don't scramble operands when we reorder them and destroy
257; 'good' source order.
258
259@a = common global [32000 x float] zeroinitializer, align 16
260
261define void @good_load_order() {
262; CHECK-LABEL: @good_load_order(
263; CHECK-NEXT:  entry:
264; CHECK-NEXT:    br label [[FOR_COND1_PREHEADER:%.*]]
265; CHECK:       for.cond1.preheader:
266; CHECK-NEXT:    [[TMP0:%.*]] = load float, float* getelementptr inbounds ([32000 x float], [32000 x float]* @a, i32 0, i32 0), align 16
267; CHECK-NEXT:    br label [[FOR_BODY3:%.*]]
268; CHECK:       for.body3:
269; CHECK-NEXT:    [[TMP1:%.*]] = phi float [ [[TMP0]], [[FOR_COND1_PREHEADER]] ], [ [[TMP14:%.*]], [[FOR_BODY3]] ]
270; CHECK-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ 0, [[FOR_COND1_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY3]] ]
271; CHECK-NEXT:    [[TMP2:%.*]] = trunc i64 [[INDVARS_IV]] to i32
272; CHECK-NEXT:    [[TMP3:%.*]] = add i32 [[TMP2]], 1
273; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [32000 x float], [32000 x float]* @a, i32 0, i32 [[TMP3]]
274; CHECK-NEXT:    [[TMP4:%.*]] = trunc i64 [[INDVARS_IV]] to i32
275; CHECK-NEXT:    [[ARRAYIDX5:%.*]] = getelementptr inbounds [32000 x float], [32000 x float]* @a, i32 0, i32 [[TMP4]]
276; CHECK-NEXT:    [[TMP5:%.*]] = trunc i64 [[INDVARS_IV]] to i32
277; CHECK-NEXT:    [[TMP6:%.*]] = add i32 [[TMP5]], 4
278; CHECK-NEXT:    [[ARRAYIDX31:%.*]] = getelementptr inbounds [32000 x float], [32000 x float]* @a, i32 0, i32 [[TMP6]]
279; CHECK-NEXT:    [[TMP7:%.*]] = bitcast float* [[ARRAYIDX]] to <4 x float>*
280; CHECK-NEXT:    [[TMP8:%.*]] = load <4 x float>, <4 x float>* [[TMP7]], align 4
281; CHECK-NEXT:    [[TMP9:%.*]] = insertelement <4 x float> undef, float [[TMP1]], i32 0
282; CHECK-NEXT:    [[TMP10:%.*]] = shufflevector <4 x float> [[TMP9]], <4 x float> [[TMP8]], <4 x i32> <i32 0, i32 4, i32 5, i32 6>
283; CHECK-NEXT:    [[TMP11:%.*]] = fmul <4 x float> [[TMP8]], [[TMP10]]
284; CHECK-NEXT:    [[TMP12:%.*]] = bitcast float* [[ARRAYIDX5]] to <4 x float>*
285; CHECK-NEXT:    store <4 x float> [[TMP11]], <4 x float>* [[TMP12]], align 4
286; CHECK-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 5
287; CHECK-NEXT:    [[TMP13:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
288; CHECK-NEXT:    [[ARRAYIDX41:%.*]] = getelementptr inbounds [32000 x float], [32000 x float]* @a, i32 0, i32 [[TMP13]]
289; CHECK-NEXT:    [[TMP14]] = load float, float* [[ARRAYIDX41]], align 4
290; CHECK-NEXT:    [[TMP15:%.*]] = extractelement <4 x float> [[TMP8]], i32 3
291; CHECK-NEXT:    [[MUL45:%.*]] = fmul float [[TMP14]], [[TMP15]]
292; CHECK-NEXT:    store float [[MUL45]], float* [[ARRAYIDX31]], align 4
293; CHECK-NEXT:    [[TMP16:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
294; CHECK-NEXT:    [[CMP2:%.*]] = icmp slt i32 [[TMP16]], 31995
295; CHECK-NEXT:    br i1 [[CMP2]], label [[FOR_BODY3]], label [[FOR_END:%.*]]
296; CHECK:       for.end:
297; CHECK-NEXT:    ret void
298;
299entry:
300  br label %for.cond1.preheader
301
302for.cond1.preheader:
303  %0 = load float, float* getelementptr inbounds ([32000 x float], [32000 x float]* @a, i64 0, i64 0), align 16
304  br label %for.body3
305
306for.body3:
307  %1 = phi float [ %0, %for.cond1.preheader ], [ %10, %for.body3 ]
308  %indvars.iv = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next, %for.body3 ]
309  %2 = add nsw i64 %indvars.iv, 1
310  %arrayidx = getelementptr inbounds [32000 x float], [32000 x float]* @a, i64 0, i64 %2
311  %3 = load float, float* %arrayidx, align 4
312  %arrayidx5 = getelementptr inbounds [32000 x float], [32000 x float]* @a, i64 0, i64 %indvars.iv
313  %mul6 = fmul float %3, %1
314  store float %mul6, float* %arrayidx5, align 4
315  %4 = add nsw i64 %indvars.iv, 2
316  %arrayidx11 = getelementptr inbounds [32000 x float], [32000 x float]* @a, i64 0, i64 %4
317  %5 = load float, float* %arrayidx11, align 4
318  %mul15 = fmul float %5, %3
319  store float %mul15, float* %arrayidx, align 4
320  %6 = add nsw i64 %indvars.iv, 3
321  %arrayidx21 = getelementptr inbounds [32000 x float], [32000 x float]* @a, i64 0, i64 %6
322  %7 = load float, float* %arrayidx21, align 4
323  %mul25 = fmul float %7, %5
324  store float %mul25, float* %arrayidx11, align 4
325  %8 = add nsw i64 %indvars.iv, 4
326  %arrayidx31 = getelementptr inbounds [32000 x float], [32000 x float]* @a, i64 0, i64 %8
327  %9 = load float, float* %arrayidx31, align 4
328  %mul35 = fmul float %9, %7
329  store float %mul35, float* %arrayidx21, align 4
330  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 5
331  %arrayidx41 = getelementptr inbounds [32000 x float], [32000 x float]* @a, i64 0, i64 %indvars.iv.next
332  %10 = load float, float* %arrayidx41, align 4
333  %mul45 = fmul float %10, %9
334  store float %mul45, float* %arrayidx31, align 4
335  %11 = trunc i64 %indvars.iv.next to i32
336  %cmp2 = icmp slt i32 %11, 31995
337  br i1 %cmp2, label %for.body3, label %for.end
338
339for.end:
340  ret void
341}
342
343; Check vectorization of following code for double data type-
344;  c[0] = a[0]+b[0];
345;  c[1] = b[1]+a[1]; // swapped b[1] and a[1]
346
347define void @load_reorder_double(double* nocapture %c, double* noalias nocapture readonly %a, double* noalias nocapture readonly %b){
348; CHECK-LABEL: @load_reorder_double(
349; CHECK-NEXT:    [[TMP1:%.*]] = bitcast double* [[B:%.*]] to <2 x double>*
350; CHECK-NEXT:    [[TMP2:%.*]] = load <2 x double>, <2 x double>* [[TMP1]], align 4
351; CHECK-NEXT:    [[TMP3:%.*]] = bitcast double* [[A:%.*]] to <2 x double>*
352; CHECK-NEXT:    [[TMP4:%.*]] = load <2 x double>, <2 x double>* [[TMP3]], align 4
353; CHECK-NEXT:    [[TMP5:%.*]] = fadd <2 x double> [[TMP4]], [[TMP2]]
354; CHECK-NEXT:    [[TMP6:%.*]] = bitcast double* [[C:%.*]] to <2 x double>*
355; CHECK-NEXT:    store <2 x double> [[TMP5]], <2 x double>* [[TMP6]], align 4
356; CHECK-NEXT:    ret void
357;
358  %1 = load double, double* %a
359  %2 = load double, double* %b
360  %3 = fadd double %1, %2
361  store double %3, double* %c
362  %4 = getelementptr inbounds double, double* %b, i64 1
363  %5 = load double, double* %4
364  %6 = getelementptr inbounds double, double* %a, i64 1
365  %7 = load double, double* %6
366  %8 = fadd double %5, %7
367  %9 = getelementptr inbounds double, double* %c, i64 1
368  store double %8, double* %9
369  ret void
370}
371
372; Check vectorization of following code for float data type-
373;  c[0] = a[0]+b[0];
374;  c[1] = b[1]+a[1]; // swapped b[1] and a[1]
375;  c[2] = a[2]+b[2];
376;  c[3] = a[3]+b[3];
377
378define void @load_reorder_float(float* nocapture %c, float* noalias nocapture readonly %a, float* noalias nocapture readonly %b){
379; CHECK-LABEL: @load_reorder_float(
380; CHECK-NEXT:    [[TMP1:%.*]] = bitcast float* [[A:%.*]] to <4 x float>*
381; CHECK-NEXT:    [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4
382; CHECK-NEXT:    [[TMP3:%.*]] = bitcast float* [[B:%.*]] to <4 x float>*
383; CHECK-NEXT:    [[TMP4:%.*]] = load <4 x float>, <4 x float>* [[TMP3]], align 4
384; CHECK-NEXT:    [[TMP5:%.*]] = fadd <4 x float> [[TMP2]], [[TMP4]]
385; CHECK-NEXT:    [[TMP6:%.*]] = bitcast float* [[C:%.*]] to <4 x float>*
386; CHECK-NEXT:    store <4 x float> [[TMP5]], <4 x float>* [[TMP6]], align 4
387; CHECK-NEXT:    ret void
388;
389  %1 = load float, float* %a
390  %2 = load float, float* %b
391  %3 = fadd float %1, %2
392  store float %3, float* %c
393  %4 = getelementptr inbounds float, float* %b, i64 1
394  %5 = load float, float* %4
395  %6 = getelementptr inbounds float, float* %a, i64 1
396  %7 = load float, float* %6
397  %8 = fadd float %5, %7
398  %9 = getelementptr inbounds float, float* %c, i64 1
399  store float %8, float* %9
400  %10 = getelementptr inbounds float, float* %a, i64 2
401  %11 = load float, float* %10
402  %12 = getelementptr inbounds float, float* %b, i64 2
403  %13 = load float, float* %12
404  %14 = fadd float %11, %13
405  %15 = getelementptr inbounds float, float* %c, i64 2
406  store float %14, float* %15
407  %16 = getelementptr inbounds float, float* %a, i64 3
408  %17 = load float, float* %16
409  %18 = getelementptr inbounds float, float* %b, i64 3
410  %19 = load float, float* %18
411  %20 = fadd float %17, %19
412  %21 = getelementptr inbounds float, float* %c, i64 3
413  store float %20, float* %21
414  ret void
415}
416
417; Check we properly reorder the below code so that it gets vectorized optimally-
418; a[0] = (b[0]+c[0])+d[0];
419; a[1] = d[1]+(b[1]+c[1]);
420; a[2] = (b[2]+c[2])+d[2];
421; a[3] = (b[3]+c[3])+d[3];
422
423define void @opcode_reorder(float* noalias nocapture %a, float* noalias nocapture readonly %b, float* noalias nocapture readonly %c,float* noalias nocapture readonly %d) {
424; CHECK-LABEL: @opcode_reorder(
425; CHECK-NEXT:    [[TMP1:%.*]] = bitcast float* [[B:%.*]] to <4 x float>*
426; CHECK-NEXT:    [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4
427; CHECK-NEXT:    [[TMP3:%.*]] = bitcast float* [[C:%.*]] to <4 x float>*
428; CHECK-NEXT:    [[TMP4:%.*]] = load <4 x float>, <4 x float>* [[TMP3]], align 4
429; CHECK-NEXT:    [[TMP5:%.*]] = fadd <4 x float> [[TMP2]], [[TMP4]]
430; CHECK-NEXT:    [[TMP6:%.*]] = bitcast float* [[D:%.*]] to <4 x float>*
431; CHECK-NEXT:    [[TMP7:%.*]] = load <4 x float>, <4 x float>* [[TMP6]], align 4
432; CHECK-NEXT:    [[TMP8:%.*]] = fadd <4 x float> [[TMP5]], [[TMP7]]
433; CHECK-NEXT:    [[TMP9:%.*]] = bitcast float* [[A:%.*]] to <4 x float>*
434; CHECK-NEXT:    store <4 x float> [[TMP8]], <4 x float>* [[TMP9]], align 4
435; CHECK-NEXT:    ret void
436;
437  %1 = load float, float* %b
438  %2 = load float, float* %c
439  %3 = fadd float %1, %2
440  %4 = load float, float* %d
441  %5 = fadd float %3, %4
442  store float %5, float* %a
443  %6 = getelementptr inbounds float, float* %d, i64 1
444  %7 = load float, float* %6
445  %8 = getelementptr inbounds float, float* %b, i64 1
446  %9 = load float, float* %8
447  %10 = getelementptr inbounds float, float* %c, i64 1
448  %11 = load float, float* %10
449  %12 = fadd float %9, %11
450  %13 = fadd float %7, %12
451  %14 = getelementptr inbounds float, float* %a, i64 1
452  store float %13, float* %14
453  %15 = getelementptr inbounds float, float* %b, i64 2
454  %16 = load float, float* %15
455  %17 = getelementptr inbounds float, float* %c, i64 2
456  %18 = load float, float* %17
457  %19 = fadd float %16, %18
458  %20 = getelementptr inbounds float, float* %d, i64 2
459  %21 = load float, float* %20
460  %22 = fadd float %19, %21
461  %23 = getelementptr inbounds float, float* %a, i64 2
462  store float %22, float* %23
463  %24 = getelementptr inbounds float, float* %b, i64 3
464  %25 = load float, float* %24
465  %26 = getelementptr inbounds float, float* %c, i64 3
466  %27 = load float, float* %26
467  %28 = fadd float %25, %27
468  %29 = getelementptr inbounds float, float* %d, i64 3
469  %30 = load float, float* %29
470  %31 = fadd float %28, %30
471  %32 = getelementptr inbounds float, float* %a, i64 3
472  store float %31, float* %32
473  ret void
474}
475