1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -slp-vectorizer -S < %s -mtriple=x86_64-apple-macosx -mcpu=corei7-avx | FileCheck %s --check-prefixes=ALL,CHECK
3; RUN: opt -slp-vectorizer -slp-vectorize-hor -slp-vectorize-hor-store -S < %s -mtriple=x86_64-apple-macosx -mcpu=corei7-avx | FileCheck %s --check-prefixes=ALL,STORE
4
5; #include <stdint.h>
6;
7; int foo(float *A, int n) {
8;   float sum = 0;
9;   for (intptr_t i=0; i < n; ++i) {
10;     sum += 7*A[i*4  ] +
11;            7*A[i*4+1] +
12;            7*A[i*4+2] +
13;            7*A[i*4+3];
14;   }
15;   return sum;
16; }
17
18define i32 @add_red(float* %A, i32 %n) {
19; ALL-LABEL: @add_red(
20; ALL-NEXT:  entry:
21; ALL-NEXT:    [[CMP31:%.*]] = icmp sgt i32 [[N:%.*]], 0
22; ALL-NEXT:    br i1 [[CMP31]], label [[FOR_BODY_LR_PH:%.*]], label [[FOR_END:%.*]]
23; ALL:       for.body.lr.ph:
24; ALL-NEXT:    [[TMP0:%.*]] = sext i32 [[N]] to i64
25; ALL-NEXT:    br label [[FOR_BODY:%.*]]
26; ALL:       for.body:
27; ALL-NEXT:    [[I_033:%.*]] = phi i64 [ 0, [[FOR_BODY_LR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
28; ALL-NEXT:    [[SUM_032:%.*]] = phi float [ 0.000000e+00, [[FOR_BODY_LR_PH]] ], [ [[ADD17:%.*]], [[FOR_BODY]] ]
29; ALL-NEXT:    [[MUL:%.*]] = shl nsw i64 [[I_033]], 2
30; ALL-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[A:%.*]], i64 [[MUL]]
31; ALL-NEXT:    [[ADD28:%.*]] = or i64 [[MUL]], 1
32; ALL-NEXT:    [[ARRAYIDX4:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD28]]
33; ALL-NEXT:    [[ADD829:%.*]] = or i64 [[MUL]], 2
34; ALL-NEXT:    [[ARRAYIDX9:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD829]]
35; ALL-NEXT:    [[ADD1330:%.*]] = or i64 [[MUL]], 3
36; ALL-NEXT:    [[ARRAYIDX14:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD1330]]
37; ALL-NEXT:    [[TMP1:%.*]] = bitcast float* [[ARRAYIDX]] to <4 x float>*
38; ALL-NEXT:    [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4
39; ALL-NEXT:    [[TMP3:%.*]] = fmul <4 x float> [[TMP2]], <float 7.000000e+00, float 7.000000e+00, float 7.000000e+00, float 7.000000e+00>
40; ALL-NEXT:    [[TMP4:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float -0.000000e+00, <4 x float> [[TMP3]])
41; ALL-NEXT:    [[ADD17]] = fadd fast float [[SUM_032]], [[TMP4]]
42; ALL-NEXT:    [[INC]] = add nsw i64 [[I_033]], 1
43; ALL-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INC]], [[TMP0]]
44; ALL-NEXT:    br i1 [[EXITCOND]], label [[FOR_COND_FOR_END_CRIT_EDGE:%.*]], label [[FOR_BODY]]
45; ALL:       for.cond.for.end_crit_edge:
46; ALL-NEXT:    [[PHITMP:%.*]] = fptosi float [[ADD17]] to i32
47; ALL-NEXT:    br label [[FOR_END]]
48; ALL:       for.end:
49; ALL-NEXT:    [[SUM_0_LCSSA:%.*]] = phi i32 [ [[PHITMP]], [[FOR_COND_FOR_END_CRIT_EDGE]] ], [ 0, [[ENTRY:%.*]] ]
50; ALL-NEXT:    ret i32 [[SUM_0_LCSSA]]
51;
52entry:
53  %cmp31 = icmp sgt i32 %n, 0
54  br i1 %cmp31, label %for.body.lr.ph, label %for.end
55
56for.body.lr.ph:
57  %0 = sext i32 %n to i64
58  br label %for.body
59
60for.body:
61  %i.033 = phi i64 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
62  %sum.032 = phi float [ 0.000000e+00, %for.body.lr.ph ], [ %add17, %for.body ]
63  %mul = shl nsw i64 %i.033, 2
64  %arrayidx = getelementptr inbounds float, float* %A, i64 %mul
65  %1 = load float, float* %arrayidx, align 4
66  %mul2 = fmul float %1, 7.000000e+00
67  %add28 = or i64 %mul, 1
68  %arrayidx4 = getelementptr inbounds float, float* %A, i64 %add28
69  %2 = load float, float* %arrayidx4, align 4
70  %mul5 = fmul float %2, 7.000000e+00
71  %add6 = fadd fast float %mul2, %mul5
72  %add829 = or i64 %mul, 2
73  %arrayidx9 = getelementptr inbounds float, float* %A, i64 %add829
74  %3 = load float, float* %arrayidx9, align 4
75  %mul10 = fmul float %3, 7.000000e+00
76  %add11 = fadd fast float %add6, %mul10
77  %add1330 = or i64 %mul, 3
78  %arrayidx14 = getelementptr inbounds float, float* %A, i64 %add1330
79  %4 = load float, float* %arrayidx14, align 4
80  %mul15 = fmul float %4, 7.000000e+00
81  %add16 = fadd fast float %add11, %mul15
82  %add17 = fadd fast float %sum.032, %add16
83  %inc = add nsw i64 %i.033, 1
84  %exitcond = icmp eq i64 %inc, %0
85  br i1 %exitcond, label %for.cond.for.end_crit_edge, label %for.body
86
87for.cond.for.end_crit_edge:
88  %phitmp = fptosi float %add17 to i32
89  br label %for.end
90
91for.end:
92  %sum.0.lcssa = phi i32 [ %phitmp, %for.cond.for.end_crit_edge ], [ 0, %entry ]
93  ret i32 %sum.0.lcssa
94}
95
96; int foo(float * restrict A, float * restrict B, int n) {
97;   float sum = 0;
98;   for (intptr_t i=0; i < n; ++i) {
99;     sum *= B[0]*A[i*4  ] +
100;       B[1]*A[i*4+1] +
101;       B[2]*A[i*4+2] +
102;       B[3]*A[i*4+3];
103;   }
104;   return sum;
105; }
106
107define i32 @mul_red(float* noalias %A, float* noalias %B, i32 %n) {
108; ALL-LABEL: @mul_red(
109; ALL-NEXT:  entry:
110; ALL-NEXT:    [[CMP38:%.*]] = icmp sgt i32 [[N:%.*]], 0
111; ALL-NEXT:    br i1 [[CMP38]], label [[FOR_BODY_LR_PH:%.*]], label [[FOR_END:%.*]]
112; ALL:       for.body.lr.ph:
113; ALL-NEXT:    [[ARRAYIDX4:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 1
114; ALL-NEXT:    [[ARRAYIDX9:%.*]] = getelementptr inbounds float, float* [[B]], i64 2
115; ALL-NEXT:    [[ARRAYIDX15:%.*]] = getelementptr inbounds float, float* [[B]], i64 3
116; ALL-NEXT:    [[TMP0:%.*]] = bitcast float* [[B]] to <4 x float>*
117; ALL-NEXT:    [[TMP1:%.*]] = load <4 x float>, <4 x float>* [[TMP0]], align 4
118; ALL-NEXT:    [[TMP2:%.*]] = sext i32 [[N]] to i64
119; ALL-NEXT:    br label [[FOR_BODY:%.*]]
120; ALL:       for.body:
121; ALL-NEXT:    [[I_040:%.*]] = phi i64 [ 0, [[FOR_BODY_LR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
122; ALL-NEXT:    [[SUM_039:%.*]] = phi float [ 0.000000e+00, [[FOR_BODY_LR_PH]] ], [ [[MUL21:%.*]], [[FOR_BODY]] ]
123; ALL-NEXT:    [[MUL:%.*]] = shl nsw i64 [[I_040]], 2
124; ALL-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds float, float* [[A:%.*]], i64 [[MUL]]
125; ALL-NEXT:    [[ADD35:%.*]] = or i64 [[MUL]], 1
126; ALL-NEXT:    [[ARRAYIDX6:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD35]]
127; ALL-NEXT:    [[ADD1136:%.*]] = or i64 [[MUL]], 2
128; ALL-NEXT:    [[ARRAYIDX12:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD1136]]
129; ALL-NEXT:    [[ADD1737:%.*]] = or i64 [[MUL]], 3
130; ALL-NEXT:    [[ARRAYIDX18:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD1737]]
131; ALL-NEXT:    [[TMP3:%.*]] = bitcast float* [[ARRAYIDX2]] to <4 x float>*
132; ALL-NEXT:    [[TMP4:%.*]] = load <4 x float>, <4 x float>* [[TMP3]], align 4
133; ALL-NEXT:    [[TMP5:%.*]] = fmul <4 x float> [[TMP1]], [[TMP4]]
134; ALL-NEXT:    [[TMP6:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float -0.000000e+00, <4 x float> [[TMP5]])
135; ALL-NEXT:    [[MUL21]] = fmul float [[SUM_039]], [[TMP6]]
136; ALL-NEXT:    [[INC]] = add nsw i64 [[I_040]], 1
137; ALL-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INC]], [[TMP2]]
138; ALL-NEXT:    br i1 [[EXITCOND]], label [[FOR_COND_FOR_END_CRIT_EDGE:%.*]], label [[FOR_BODY]]
139; ALL:       for.cond.for.end_crit_edge:
140; ALL-NEXT:    [[PHITMP:%.*]] = fptosi float [[MUL21]] to i32
141; ALL-NEXT:    br label [[FOR_END]]
142; ALL:       for.end:
143; ALL-NEXT:    [[SUM_0_LCSSA:%.*]] = phi i32 [ [[PHITMP]], [[FOR_COND_FOR_END_CRIT_EDGE]] ], [ 0, [[ENTRY:%.*]] ]
144; ALL-NEXT:    ret i32 [[SUM_0_LCSSA]]
145;
146entry:
147  %cmp38 = icmp sgt i32 %n, 0
148  br i1 %cmp38, label %for.body.lr.ph, label %for.end
149
150for.body.lr.ph:
151  %0 = load float, float* %B, align 4
152  %arrayidx4 = getelementptr inbounds float, float* %B, i64 1
153  %1 = load float, float* %arrayidx4, align 4
154  %arrayidx9 = getelementptr inbounds float, float* %B, i64 2
155  %2 = load float, float* %arrayidx9, align 4
156  %arrayidx15 = getelementptr inbounds float, float* %B, i64 3
157  %3 = load float, float* %arrayidx15, align 4
158  %4 = sext i32 %n to i64
159  br label %for.body
160
161for.body:
162  %i.040 = phi i64 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
163  %sum.039 = phi float [ 0.000000e+00, %for.body.lr.ph ], [ %mul21, %for.body ]
164  %mul = shl nsw i64 %i.040, 2
165  %arrayidx2 = getelementptr inbounds float, float* %A, i64 %mul
166  %5 = load float, float* %arrayidx2, align 4
167  %mul3 = fmul float %0, %5
168  %add35 = or i64 %mul, 1
169  %arrayidx6 = getelementptr inbounds float, float* %A, i64 %add35
170  %6 = load float, float* %arrayidx6, align 4
171  %mul7 = fmul float %1, %6
172  %add8 = fadd fast float %mul3, %mul7
173  %add1136 = or i64 %mul, 2
174  %arrayidx12 = getelementptr inbounds float, float* %A, i64 %add1136
175  %7 = load float, float* %arrayidx12, align 4
176  %mul13 = fmul float %2, %7
177  %add14 = fadd fast float %add8, %mul13
178  %add1737 = or i64 %mul, 3
179  %arrayidx18 = getelementptr inbounds float, float* %A, i64 %add1737
180  %8 = load float, float* %arrayidx18, align 4
181  %mul19 = fmul float %3, %8
182  %add20 = fadd fast float %add14, %mul19
183  %mul21 = fmul float %sum.039, %add20
184  %inc = add nsw i64 %i.040, 1
185  %exitcond = icmp eq i64 %inc, %4
186  br i1 %exitcond, label %for.cond.for.end_crit_edge, label %for.body
187
188for.cond.for.end_crit_edge:
189  %phitmp = fptosi float %mul21 to i32
190  br label %for.end
191
192for.end:
193  %sum.0.lcssa = phi i32 [ %phitmp, %for.cond.for.end_crit_edge ], [ 0, %entry ]
194  ret i32 %sum.0.lcssa
195}
196
197; int foo(float * restrict A, float * restrict B, int n) {
198;   float sum = 0;
199;   for (intptr_t i=0; i < n; ++i) {
200;     sum += B[0]*A[i*6  ] +
201;            B[1]*A[i*6+1] +
202;            B[2]*A[i*6+2] +
203;            B[3]*A[i*6+3] +
204;            B[4]*A[i*6+4] +
205;            B[5]*A[i*6+5] +
206;            B[6]*A[i*6+6] +
207;            B[7]*A[i*6+7] +
208;            B[8]*A[i*6+8];
209;   }
210;   return sum;
211; }
212
213define i32 @long_red(float* noalias %A, float* noalias %B, i32 %n) {
214; ALL-LABEL: @long_red(
215; ALL-NEXT:  entry:
216; ALL-NEXT:    [[CMP81:%.*]] = icmp sgt i32 [[N:%.*]], 0
217; ALL-NEXT:    br i1 [[CMP81]], label [[FOR_BODY_LR_PH:%.*]], label [[FOR_END:%.*]]
218; ALL:       for.body.lr.ph:
219; ALL-NEXT:    [[ARRAYIDX4:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 1
220; ALL-NEXT:    [[ARRAYIDX9:%.*]] = getelementptr inbounds float, float* [[B]], i64 2
221; ALL-NEXT:    [[ARRAYIDX15:%.*]] = getelementptr inbounds float, float* [[B]], i64 3
222; ALL-NEXT:    [[ARRAYIDX21:%.*]] = getelementptr inbounds float, float* [[B]], i64 4
223; ALL-NEXT:    [[ARRAYIDX27:%.*]] = getelementptr inbounds float, float* [[B]], i64 5
224; ALL-NEXT:    [[ARRAYIDX33:%.*]] = getelementptr inbounds float, float* [[B]], i64 6
225; ALL-NEXT:    [[ARRAYIDX39:%.*]] = getelementptr inbounds float, float* [[B]], i64 7
226; ALL-NEXT:    [[TMP0:%.*]] = bitcast float* [[B]] to <8 x float>*
227; ALL-NEXT:    [[TMP1:%.*]] = load <8 x float>, <8 x float>* [[TMP0]], align 4
228; ALL-NEXT:    [[ARRAYIDX45:%.*]] = getelementptr inbounds float, float* [[B]], i64 8
229; ALL-NEXT:    [[TMP2:%.*]] = load float, float* [[ARRAYIDX45]], align 4
230; ALL-NEXT:    [[TMP3:%.*]] = sext i32 [[N]] to i64
231; ALL-NEXT:    br label [[FOR_BODY:%.*]]
232; ALL:       for.body:
233; ALL-NEXT:    [[I_083:%.*]] = phi i64 [ 0, [[FOR_BODY_LR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
234; ALL-NEXT:    [[SUM_082:%.*]] = phi float [ 0.000000e+00, [[FOR_BODY_LR_PH]] ], [ [[ADD51:%.*]], [[FOR_BODY]] ]
235; ALL-NEXT:    [[MUL:%.*]] = mul nsw i64 [[I_083]], 6
236; ALL-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds float, float* [[A:%.*]], i64 [[MUL]]
237; ALL-NEXT:    [[ADD80:%.*]] = or i64 [[MUL]], 1
238; ALL-NEXT:    [[ARRAYIDX6:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD80]]
239; ALL-NEXT:    [[ADD11:%.*]] = add nsw i64 [[MUL]], 2
240; ALL-NEXT:    [[ARRAYIDX12:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD11]]
241; ALL-NEXT:    [[ADD17:%.*]] = add nsw i64 [[MUL]], 3
242; ALL-NEXT:    [[ARRAYIDX18:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD17]]
243; ALL-NEXT:    [[ADD23:%.*]] = add nsw i64 [[MUL]], 4
244; ALL-NEXT:    [[ARRAYIDX24:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD23]]
245; ALL-NEXT:    [[ADD29:%.*]] = add nsw i64 [[MUL]], 5
246; ALL-NEXT:    [[ARRAYIDX30:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD29]]
247; ALL-NEXT:    [[ADD35:%.*]] = add nsw i64 [[MUL]], 6
248; ALL-NEXT:    [[ARRAYIDX36:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD35]]
249; ALL-NEXT:    [[ADD41:%.*]] = add nsw i64 [[MUL]], 7
250; ALL-NEXT:    [[ARRAYIDX42:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD41]]
251; ALL-NEXT:    [[TMP4:%.*]] = bitcast float* [[ARRAYIDX2]] to <8 x float>*
252; ALL-NEXT:    [[TMP5:%.*]] = load <8 x float>, <8 x float>* [[TMP4]], align 4
253; ALL-NEXT:    [[TMP6:%.*]] = fmul fast <8 x float> [[TMP1]], [[TMP5]]
254; ALL-NEXT:    [[ADD47:%.*]] = add nsw i64 [[MUL]], 8
255; ALL-NEXT:    [[ARRAYIDX48:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD47]]
256; ALL-NEXT:    [[TMP7:%.*]] = load float, float* [[ARRAYIDX48]], align 4
257; ALL-NEXT:    [[MUL49:%.*]] = fmul fast float [[TMP2]], [[TMP7]]
258; ALL-NEXT:    [[TMP8:%.*]] = call fast float @llvm.vector.reduce.fadd.v8f32(float -0.000000e+00, <8 x float> [[TMP6]])
259; ALL-NEXT:    [[TMP9:%.*]] = fadd fast float [[TMP8]], [[MUL49]]
260; ALL-NEXT:    [[ADD51]] = fadd fast float [[SUM_082]], [[TMP9]]
261; ALL-NEXT:    [[INC]] = add nsw i64 [[I_083]], 1
262; ALL-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INC]], [[TMP3]]
263; ALL-NEXT:    br i1 [[EXITCOND]], label [[FOR_COND_FOR_END_CRIT_EDGE:%.*]], label [[FOR_BODY]]
264; ALL:       for.cond.for.end_crit_edge:
265; ALL-NEXT:    [[PHITMP:%.*]] = fptosi float [[ADD51]] to i32
266; ALL-NEXT:    br label [[FOR_END]]
267; ALL:       for.end:
268; ALL-NEXT:    [[SUM_0_LCSSA:%.*]] = phi i32 [ [[PHITMP]], [[FOR_COND_FOR_END_CRIT_EDGE]] ], [ 0, [[ENTRY:%.*]] ]
269; ALL-NEXT:    ret i32 [[SUM_0_LCSSA]]
270;
271entry:
272  %cmp81 = icmp sgt i32 %n, 0
273  br i1 %cmp81, label %for.body.lr.ph, label %for.end
274
275for.body.lr.ph:
276  %0 = load float, float* %B, align 4
277  %arrayidx4 = getelementptr inbounds float, float* %B, i64 1
278  %1 = load float, float* %arrayidx4, align 4
279  %arrayidx9 = getelementptr inbounds float, float* %B, i64 2
280  %2 = load float, float* %arrayidx9, align 4
281  %arrayidx15 = getelementptr inbounds float, float* %B, i64 3
282  %3 = load float, float* %arrayidx15, align 4
283  %arrayidx21 = getelementptr inbounds float, float* %B, i64 4
284  %4 = load float, float* %arrayidx21, align 4
285  %arrayidx27 = getelementptr inbounds float, float* %B, i64 5
286  %5 = load float, float* %arrayidx27, align 4
287  %arrayidx33 = getelementptr inbounds float, float* %B, i64 6
288  %6 = load float, float* %arrayidx33, align 4
289  %arrayidx39 = getelementptr inbounds float, float* %B, i64 7
290  %7 = load float, float* %arrayidx39, align 4
291  %arrayidx45 = getelementptr inbounds float, float* %B, i64 8
292  %8 = load float, float* %arrayidx45, align 4
293  %9 = sext i32 %n to i64
294  br label %for.body
295
296for.body:
297  %i.083 = phi i64 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
298  %sum.082 = phi float [ 0.000000e+00, %for.body.lr.ph ], [ %add51, %for.body ]
299  %mul = mul nsw i64 %i.083, 6
300  %arrayidx2 = getelementptr inbounds float, float* %A, i64 %mul
301  %10 = load float, float* %arrayidx2, align 4
302  %mul3 = fmul fast float %0, %10
303  %add80 = or i64 %mul, 1
304  %arrayidx6 = getelementptr inbounds float, float* %A, i64 %add80
305  %11 = load float, float* %arrayidx6, align 4
306  %mul7 = fmul fast float %1, %11
307  %add8 = fadd fast float %mul3, %mul7
308  %add11 = add nsw i64 %mul, 2
309  %arrayidx12 = getelementptr inbounds float, float* %A, i64 %add11
310  %12 = load float, float* %arrayidx12, align 4
311  %mul13 = fmul fast float %2, %12
312  %add14 = fadd fast float %add8, %mul13
313  %add17 = add nsw i64 %mul, 3
314  %arrayidx18 = getelementptr inbounds float, float* %A, i64 %add17
315  %13 = load float, float* %arrayidx18, align 4
316  %mul19 = fmul fast float %3, %13
317  %add20 = fadd fast float %add14, %mul19
318  %add23 = add nsw i64 %mul, 4
319  %arrayidx24 = getelementptr inbounds float, float* %A, i64 %add23
320  %14 = load float, float* %arrayidx24, align 4
321  %mul25 = fmul fast float %4, %14
322  %add26 = fadd fast float %add20, %mul25
323  %add29 = add nsw i64 %mul, 5
324  %arrayidx30 = getelementptr inbounds float, float* %A, i64 %add29
325  %15 = load float, float* %arrayidx30, align 4
326  %mul31 = fmul fast float %5, %15
327  %add32 = fadd fast float %add26, %mul31
328  %add35 = add nsw i64 %mul, 6
329  %arrayidx36 = getelementptr inbounds float, float* %A, i64 %add35
330  %16 = load float, float* %arrayidx36, align 4
331  %mul37 = fmul fast float %6, %16
332  %add38 = fadd fast float %add32, %mul37
333  %add41 = add nsw i64 %mul, 7
334  %arrayidx42 = getelementptr inbounds float, float* %A, i64 %add41
335  %17 = load float, float* %arrayidx42, align 4
336  %mul43 = fmul fast float %7, %17
337  %add44 = fadd fast float %add38, %mul43
338  %add47 = add nsw i64 %mul, 8
339  %arrayidx48 = getelementptr inbounds float, float* %A, i64 %add47
340  %18 = load float, float* %arrayidx48, align 4
341  %mul49 = fmul fast float %8, %18
342  %add50 = fadd fast float %add44, %mul49
343  %add51 = fadd fast float %sum.082, %add50
344  %inc = add nsw i64 %i.083, 1
345  %exitcond = icmp eq i64 %inc, %9
346  br i1 %exitcond, label %for.cond.for.end_crit_edge, label %for.body
347
348for.cond.for.end_crit_edge:
349  %phitmp = fptosi float %add51 to i32
350  br label %for.end
351
352for.end:
353  %sum.0.lcssa = phi i32 [ %phitmp, %for.cond.for.end_crit_edge ], [ 0, %entry ]
354  ret i32 %sum.0.lcssa
355}
356
357; int foo(float * restrict A, float * restrict B, int n) {
358;   float sum = 0;
359;   for (intptr_t i=0; i < n; ++i) {
360;     sum += B[0]*A[i*4  ];
361;     sum += B[1]*A[i*4+1];
362;     sum += B[2]*A[i*4+2];
363;     sum += B[3]*A[i*4+3];
364;   }
365;   return sum;
366; }
367
368define i32 @chain_red(float* noalias %A, float* noalias %B, i32 %n) {
369; ALL-LABEL: @chain_red(
370; ALL-NEXT:  entry:
371; ALL-NEXT:    [[CMP41:%.*]] = icmp sgt i32 [[N:%.*]], 0
372; ALL-NEXT:    br i1 [[CMP41]], label [[FOR_BODY_LR_PH:%.*]], label [[FOR_END:%.*]]
373; ALL:       for.body.lr.ph:
374; ALL-NEXT:    [[ARRAYIDX4:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 1
375; ALL-NEXT:    [[ARRAYIDX10:%.*]] = getelementptr inbounds float, float* [[B]], i64 2
376; ALL-NEXT:    [[ARRAYIDX16:%.*]] = getelementptr inbounds float, float* [[B]], i64 3
377; ALL-NEXT:    [[TMP0:%.*]] = bitcast float* [[B]] to <4 x float>*
378; ALL-NEXT:    [[TMP1:%.*]] = load <4 x float>, <4 x float>* [[TMP0]], align 4
379; ALL-NEXT:    [[TMP2:%.*]] = sext i32 [[N]] to i64
380; ALL-NEXT:    br label [[FOR_BODY:%.*]]
381; ALL:       for.body:
382; ALL-NEXT:    [[I_043:%.*]] = phi i64 [ 0, [[FOR_BODY_LR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
383; ALL-NEXT:    [[SUM_042:%.*]] = phi float [ 0.000000e+00, [[FOR_BODY_LR_PH]] ], [ [[OP_EXTRA:%.*]], [[FOR_BODY]] ]
384; ALL-NEXT:    [[MUL:%.*]] = shl nsw i64 [[I_043]], 2
385; ALL-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds float, float* [[A:%.*]], i64 [[MUL]]
386; ALL-NEXT:    [[ADD638:%.*]] = or i64 [[MUL]], 1
387; ALL-NEXT:    [[ARRAYIDX7:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD638]]
388; ALL-NEXT:    [[ADD1239:%.*]] = or i64 [[MUL]], 2
389; ALL-NEXT:    [[ARRAYIDX13:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD1239]]
390; ALL-NEXT:    [[ADD1840:%.*]] = or i64 [[MUL]], 3
391; ALL-NEXT:    [[ARRAYIDX19:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD1840]]
392; ALL-NEXT:    [[TMP3:%.*]] = bitcast float* [[ARRAYIDX2]] to <4 x float>*
393; ALL-NEXT:    [[TMP4:%.*]] = load <4 x float>, <4 x float>* [[TMP3]], align 4
394; ALL-NEXT:    [[TMP5:%.*]] = fmul fast <4 x float> [[TMP1]], [[TMP4]]
395; ALL-NEXT:    [[TMP6:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float -0.000000e+00, <4 x float> [[TMP5]])
396; ALL-NEXT:    [[OP_EXTRA]] = fadd fast float [[TMP6]], [[SUM_042]]
397; ALL-NEXT:    [[INC]] = add nsw i64 [[I_043]], 1
398; ALL-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INC]], [[TMP2]]
399; ALL-NEXT:    br i1 [[EXITCOND]], label [[FOR_COND_FOR_END_CRIT_EDGE:%.*]], label [[FOR_BODY]]
400; ALL:       for.cond.for.end_crit_edge:
401; ALL-NEXT:    [[PHITMP:%.*]] = fptosi float [[OP_EXTRA]] to i32
402; ALL-NEXT:    br label [[FOR_END]]
403; ALL:       for.end:
404; ALL-NEXT:    [[SUM_0_LCSSA:%.*]] = phi i32 [ [[PHITMP]], [[FOR_COND_FOR_END_CRIT_EDGE]] ], [ 0, [[ENTRY:%.*]] ]
405; ALL-NEXT:    ret i32 [[SUM_0_LCSSA]]
406;
407entry:
408  %cmp41 = icmp sgt i32 %n, 0
409  br i1 %cmp41, label %for.body.lr.ph, label %for.end
410
411for.body.lr.ph:
412  %0 = load float, float* %B, align 4
413  %arrayidx4 = getelementptr inbounds float, float* %B, i64 1
414  %1 = load float, float* %arrayidx4, align 4
415  %arrayidx10 = getelementptr inbounds float, float* %B, i64 2
416  %2 = load float, float* %arrayidx10, align 4
417  %arrayidx16 = getelementptr inbounds float, float* %B, i64 3
418  %3 = load float, float* %arrayidx16, align 4
419  %4 = sext i32 %n to i64
420  br label %for.body
421
422for.body:
423  %i.043 = phi i64 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
424  %sum.042 = phi float [ 0.000000e+00, %for.body.lr.ph ], [ %add21, %for.body ]
425  %mul = shl nsw i64 %i.043, 2
426  %arrayidx2 = getelementptr inbounds float, float* %A, i64 %mul
427  %5 = load float, float* %arrayidx2, align 4
428  %mul3 = fmul fast float %0, %5
429  %add = fadd fast float %sum.042, %mul3
430  %add638 = or i64 %mul, 1
431  %arrayidx7 = getelementptr inbounds float, float* %A, i64 %add638
432  %6 = load float, float* %arrayidx7, align 4
433  %mul8 = fmul fast float %1, %6
434  %add9 = fadd fast float %add, %mul8
435  %add1239 = or i64 %mul, 2
436  %arrayidx13 = getelementptr inbounds float, float* %A, i64 %add1239
437  %7 = load float, float* %arrayidx13, align 4
438  %mul14 = fmul fast float %2, %7
439  %add15 = fadd fast float %add9, %mul14
440  %add1840 = or i64 %mul, 3
441  %arrayidx19 = getelementptr inbounds float, float* %A, i64 %add1840
442  %8 = load float, float* %arrayidx19, align 4
443  %mul20 = fmul fast float %3, %8
444  %add21 = fadd fast float %add15, %mul20
445  %inc = add nsw i64 %i.043, 1
446  %exitcond = icmp eq i64 %inc, %4
447  br i1 %exitcond, label %for.cond.for.end_crit_edge, label %for.body
448
449for.cond.for.end_crit_edge:
450  %phitmp = fptosi float %add21 to i32
451  br label %for.end
452
453for.end:
454  %sum.0.lcssa = phi i32 [ %phitmp, %for.cond.for.end_crit_edge ], [ 0, %entry ]
455  ret i32 %sum.0.lcssa
456}
457
458; void foo(const float *arg_A, unsigned arg_B, float *array) {
459;   for (uint32_t i = 0; i < 6; ++i) {
460;     const float *ptr = arg_A + i;
461;     float w0 = array[i * 4 + 0];
462;     float w1 = array[i * 4 + 1];
463;     float w2 = array[i * 4 + 2];
464;     float w3 = array[i * 4 + 3];
465;
466;     for (unsigned j = 0; j < arg_B; ++j) {
467;       const float x1 = *ptr - (-1.1f * w0) - (1.2f * w1);
468;       const float x2 = (2.1f * x1) + (-2.2f * w0) + (2.3f * w1);
469;       const float x3 = x2 - (-3.1f * w2) - (3.2f * w3);
470;       const float x4 = x3 + (-4.0f * w2) + w3;
471;       w1 = w0;
472;       w0 = x1;
473;       w3 = w2;
474;       w2 = x3;
475;     }
476;
477;     array[i * 4 + 0] = w0;
478;     array[i * 4 + 1] = w1;
479;     array[i * 4 + 2] = w2;
480;     array[i * 4 + 3] = w3;
481;   }
482; }
483
484define void @foo(float* nocapture readonly %arg_A, i32 %arg_B, float* nocapture %array) {
485; ALL-LABEL: @foo(
486; ALL-NEXT:  entry:
487; ALL-NEXT:    [[CMP1495:%.*]] = icmp eq i32 [[ARG_B:%.*]], 0
488; ALL-NEXT:    br label [[FOR_BODY:%.*]]
489; ALL:       for.cond.cleanup:
490; ALL-NEXT:    ret void
491; ALL:       for.body:
492; ALL-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_COND_CLEANUP15:%.*]] ]
493; ALL-NEXT:    [[TMP0:%.*]] = shl i64 [[INDVARS_IV]], 2
494; ALL-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[ARRAY:%.*]], i64 [[TMP0]]
495; ALL-NEXT:    [[TMP1:%.*]] = load float, float* [[ARRAYIDX]], align 4
496; ALL-NEXT:    [[TMP2:%.*]] = or i64 [[TMP0]], 1
497; ALL-NEXT:    [[ARRAYIDX4:%.*]] = getelementptr inbounds float, float* [[ARRAY]], i64 [[TMP2]]
498; ALL-NEXT:    [[TMP3:%.*]] = load float, float* [[ARRAYIDX4]], align 4
499; ALL-NEXT:    [[TMP4:%.*]] = or i64 [[TMP0]], 2
500; ALL-NEXT:    [[ARRAYIDX8:%.*]] = getelementptr inbounds float, float* [[ARRAY]], i64 [[TMP4]]
501; ALL-NEXT:    [[TMP5:%.*]] = load float, float* [[ARRAYIDX8]], align 4
502; ALL-NEXT:    [[TMP6:%.*]] = or i64 [[TMP0]], 3
503; ALL-NEXT:    [[ARRAYIDX12:%.*]] = getelementptr inbounds float, float* [[ARRAY]], i64 [[TMP6]]
504; ALL-NEXT:    [[TMP7:%.*]] = load float, float* [[ARRAYIDX12]], align 4
505; ALL-NEXT:    br i1 [[CMP1495]], label [[FOR_COND_CLEANUP15]], label [[FOR_BODY16_LR_PH:%.*]]
506; ALL:       for.body16.lr.ph:
507; ALL-NEXT:    [[ADD_PTR:%.*]] = getelementptr inbounds float, float* [[ARG_A:%.*]], i64 [[INDVARS_IV]]
508; ALL-NEXT:    [[TMP8:%.*]] = load float, float* [[ADD_PTR]], align 4
509; ALL-NEXT:    br label [[FOR_BODY16:%.*]]
510; ALL:       for.cond.cleanup15:
511; ALL-NEXT:    [[W2_0_LCSSA:%.*]] = phi float [ [[TMP5]], [[FOR_BODY]] ], [ [[SUB28:%.*]], [[FOR_BODY16]] ]
512; ALL-NEXT:    [[W3_0_LCSSA:%.*]] = phi float [ [[TMP7]], [[FOR_BODY]] ], [ [[W2_096:%.*]], [[FOR_BODY16]] ]
513; ALL-NEXT:    [[W1_0_LCSSA:%.*]] = phi float [ [[TMP3]], [[FOR_BODY]] ], [ [[W0_0100:%.*]], [[FOR_BODY16]] ]
514; ALL-NEXT:    [[W0_0_LCSSA:%.*]] = phi float [ [[TMP1]], [[FOR_BODY]] ], [ [[SUB19:%.*]], [[FOR_BODY16]] ]
515; ALL-NEXT:    store float [[W0_0_LCSSA]], float* [[ARRAYIDX]], align 4
516; ALL-NEXT:    store float [[W1_0_LCSSA]], float* [[ARRAYIDX4]], align 4
517; ALL-NEXT:    store float [[W2_0_LCSSA]], float* [[ARRAYIDX8]], align 4
518; ALL-NEXT:    store float [[W3_0_LCSSA]], float* [[ARRAYIDX12]], align 4
519; ALL-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
520; ALL-NEXT:    [[EXITCOND109:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 6
521; ALL-NEXT:    br i1 [[EXITCOND109]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]]
522; ALL:       for.body16:
523; ALL-NEXT:    [[W0_0100]] = phi float [ [[TMP1]], [[FOR_BODY16_LR_PH]] ], [ [[SUB19]], [[FOR_BODY16]] ]
524; ALL-NEXT:    [[W1_099:%.*]] = phi float [ [[TMP3]], [[FOR_BODY16_LR_PH]] ], [ [[W0_0100]], [[FOR_BODY16]] ]
525; ALL-NEXT:    [[J_098:%.*]] = phi i32 [ 0, [[FOR_BODY16_LR_PH]] ], [ [[INC:%.*]], [[FOR_BODY16]] ]
526; ALL-NEXT:    [[W3_097:%.*]] = phi float [ [[TMP7]], [[FOR_BODY16_LR_PH]] ], [ [[W2_096]], [[FOR_BODY16]] ]
527; ALL-NEXT:    [[W2_096]] = phi float [ [[TMP5]], [[FOR_BODY16_LR_PH]] ], [ [[SUB28]], [[FOR_BODY16]] ]
528; ALL-NEXT:    [[MUL17:%.*]] = fmul fast float [[W0_0100]], 0x3FF19999A0000000
529; ALL-NEXT:    [[MUL18_NEG:%.*]] = fmul fast float [[W1_099]], 0xBFF3333340000000
530; ALL-NEXT:    [[SUB92:%.*]] = fadd fast float [[MUL17]], [[MUL18_NEG]]
531; ALL-NEXT:    [[SUB19]] = fadd fast float [[SUB92]], [[TMP8]]
532; ALL-NEXT:    [[MUL20:%.*]] = fmul fast float [[SUB19]], 0x4000CCCCC0000000
533; ALL-NEXT:    [[MUL21_NEG:%.*]] = fmul fast float [[W0_0100]], 0xC0019999A0000000
534; ALL-NEXT:    [[MUL23:%.*]] = fmul fast float [[W1_099]], 0x4002666660000000
535; ALL-NEXT:    [[MUL25:%.*]] = fmul fast float [[W2_096]], 0x4008CCCCC0000000
536; ALL-NEXT:    [[MUL27_NEG:%.*]] = fmul fast float [[W3_097]], 0xC0099999A0000000
537; ALL-NEXT:    [[ADD2293:%.*]] = fadd fast float [[MUL27_NEG]], [[MUL25]]
538; ALL-NEXT:    [[ADD24:%.*]] = fadd fast float [[ADD2293]], [[MUL23]]
539; ALL-NEXT:    [[SUB2694:%.*]] = fadd fast float [[ADD24]], [[MUL21_NEG]]
540; ALL-NEXT:    [[SUB28]] = fadd fast float [[SUB2694]], [[MUL20]]
541; ALL-NEXT:    [[INC]] = add nuw i32 [[J_098]], 1
542; ALL-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[INC]], [[ARG_B]]
543; ALL-NEXT:    br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP15]], label [[FOR_BODY16]]
544;
545entry:
546  %cmp1495 = icmp eq i32 %arg_B, 0
547  br label %for.body
548
549for.cond.cleanup:                                 ; preds = %for.cond.cleanup15
550  ret void
551
552for.body:                                         ; preds = %for.cond.cleanup15, %entry
553  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.cond.cleanup15 ]
554  %0 = shl i64 %indvars.iv, 2
555  %arrayidx = getelementptr inbounds float, float* %array, i64 %0
556  %1 = load float, float* %arrayidx, align 4
557  %2 = or i64 %0, 1
558  %arrayidx4 = getelementptr inbounds float, float* %array, i64 %2
559  %3 = load float, float* %arrayidx4, align 4
560  %4 = or i64 %0, 2
561  %arrayidx8 = getelementptr inbounds float, float* %array, i64 %4
562  %5 = load float, float* %arrayidx8, align 4
563  %6 = or i64 %0, 3
564  %arrayidx12 = getelementptr inbounds float, float* %array, i64 %6
565  %7 = load float, float* %arrayidx12, align 4
566  br i1 %cmp1495, label %for.cond.cleanup15, label %for.body16.lr.ph
567
568for.body16.lr.ph:                                 ; preds = %for.body
569  %add.ptr = getelementptr inbounds float, float* %arg_A, i64 %indvars.iv
570  %8 = load float, float* %add.ptr, align 4
571  br label %for.body16
572
573for.cond.cleanup15:                               ; preds = %for.body16, %for.body
574  %w2.0.lcssa = phi float [ %5, %for.body ], [ %sub28, %for.body16 ]
575  %w3.0.lcssa = phi float [ %7, %for.body ], [ %w2.096, %for.body16 ]
576  %w1.0.lcssa = phi float [ %3, %for.body ], [ %w0.0100, %for.body16 ]
577  %w0.0.lcssa = phi float [ %1, %for.body ], [ %sub19, %for.body16 ]
578  store float %w0.0.lcssa, float* %arrayidx, align 4
579  store float %w1.0.lcssa, float* %arrayidx4, align 4
580  store float %w2.0.lcssa, float* %arrayidx8, align 4
581  store float %w3.0.lcssa, float* %arrayidx12, align 4
582  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
583  %exitcond109 = icmp eq i64 %indvars.iv.next, 6
584  br i1 %exitcond109, label %for.cond.cleanup, label %for.body
585
586for.body16:                                       ; preds = %for.body16, %for.body16.lr.ph
587  %w0.0100 = phi float [ %1, %for.body16.lr.ph ], [ %sub19, %for.body16 ]
588  %w1.099 = phi float [ %3, %for.body16.lr.ph ], [ %w0.0100, %for.body16 ]
589  %j.098 = phi i32 [ 0, %for.body16.lr.ph ], [ %inc, %for.body16 ]
590  %w3.097 = phi float [ %7, %for.body16.lr.ph ], [ %w2.096, %for.body16 ]
591  %w2.096 = phi float [ %5, %for.body16.lr.ph ], [ %sub28, %for.body16 ]
592  %mul17 = fmul fast float %w0.0100, 0x3FF19999A0000000
593  %mul18.neg = fmul fast float %w1.099, 0xBFF3333340000000
594  %sub92 = fadd fast float %mul17, %mul18.neg
595  %sub19 = fadd fast float %sub92, %8
596  %mul20 = fmul fast float %sub19, 0x4000CCCCC0000000
597  %mul21.neg = fmul fast float %w0.0100, 0xC0019999A0000000
598  %mul23 = fmul fast float %w1.099, 0x4002666660000000
599  %mul25 = fmul fast float %w2.096, 0x4008CCCCC0000000
600  %mul27.neg = fmul fast float %w3.097, 0xC0099999A0000000
601  %add2293 = fadd fast float %mul27.neg, %mul25
602  %add24 = fadd fast float %add2293, %mul23
603  %sub2694 = fadd fast float %add24, %mul21.neg
604  %sub28 = fadd fast float %sub2694, %mul20
605  %inc = add nuw i32 %j.098, 1
606  %exitcond = icmp eq i32 %inc, %arg_B
607  br i1 %exitcond, label %for.cond.cleanup15, label %for.body16
608}
609
610
611; void foo(double * restrict A, double * restrict B, double * restrict C,
612;          int n) {
613;   for (intptr_t i=0; i < n; ++i) {
614;     C[i] = B[0] *A[i*4  ] + B[1] *A[i*4+1];
615;   }
616; }
617
618define void @store_red_double(double* noalias %A, double* noalias %B, double* noalias %C, i32 %n) {
619; CHECK-LABEL: @store_red_double(
620; CHECK-NEXT:  entry:
621; CHECK-NEXT:    [[CMP17:%.*]] = icmp sgt i32 [[N:%.*]], 0
622; CHECK-NEXT:    br i1 [[CMP17]], label [[FOR_BODY_LR_PH:%.*]], label [[FOR_END:%.*]]
623; CHECK:       for.body.lr.ph:
624; CHECK-NEXT:    [[TMP0:%.*]] = load double, double* [[B:%.*]], align 8
625; CHECK-NEXT:    [[ARRAYIDX4:%.*]] = getelementptr inbounds double, double* [[B]], i64 1
626; CHECK-NEXT:    [[TMP1:%.*]] = load double, double* [[ARRAYIDX4]], align 8
627; CHECK-NEXT:    [[TMP2:%.*]] = sext i32 [[N]] to i64
628; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
629; CHECK:       for.body:
630; CHECK-NEXT:    [[I_018:%.*]] = phi i64 [ 0, [[FOR_BODY_LR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
631; CHECK-NEXT:    [[MUL:%.*]] = shl nsw i64 [[I_018]], 2
632; CHECK-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds double, double* [[A:%.*]], i64 [[MUL]]
633; CHECK-NEXT:    [[TMP3:%.*]] = load double, double* [[ARRAYIDX2]], align 8
634; CHECK-NEXT:    [[MUL3:%.*]] = fmul fast double [[TMP0]], [[TMP3]]
635; CHECK-NEXT:    [[ADD16:%.*]] = or i64 [[MUL]], 1
636; CHECK-NEXT:    [[ARRAYIDX6:%.*]] = getelementptr inbounds double, double* [[A]], i64 [[ADD16]]
637; CHECK-NEXT:    [[TMP4:%.*]] = load double, double* [[ARRAYIDX6]], align 8
638; CHECK-NEXT:    [[MUL7:%.*]] = fmul fast double [[TMP1]], [[TMP4]]
639; CHECK-NEXT:    [[ADD8:%.*]] = fadd fast double [[MUL3]], [[MUL7]]
640; CHECK-NEXT:    [[ARRAYIDX9:%.*]] = getelementptr inbounds double, double* [[C:%.*]], i64 [[I_018]]
641; CHECK-NEXT:    store double [[ADD8]], double* [[ARRAYIDX9]], align 8
642; CHECK-NEXT:    [[INC]] = add nsw i64 [[I_018]], 1
643; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INC]], [[TMP2]]
644; CHECK-NEXT:    br i1 [[EXITCOND]], label [[FOR_END]], label [[FOR_BODY]]
645; CHECK:       for.end:
646; CHECK-NEXT:    ret void
647;
648; STORE-LABEL: @store_red_double(
649; STORE-NEXT:  entry:
650; STORE-NEXT:    [[CMP17:%.*]] = icmp sgt i32 [[N:%.*]], 0
651; STORE-NEXT:    br i1 [[CMP17]], label [[FOR_BODY_LR_PH:%.*]], label [[FOR_END:%.*]]
652; STORE:       for.body.lr.ph:
653; STORE-NEXT:    [[ARRAYIDX4:%.*]] = getelementptr inbounds double, double* [[B:%.*]], i64 1
654; STORE-NEXT:    [[TMP0:%.*]] = bitcast double* [[B]] to <2 x double>*
655; STORE-NEXT:    [[TMP1:%.*]] = load <2 x double>, <2 x double>* [[TMP0]], align 8
656; STORE-NEXT:    [[TMP2:%.*]] = sext i32 [[N]] to i64
657; STORE-NEXT:    br label [[FOR_BODY:%.*]]
658; STORE:       for.body:
659; STORE-NEXT:    [[I_018:%.*]] = phi i64 [ 0, [[FOR_BODY_LR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
660; STORE-NEXT:    [[MUL:%.*]] = shl nsw i64 [[I_018]], 2
661; STORE-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds double, double* [[A:%.*]], i64 [[MUL]]
662; STORE-NEXT:    [[ADD16:%.*]] = or i64 [[MUL]], 1
663; STORE-NEXT:    [[ARRAYIDX6:%.*]] = getelementptr inbounds double, double* [[A]], i64 [[ADD16]]
664; STORE-NEXT:    [[TMP3:%.*]] = bitcast double* [[ARRAYIDX2]] to <2 x double>*
665; STORE-NEXT:    [[TMP4:%.*]] = load <2 x double>, <2 x double>* [[TMP3]], align 8
666; STORE-NEXT:    [[TMP5:%.*]] = fmul fast <2 x double> [[TMP1]], [[TMP4]]
667; STORE-NEXT:    [[TMP6:%.*]] = extractelement <2 x double> [[TMP5]], i32 0
668; STORE-NEXT:    [[TMP7:%.*]] = extractelement <2 x double> [[TMP5]], i32 1
669; STORE-NEXT:    [[ADD8:%.*]] = fadd fast double [[TMP6]], [[TMP7]]
670; STORE-NEXT:    [[ARRAYIDX9:%.*]] = getelementptr inbounds double, double* [[C:%.*]], i64 [[I_018]]
671; STORE-NEXT:    store double [[ADD8]], double* [[ARRAYIDX9]], align 8
672; STORE-NEXT:    [[INC]] = add nsw i64 [[I_018]], 1
673; STORE-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INC]], [[TMP2]]
674; STORE-NEXT:    br i1 [[EXITCOND]], label [[FOR_END]], label [[FOR_BODY]]
675; STORE:       for.end:
676; STORE-NEXT:    ret void
677;
678entry:
679  %cmp17 = icmp sgt i32 %n, 0
680  br i1 %cmp17, label %for.body.lr.ph, label %for.end
681
682for.body.lr.ph:
683  %0 = load double, double* %B, align 8
684  %arrayidx4 = getelementptr inbounds double, double* %B, i64 1
685  %1 = load double, double* %arrayidx4, align 8
686  %2 = sext i32 %n to i64
687  br label %for.body
688
689for.body:
690  %i.018 = phi i64 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
691  %mul = shl nsw i64 %i.018, 2
692  %arrayidx2 = getelementptr inbounds double, double* %A, i64 %mul
693  %3 = load double, double* %arrayidx2, align 8
694  %mul3 = fmul fast double %0, %3
695  %add16 = or i64 %mul, 1
696  %arrayidx6 = getelementptr inbounds double, double* %A, i64 %add16
697  %4 = load double, double* %arrayidx6, align 8
698  %mul7 = fmul fast double %1, %4
699  %add8 = fadd fast double %mul3, %mul7
700  %arrayidx9 = getelementptr inbounds double, double* %C, i64 %i.018
701  store double %add8, double* %arrayidx9, align 8
702  %inc = add nsw i64 %i.018, 1
703  %exitcond = icmp eq i64 %inc, %2
704  br i1 %exitcond, label %for.end, label %for.body
705
706for.end:
707  ret void
708}
709
710; int foo(float * restrict A, float * restrict B, float * restrict C, int n) {
711;   float sum = 0;
712;   for (intptr_t i=0; i < n; ++i) {
713;     C[i] = B[0] *A[i*4  ] +
714;          B[1] *A[i*4+1] +
715;          B[2] *A[i*4+2] +
716;          B[3] *A[i*4+3];
717;   }
718;   return sum;
719; }
720
721define i32 @store_red(float* noalias %A, float* noalias %B, float* noalias %C, i32 %n) {
722; CHECK-LABEL: @store_red(
723; CHECK-NEXT:  entry:
724; CHECK-NEXT:    [[CMP37:%.*]] = icmp sgt i32 [[N:%.*]], 0
725; CHECK-NEXT:    br i1 [[CMP37]], label [[FOR_BODY_LR_PH:%.*]], label [[FOR_END:%.*]]
726; CHECK:       for.body.lr.ph:
727; CHECK-NEXT:    [[ARRAYIDX4:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 1
728; CHECK-NEXT:    [[ARRAYIDX9:%.*]] = getelementptr inbounds float, float* [[B]], i64 2
729; CHECK-NEXT:    [[ARRAYIDX15:%.*]] = getelementptr inbounds float, float* [[B]], i64 3
730; CHECK-NEXT:    [[TMP0:%.*]] = sext i32 [[N]] to i64
731; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
732; CHECK:       for.body:
733; CHECK-NEXT:    [[I_039:%.*]] = phi i64 [ 0, [[FOR_BODY_LR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
734; CHECK-NEXT:    [[C_ADDR_038:%.*]] = phi float* [ [[C:%.*]], [[FOR_BODY_LR_PH]] ], [ [[INCDEC_PTR:%.*]], [[FOR_BODY]] ]
735; CHECK-NEXT:    [[TMP1:%.*]] = load float, float* [[B]], align 4
736; CHECK-NEXT:    [[MUL:%.*]] = shl nsw i64 [[I_039]], 2
737; CHECK-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds float, float* [[A:%.*]], i64 [[MUL]]
738; CHECK-NEXT:    [[TMP2:%.*]] = load float, float* [[ARRAYIDX2]], align 4
739; CHECK-NEXT:    [[MUL3:%.*]] = fmul fast float [[TMP1]], [[TMP2]]
740; CHECK-NEXT:    [[TMP3:%.*]] = load float, float* [[ARRAYIDX4]], align 4
741; CHECK-NEXT:    [[ADD34:%.*]] = or i64 [[MUL]], 1
742; CHECK-NEXT:    [[ARRAYIDX6:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD34]]
743; CHECK-NEXT:    [[TMP4:%.*]] = load float, float* [[ARRAYIDX6]], align 4
744; CHECK-NEXT:    [[MUL7:%.*]] = fmul fast float [[TMP3]], [[TMP4]]
745; CHECK-NEXT:    [[ADD8:%.*]] = fadd fast float [[MUL3]], [[MUL7]]
746; CHECK-NEXT:    [[TMP5:%.*]] = load float, float* [[ARRAYIDX9]], align 4
747; CHECK-NEXT:    [[ADD1135:%.*]] = or i64 [[MUL]], 2
748; CHECK-NEXT:    [[ARRAYIDX12:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD1135]]
749; CHECK-NEXT:    [[TMP6:%.*]] = load float, float* [[ARRAYIDX12]], align 4
750; CHECK-NEXT:    [[MUL13:%.*]] = fmul fast float [[TMP5]], [[TMP6]]
751; CHECK-NEXT:    [[ADD14:%.*]] = fadd fast float [[ADD8]], [[MUL13]]
752; CHECK-NEXT:    [[TMP7:%.*]] = load float, float* [[ARRAYIDX15]], align 4
753; CHECK-NEXT:    [[ADD1736:%.*]] = or i64 [[MUL]], 3
754; CHECK-NEXT:    [[ARRAYIDX18:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD1736]]
755; CHECK-NEXT:    [[TMP8:%.*]] = load float, float* [[ARRAYIDX18]], align 4
756; CHECK-NEXT:    [[MUL19:%.*]] = fmul fast float [[TMP7]], [[TMP8]]
757; CHECK-NEXT:    [[ADD20:%.*]] = fadd fast float [[ADD14]], [[MUL19]]
758; CHECK-NEXT:    store float [[ADD20]], float* [[C_ADDR_038]], align 4
759; CHECK-NEXT:    [[INCDEC_PTR]] = getelementptr inbounds float, float* [[C_ADDR_038]], i64 1
760; CHECK-NEXT:    [[INC]] = add nsw i64 [[I_039]], 1
761; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INC]], [[TMP0]]
762; CHECK-NEXT:    br i1 [[EXITCOND]], label [[FOR_END]], label [[FOR_BODY]]
763; CHECK:       for.end:
764; CHECK-NEXT:    ret i32 0
765;
766; STORE-LABEL: @store_red(
767; STORE-NEXT:  entry:
768; STORE-NEXT:    [[CMP37:%.*]] = icmp sgt i32 [[N:%.*]], 0
769; STORE-NEXT:    br i1 [[CMP37]], label [[FOR_BODY_LR_PH:%.*]], label [[FOR_END:%.*]]
770; STORE:       for.body.lr.ph:
771; STORE-NEXT:    [[ARRAYIDX4:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 1
772; STORE-NEXT:    [[ARRAYIDX9:%.*]] = getelementptr inbounds float, float* [[B]], i64 2
773; STORE-NEXT:    [[ARRAYIDX15:%.*]] = getelementptr inbounds float, float* [[B]], i64 3
774; STORE-NEXT:    [[TMP0:%.*]] = sext i32 [[N]] to i64
775; STORE-NEXT:    br label [[FOR_BODY:%.*]]
776; STORE:       for.body:
777; STORE-NEXT:    [[I_039:%.*]] = phi i64 [ 0, [[FOR_BODY_LR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
778; STORE-NEXT:    [[C_ADDR_038:%.*]] = phi float* [ [[C:%.*]], [[FOR_BODY_LR_PH]] ], [ [[INCDEC_PTR:%.*]], [[FOR_BODY]] ]
779; STORE-NEXT:    [[MUL:%.*]] = shl nsw i64 [[I_039]], 2
780; STORE-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds float, float* [[A:%.*]], i64 [[MUL]]
781; STORE-NEXT:    [[ADD34:%.*]] = or i64 [[MUL]], 1
782; STORE-NEXT:    [[ARRAYIDX6:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD34]]
783; STORE-NEXT:    [[ADD1135:%.*]] = or i64 [[MUL]], 2
784; STORE-NEXT:    [[ARRAYIDX12:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD1135]]
785; STORE-NEXT:    [[TMP1:%.*]] = bitcast float* [[B]] to <4 x float>*
786; STORE-NEXT:    [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4
787; STORE-NEXT:    [[ADD1736:%.*]] = or i64 [[MUL]], 3
788; STORE-NEXT:    [[ARRAYIDX18:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[ADD1736]]
789; STORE-NEXT:    [[TMP3:%.*]] = bitcast float* [[ARRAYIDX2]] to <4 x float>*
790; STORE-NEXT:    [[TMP4:%.*]] = load <4 x float>, <4 x float>* [[TMP3]], align 4
791; STORE-NEXT:    [[TMP5:%.*]] = fmul fast <4 x float> [[TMP2]], [[TMP4]]
792; STORE-NEXT:    [[TMP6:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float -0.000000e+00, <4 x float> [[TMP5]])
793; STORE-NEXT:    store float [[TMP6]], float* [[C_ADDR_038]], align 4
794; STORE-NEXT:    [[INCDEC_PTR]] = getelementptr inbounds float, float* [[C_ADDR_038]], i64 1
795; STORE-NEXT:    [[INC]] = add nsw i64 [[I_039]], 1
796; STORE-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INC]], [[TMP0]]
797; STORE-NEXT:    br i1 [[EXITCOND]], label [[FOR_END]], label [[FOR_BODY]]
798; STORE:       for.end:
799; STORE-NEXT:    ret i32 0
800;
801entry:
802  %cmp37 = icmp sgt i32 %n, 0
803  br i1 %cmp37, label %for.body.lr.ph, label %for.end
804
805for.body.lr.ph:
806  %arrayidx4 = getelementptr inbounds float, float* %B, i64 1
807  %arrayidx9 = getelementptr inbounds float, float* %B, i64 2
808  %arrayidx15 = getelementptr inbounds float, float* %B, i64 3
809  %0 = sext i32 %n to i64
810  br label %for.body
811
812for.body:
813  %i.039 = phi i64 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
814  %C.addr.038 = phi float* [ %C, %for.body.lr.ph ], [ %incdec.ptr, %for.body ]
815  %1 = load float, float* %B, align 4
816  %mul = shl nsw i64 %i.039, 2
817  %arrayidx2 = getelementptr inbounds float, float* %A, i64 %mul
818  %2 = load float, float* %arrayidx2, align 4
819  %mul3 = fmul fast float %1, %2
820  %3 = load float, float* %arrayidx4, align 4
821  %add34 = or i64 %mul, 1
822  %arrayidx6 = getelementptr inbounds float, float* %A, i64 %add34
823  %4 = load float, float* %arrayidx6, align 4
824  %mul7 = fmul fast float %3, %4
825  %add8 = fadd fast float %mul3, %mul7
826  %5 = load float, float* %arrayidx9, align 4
827  %add1135 = or i64 %mul, 2
828  %arrayidx12 = getelementptr inbounds float, float* %A, i64 %add1135
829  %6 = load float, float* %arrayidx12, align 4
830  %mul13 = fmul fast float %5, %6
831  %add14 = fadd fast float %add8, %mul13
832  %7 = load float, float* %arrayidx15, align 4
833  %add1736 = or i64 %mul, 3
834  %arrayidx18 = getelementptr inbounds float, float* %A, i64 %add1736
835  %8 = load float, float* %arrayidx18, align 4
836  %mul19 = fmul fast float %7, %8
837  %add20 = fadd fast float %add14, %mul19
838  store float %add20, float* %C.addr.038, align 4
839  %incdec.ptr = getelementptr inbounds float, float* %C.addr.038, i64 1
840  %inc = add nsw i64 %i.039, 1
841  %exitcond = icmp eq i64 %inc, %0
842  br i1 %exitcond, label %for.end, label %for.body
843
844for.end:
845  ret i32 0
846}
847
848@arr_i32 = global [32 x i32] zeroinitializer, align 16
849@arr_float = global [32 x float] zeroinitializer, align 16
850
851define void @float_red_example4(float* %res) {
852; CHECK-LABEL: @float_red_example4(
853; CHECK-NEXT:  entry:
854; CHECK-NEXT:    [[TMP0:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 0), align 16
855; CHECK-NEXT:    [[TMP1:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 1), align 4
856; CHECK-NEXT:    [[ADD:%.*]] = fadd fast float [[TMP1]], [[TMP0]]
857; CHECK-NEXT:    [[TMP2:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 2), align 8
858; CHECK-NEXT:    [[ADD_1:%.*]] = fadd fast float [[TMP2]], [[ADD]]
859; CHECK-NEXT:    [[TMP3:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 3), align 4
860; CHECK-NEXT:    [[ADD_2:%.*]] = fadd fast float [[TMP3]], [[ADD_1]]
861; CHECK-NEXT:    store float [[ADD_2]], float* [[RES:%.*]], align 16
862; CHECK-NEXT:    ret void
863;
864; STORE-LABEL: @float_red_example4(
865; STORE-NEXT:  entry:
866; STORE-NEXT:    [[TMP0:%.*]] = load <4 x float>, <4 x float>* bitcast ([32 x float]* @arr_float to <4 x float>*), align 16
867; STORE-NEXT:    [[TMP1:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float -0.000000e+00, <4 x float> [[TMP0]])
868; STORE-NEXT:    store float [[TMP1]], float* [[RES:%.*]], align 16
869; STORE-NEXT:    ret void
870;
871entry:
872  %0 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 0), align 16
873  %1 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 1), align 4
874  %add = fadd fast float %1, %0
875  %2 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 2), align 8
876  %add.1 = fadd fast float %2, %add
877  %3 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 3), align 4
878  %add.2 = fadd fast float %3, %add.1
879  store float %add.2, float* %res, align 16
880  ret void
881}
882
883define void @float_red_example8(float* %res) {
884; CHECK-LABEL: @float_red_example8(
885; CHECK-NEXT:  entry:
886; CHECK-NEXT:    [[TMP0:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 0), align 16
887; CHECK-NEXT:    [[TMP1:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 1), align 4
888; CHECK-NEXT:    [[ADD:%.*]] = fadd fast float [[TMP1]], [[TMP0]]
889; CHECK-NEXT:    [[TMP2:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 2), align 8
890; CHECK-NEXT:    [[ADD_1:%.*]] = fadd fast float [[TMP2]], [[ADD]]
891; CHECK-NEXT:    [[TMP3:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 3), align 4
892; CHECK-NEXT:    [[ADD_2:%.*]] = fadd fast float [[TMP3]], [[ADD_1]]
893; CHECK-NEXT:    [[TMP4:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 4), align 16
894; CHECK-NEXT:    [[ADD_3:%.*]] = fadd fast float [[TMP4]], [[ADD_2]]
895; CHECK-NEXT:    [[TMP5:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 5), align 4
896; CHECK-NEXT:    [[ADD_4:%.*]] = fadd fast float [[TMP5]], [[ADD_3]]
897; CHECK-NEXT:    [[TMP6:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 6), align 8
898; CHECK-NEXT:    [[ADD_5:%.*]] = fadd fast float [[TMP6]], [[ADD_4]]
899; CHECK-NEXT:    [[TMP7:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 7), align 4
900; CHECK-NEXT:    [[ADD_6:%.*]] = fadd fast float [[TMP7]], [[ADD_5]]
901; CHECK-NEXT:    store float [[ADD_6]], float* [[RES:%.*]], align 16
902; CHECK-NEXT:    ret void
903;
904; STORE-LABEL: @float_red_example8(
905; STORE-NEXT:  entry:
906; STORE-NEXT:    [[TMP0:%.*]] = load <8 x float>, <8 x float>* bitcast ([32 x float]* @arr_float to <8 x float>*), align 16
907; STORE-NEXT:    [[TMP1:%.*]] = call fast float @llvm.vector.reduce.fadd.v8f32(float -0.000000e+00, <8 x float> [[TMP0]])
908; STORE-NEXT:    store float [[TMP1]], float* [[RES:%.*]], align 16
909; STORE-NEXT:    ret void
910;
911entry:
912  %0 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 0), align 16
913  %1 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 1), align 4
914  %add = fadd fast float %1, %0
915  %2 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 2), align 8
916  %add.1 = fadd fast float %2, %add
917  %3 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 3), align 4
918  %add.2 = fadd fast float %3, %add.1
919  %4 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 4), align 16
920  %add.3 = fadd fast float %4, %add.2
921  %5 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 5), align 4
922  %add.4 = fadd fast float %5, %add.3
923  %6 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 6), align 8
924  %add.5 = fadd fast float %6, %add.4
925  %7 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 7), align 4
926  %add.6 = fadd fast float %7, %add.5
927  store float %add.6, float* %res, align 16
928  ret void
929}
930
931define void @float_red_example16(float* %res) {
932; CHECK-LABEL: @float_red_example16(
933; CHECK-NEXT:  entry:
934; CHECK-NEXT:    [[TMP0:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 0), align 16
935; CHECK-NEXT:    [[TMP1:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 1), align 4
936; CHECK-NEXT:    [[ADD:%.*]] = fadd fast float [[TMP1]], [[TMP0]]
937; CHECK-NEXT:    [[TMP2:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 2), align 8
938; CHECK-NEXT:    [[ADD_1:%.*]] = fadd fast float [[TMP2]], [[ADD]]
939; CHECK-NEXT:    [[TMP3:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 3), align 4
940; CHECK-NEXT:    [[ADD_2:%.*]] = fadd fast float [[TMP3]], [[ADD_1]]
941; CHECK-NEXT:    [[TMP4:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 4), align 16
942; CHECK-NEXT:    [[ADD_3:%.*]] = fadd fast float [[TMP4]], [[ADD_2]]
943; CHECK-NEXT:    [[TMP5:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 5), align 4
944; CHECK-NEXT:    [[ADD_4:%.*]] = fadd fast float [[TMP5]], [[ADD_3]]
945; CHECK-NEXT:    [[TMP6:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 6), align 8
946; CHECK-NEXT:    [[ADD_5:%.*]] = fadd fast float [[TMP6]], [[ADD_4]]
947; CHECK-NEXT:    [[TMP7:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 7), align 4
948; CHECK-NEXT:    [[ADD_6:%.*]] = fadd fast float [[TMP7]], [[ADD_5]]
949; CHECK-NEXT:    [[TMP8:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 8), align 16
950; CHECK-NEXT:    [[ADD_7:%.*]] = fadd fast float [[TMP8]], [[ADD_6]]
951; CHECK-NEXT:    [[TMP9:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 9), align 4
952; CHECK-NEXT:    [[ADD_8:%.*]] = fadd fast float [[TMP9]], [[ADD_7]]
953; CHECK-NEXT:    [[TMP10:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 10), align 8
954; CHECK-NEXT:    [[ADD_9:%.*]] = fadd fast float [[TMP10]], [[ADD_8]]
955; CHECK-NEXT:    [[TMP11:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 11), align 4
956; CHECK-NEXT:    [[ADD_10:%.*]] = fadd fast float [[TMP11]], [[ADD_9]]
957; CHECK-NEXT:    [[TMP12:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 12), align 16
958; CHECK-NEXT:    [[ADD_11:%.*]] = fadd fast float [[TMP12]], [[ADD_10]]
959; CHECK-NEXT:    [[TMP13:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 13), align 4
960; CHECK-NEXT:    [[ADD_12:%.*]] = fadd fast float [[TMP13]], [[ADD_11]]
961; CHECK-NEXT:    [[TMP14:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 14), align 8
962; CHECK-NEXT:    [[ADD_13:%.*]] = fadd fast float [[TMP14]], [[ADD_12]]
963; CHECK-NEXT:    [[TMP15:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 15), align 4
964; CHECK-NEXT:    [[ADD_14:%.*]] = fadd fast float [[TMP15]], [[ADD_13]]
965; CHECK-NEXT:    store float [[ADD_14]], float* [[RES:%.*]], align 16
966; CHECK-NEXT:    ret void
967;
968; STORE-LABEL: @float_red_example16(
969; STORE-NEXT:  entry:
970; STORE-NEXT:    [[TMP0:%.*]] = load <16 x float>, <16 x float>* bitcast ([32 x float]* @arr_float to <16 x float>*), align 16
971; STORE-NEXT:    [[TMP1:%.*]] = call fast float @llvm.vector.reduce.fadd.v16f32(float -0.000000e+00, <16 x float> [[TMP0]])
972; STORE-NEXT:    store float [[TMP1]], float* [[RES:%.*]], align 16
973; STORE-NEXT:    ret void
974;
975entry:
976  %0 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 0), align 16
977  %1 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 1), align 4
978  %add = fadd fast float %1, %0
979  %2 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 2), align 8
980  %add.1 = fadd fast float %2, %add
981  %3 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 3), align 4
982  %add.2 = fadd fast float %3, %add.1
983  %4 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 4), align 16
984  %add.3 = fadd fast float %4, %add.2
985  %5 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 5), align 4
986  %add.4 = fadd fast float %5, %add.3
987  %6 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 6), align 8
988  %add.5 = fadd fast float %6, %add.4
989  %7 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 7), align 4
990  %add.6 = fadd fast float %7, %add.5
991  %8 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 8), align 16
992  %add.7 = fadd fast float %8, %add.6
993  %9 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 9), align 4
994  %add.8 = fadd fast float %9, %add.7
995  %10 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 10), align 8
996  %add.9 = fadd fast float %10, %add.8
997  %11 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 11), align 4
998  %add.10 = fadd fast float %11, %add.9
999  %12 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 12), align 16
1000  %add.11 = fadd fast float %12, %add.10
1001  %13 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 13), align 4
1002  %add.12 = fadd fast float %13, %add.11
1003  %14 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 14), align 8
1004  %add.13 = fadd fast float %14, %add.12
1005  %15 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @arr_float, i64 0, i64 15), align 4
1006  %add.14 = fadd fast float %15, %add.13
1007  store float %add.14, float* %res, align 16
1008  ret void
1009}
1010
1011define void @i32_red_example4(i32* %res) {
1012; CHECK-LABEL: @i32_red_example4(
1013; CHECK-NEXT:  entry:
1014; CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 0), align 16
1015; CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 1), align 4
1016; CHECK-NEXT:    [[ADD:%.*]] = add nsw i32 [[TMP1]], [[TMP0]]
1017; CHECK-NEXT:    [[TMP2:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 2), align 8
1018; CHECK-NEXT:    [[ADD_1:%.*]] = add nsw i32 [[TMP2]], [[ADD]]
1019; CHECK-NEXT:    [[TMP3:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 3), align 4
1020; CHECK-NEXT:    [[ADD_2:%.*]] = add nsw i32 [[TMP3]], [[ADD_1]]
1021; CHECK-NEXT:    store i32 [[ADD_2]], i32* [[RES:%.*]], align 16
1022; CHECK-NEXT:    ret void
1023;
1024; STORE-LABEL: @i32_red_example4(
1025; STORE-NEXT:  entry:
1026; STORE-NEXT:    [[TMP0:%.*]] = load <4 x i32>, <4 x i32>* bitcast ([32 x i32]* @arr_i32 to <4 x i32>*), align 16
1027; STORE-NEXT:    [[TMP1:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[TMP0]])
1028; STORE-NEXT:    store i32 [[TMP1]], i32* [[RES:%.*]], align 16
1029; STORE-NEXT:    ret void
1030;
1031entry:
1032  %0 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 0), align 16
1033  %1 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 1), align 4
1034  %add = add nsw i32 %1, %0
1035  %2 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 2), align 8
1036  %add.1 = add nsw i32 %2, %add
1037  %3 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 3), align 4
1038  %add.2 = add nsw i32 %3, %add.1
1039  store i32 %add.2, i32* %res, align 16
1040  ret void
1041}
1042
1043define void @i32_red_example8(i32* %res) {
1044; CHECK-LABEL: @i32_red_example8(
1045; CHECK-NEXT:  entry:
1046; CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 0), align 16
1047; CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 1), align 4
1048; CHECK-NEXT:    [[ADD:%.*]] = add nsw i32 [[TMP1]], [[TMP0]]
1049; CHECK-NEXT:    [[TMP2:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 2), align 8
1050; CHECK-NEXT:    [[ADD_1:%.*]] = add nsw i32 [[TMP2]], [[ADD]]
1051; CHECK-NEXT:    [[TMP3:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 3), align 4
1052; CHECK-NEXT:    [[ADD_2:%.*]] = add nsw i32 [[TMP3]], [[ADD_1]]
1053; CHECK-NEXT:    [[TMP4:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 4), align 16
1054; CHECK-NEXT:    [[ADD_3:%.*]] = add nsw i32 [[TMP4]], [[ADD_2]]
1055; CHECK-NEXT:    [[TMP5:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 5), align 4
1056; CHECK-NEXT:    [[ADD_4:%.*]] = add nsw i32 [[TMP5]], [[ADD_3]]
1057; CHECK-NEXT:    [[TMP6:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 6), align 8
1058; CHECK-NEXT:    [[ADD_5:%.*]] = add nsw i32 [[TMP6]], [[ADD_4]]
1059; CHECK-NEXT:    [[TMP7:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 7), align 4
1060; CHECK-NEXT:    [[ADD_6:%.*]] = add nsw i32 [[TMP7]], [[ADD_5]]
1061; CHECK-NEXT:    store i32 [[ADD_6]], i32* [[RES:%.*]], align 16
1062; CHECK-NEXT:    ret void
1063;
1064; STORE-LABEL: @i32_red_example8(
1065; STORE-NEXT:  entry:
1066; STORE-NEXT:    [[TMP0:%.*]] = load <8 x i32>, <8 x i32>* bitcast ([32 x i32]* @arr_i32 to <8 x i32>*), align 16
1067; STORE-NEXT:    [[TMP1:%.*]] = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> [[TMP0]])
1068; STORE-NEXT:    store i32 [[TMP1]], i32* [[RES:%.*]], align 16
1069; STORE-NEXT:    ret void
1070;
1071entry:
1072  %0 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 0), align 16
1073  %1 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 1), align 4
1074  %add = add nsw i32 %1, %0
1075  %2 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 2), align 8
1076  %add.1 = add nsw i32 %2, %add
1077  %3 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 3), align 4
1078  %add.2 = add nsw i32 %3, %add.1
1079  %4 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 4), align 16
1080  %add.3 = add nsw i32 %4, %add.2
1081  %5 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 5), align 4
1082  %add.4 = add nsw i32 %5, %add.3
1083  %6 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 6), align 8
1084  %add.5 = add nsw i32 %6, %add.4
1085  %7 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 7), align 4
1086  %add.6 = add nsw i32 %7, %add.5
1087  store i32 %add.6, i32* %res, align 16
1088  ret void
1089}
1090
1091define void @i32_red_example16(i32* %res) {
1092; CHECK-LABEL: @i32_red_example16(
1093; CHECK-NEXT:  entry:
1094; CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 0), align 16
1095; CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 1), align 4
1096; CHECK-NEXT:    [[ADD:%.*]] = add nsw i32 [[TMP1]], [[TMP0]]
1097; CHECK-NEXT:    [[TMP2:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 2), align 8
1098; CHECK-NEXT:    [[ADD_1:%.*]] = add nsw i32 [[TMP2]], [[ADD]]
1099; CHECK-NEXT:    [[TMP3:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 3), align 4
1100; CHECK-NEXT:    [[ADD_2:%.*]] = add nsw i32 [[TMP3]], [[ADD_1]]
1101; CHECK-NEXT:    [[TMP4:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 4), align 16
1102; CHECK-NEXT:    [[ADD_3:%.*]] = add nsw i32 [[TMP4]], [[ADD_2]]
1103; CHECK-NEXT:    [[TMP5:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 5), align 4
1104; CHECK-NEXT:    [[ADD_4:%.*]] = add nsw i32 [[TMP5]], [[ADD_3]]
1105; CHECK-NEXT:    [[TMP6:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 6), align 8
1106; CHECK-NEXT:    [[ADD_5:%.*]] = add nsw i32 [[TMP6]], [[ADD_4]]
1107; CHECK-NEXT:    [[TMP7:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 7), align 4
1108; CHECK-NEXT:    [[ADD_6:%.*]] = add nsw i32 [[TMP7]], [[ADD_5]]
1109; CHECK-NEXT:    [[TMP8:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 8), align 16
1110; CHECK-NEXT:    [[ADD_7:%.*]] = add nsw i32 [[TMP8]], [[ADD_6]]
1111; CHECK-NEXT:    [[TMP9:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 9), align 4
1112; CHECK-NEXT:    [[ADD_8:%.*]] = add nsw i32 [[TMP9]], [[ADD_7]]
1113; CHECK-NEXT:    [[TMP10:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 10), align 8
1114; CHECK-NEXT:    [[ADD_9:%.*]] = add nsw i32 [[TMP10]], [[ADD_8]]
1115; CHECK-NEXT:    [[TMP11:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 11), align 4
1116; CHECK-NEXT:    [[ADD_10:%.*]] = add nsw i32 [[TMP11]], [[ADD_9]]
1117; CHECK-NEXT:    [[TMP12:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 12), align 16
1118; CHECK-NEXT:    [[ADD_11:%.*]] = add nsw i32 [[TMP12]], [[ADD_10]]
1119; CHECK-NEXT:    [[TMP13:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 13), align 4
1120; CHECK-NEXT:    [[ADD_12:%.*]] = add nsw i32 [[TMP13]], [[ADD_11]]
1121; CHECK-NEXT:    [[TMP14:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 14), align 8
1122; CHECK-NEXT:    [[ADD_13:%.*]] = add nsw i32 [[TMP14]], [[ADD_12]]
1123; CHECK-NEXT:    [[TMP15:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 15), align 4
1124; CHECK-NEXT:    [[ADD_14:%.*]] = add nsw i32 [[TMP15]], [[ADD_13]]
1125; CHECK-NEXT:    store i32 [[ADD_14]], i32* [[RES:%.*]], align 16
1126; CHECK-NEXT:    ret void
1127;
1128; STORE-LABEL: @i32_red_example16(
1129; STORE-NEXT:  entry:
1130; STORE-NEXT:    [[TMP0:%.*]] = load <16 x i32>, <16 x i32>* bitcast ([32 x i32]* @arr_i32 to <16 x i32>*), align 16
1131; STORE-NEXT:    [[TMP1:%.*]] = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> [[TMP0]])
1132; STORE-NEXT:    store i32 [[TMP1]], i32* [[RES:%.*]], align 16
1133; STORE-NEXT:    ret void
1134;
1135entry:
1136  %0 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 0), align 16
1137  %1 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 1), align 4
1138  %add = add nsw i32 %1, %0
1139  %2 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 2), align 8
1140  %add.1 = add nsw i32 %2, %add
1141  %3 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 3), align 4
1142  %add.2 = add nsw i32 %3, %add.1
1143  %4 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 4), align 16
1144  %add.3 = add nsw i32 %4, %add.2
1145  %5 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 5), align 4
1146  %add.4 = add nsw i32 %5, %add.3
1147  %6 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 6), align 8
1148  %add.5 = add nsw i32 %6, %add.4
1149  %7 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 7), align 4
1150  %add.6 = add nsw i32 %7, %add.5
1151  %8 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 8), align 16
1152  %add.7 = add nsw i32 %8, %add.6
1153  %9 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 9), align 4
1154  %add.8 = add nsw i32 %9, %add.7
1155  %10 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 10), align 8
1156  %add.9 = add nsw i32 %10, %add.8
1157  %11 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 11), align 4
1158  %add.10 = add nsw i32 %11, %add.9
1159  %12 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 12), align 16
1160  %add.11 = add nsw i32 %12, %add.10
1161  %13 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 13), align 4
1162  %add.12 = add nsw i32 %13, %add.11
1163  %14 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 14), align 8
1164  %add.13 = add nsw i32 %14, %add.12
1165  %15 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 15), align 4
1166  %add.14 = add nsw i32 %15, %add.13
1167  store i32 %add.14, i32* %res, align 16
1168  ret void
1169}
1170
1171define void @i32_red_example32(i32* %res) {
1172; CHECK-LABEL: @i32_red_example32(
1173; CHECK-NEXT:  entry:
1174; CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 0), align 16
1175; CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 1), align 4
1176; CHECK-NEXT:    [[ADD:%.*]] = add nsw i32 [[TMP1]], [[TMP0]]
1177; CHECK-NEXT:    [[TMP2:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 2), align 8
1178; CHECK-NEXT:    [[ADD_1:%.*]] = add nsw i32 [[TMP2]], [[ADD]]
1179; CHECK-NEXT:    [[TMP3:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 3), align 4
1180; CHECK-NEXT:    [[ADD_2:%.*]] = add nsw i32 [[TMP3]], [[ADD_1]]
1181; CHECK-NEXT:    [[TMP4:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 4), align 16
1182; CHECK-NEXT:    [[ADD_3:%.*]] = add nsw i32 [[TMP4]], [[ADD_2]]
1183; CHECK-NEXT:    [[TMP5:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 5), align 4
1184; CHECK-NEXT:    [[ADD_4:%.*]] = add nsw i32 [[TMP5]], [[ADD_3]]
1185; CHECK-NEXT:    [[TMP6:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 6), align 8
1186; CHECK-NEXT:    [[ADD_5:%.*]] = add nsw i32 [[TMP6]], [[ADD_4]]
1187; CHECK-NEXT:    [[TMP7:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 7), align 4
1188; CHECK-NEXT:    [[ADD_6:%.*]] = add nsw i32 [[TMP7]], [[ADD_5]]
1189; CHECK-NEXT:    [[TMP8:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 8), align 16
1190; CHECK-NEXT:    [[ADD_7:%.*]] = add nsw i32 [[TMP8]], [[ADD_6]]
1191; CHECK-NEXT:    [[TMP9:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 9), align 4
1192; CHECK-NEXT:    [[ADD_8:%.*]] = add nsw i32 [[TMP9]], [[ADD_7]]
1193; CHECK-NEXT:    [[TMP10:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 10), align 8
1194; CHECK-NEXT:    [[ADD_9:%.*]] = add nsw i32 [[TMP10]], [[ADD_8]]
1195; CHECK-NEXT:    [[TMP11:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 11), align 4
1196; CHECK-NEXT:    [[ADD_10:%.*]] = add nsw i32 [[TMP11]], [[ADD_9]]
1197; CHECK-NEXT:    [[TMP12:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 12), align 16
1198; CHECK-NEXT:    [[ADD_11:%.*]] = add nsw i32 [[TMP12]], [[ADD_10]]
1199; CHECK-NEXT:    [[TMP13:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 13), align 4
1200; CHECK-NEXT:    [[ADD_12:%.*]] = add nsw i32 [[TMP13]], [[ADD_11]]
1201; CHECK-NEXT:    [[TMP14:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 14), align 8
1202; CHECK-NEXT:    [[ADD_13:%.*]] = add nsw i32 [[TMP14]], [[ADD_12]]
1203; CHECK-NEXT:    [[TMP15:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 15), align 4
1204; CHECK-NEXT:    [[ADD_14:%.*]] = add nsw i32 [[TMP15]], [[ADD_13]]
1205; CHECK-NEXT:    [[TMP16:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 16), align 16
1206; CHECK-NEXT:    [[ADD_15:%.*]] = add nsw i32 [[TMP16]], [[ADD_14]]
1207; CHECK-NEXT:    [[TMP17:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 17), align 4
1208; CHECK-NEXT:    [[ADD_16:%.*]] = add nsw i32 [[TMP17]], [[ADD_15]]
1209; CHECK-NEXT:    [[TMP18:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 18), align 8
1210; CHECK-NEXT:    [[ADD_17:%.*]] = add nsw i32 [[TMP18]], [[ADD_16]]
1211; CHECK-NEXT:    [[TMP19:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 19), align 4
1212; CHECK-NEXT:    [[ADD_18:%.*]] = add nsw i32 [[TMP19]], [[ADD_17]]
1213; CHECK-NEXT:    [[TMP20:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 20), align 16
1214; CHECK-NEXT:    [[ADD_19:%.*]] = add nsw i32 [[TMP20]], [[ADD_18]]
1215; CHECK-NEXT:    [[TMP21:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 21), align 4
1216; CHECK-NEXT:    [[ADD_20:%.*]] = add nsw i32 [[TMP21]], [[ADD_19]]
1217; CHECK-NEXT:    [[TMP22:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 22), align 8
1218; CHECK-NEXT:    [[ADD_21:%.*]] = add nsw i32 [[TMP22]], [[ADD_20]]
1219; CHECK-NEXT:    [[TMP23:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 23), align 4
1220; CHECK-NEXT:    [[ADD_22:%.*]] = add nsw i32 [[TMP23]], [[ADD_21]]
1221; CHECK-NEXT:    [[TMP24:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 24), align 16
1222; CHECK-NEXT:    [[ADD_23:%.*]] = add nsw i32 [[TMP24]], [[ADD_22]]
1223; CHECK-NEXT:    [[TMP25:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 25), align 4
1224; CHECK-NEXT:    [[ADD_24:%.*]] = add nsw i32 [[TMP25]], [[ADD_23]]
1225; CHECK-NEXT:    [[TMP26:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 26), align 8
1226; CHECK-NEXT:    [[ADD_25:%.*]] = add nsw i32 [[TMP26]], [[ADD_24]]
1227; CHECK-NEXT:    [[TMP27:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 27), align 4
1228; CHECK-NEXT:    [[ADD_26:%.*]] = add nsw i32 [[TMP27]], [[ADD_25]]
1229; CHECK-NEXT:    [[TMP28:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 28), align 16
1230; CHECK-NEXT:    [[ADD_27:%.*]] = add nsw i32 [[TMP28]], [[ADD_26]]
1231; CHECK-NEXT:    [[TMP29:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 29), align 4
1232; CHECK-NEXT:    [[ADD_28:%.*]] = add nsw i32 [[TMP29]], [[ADD_27]]
1233; CHECK-NEXT:    [[TMP30:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 30), align 8
1234; CHECK-NEXT:    [[ADD_29:%.*]] = add nsw i32 [[TMP30]], [[ADD_28]]
1235; CHECK-NEXT:    [[TMP31:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 31), align 4
1236; CHECK-NEXT:    [[ADD_30:%.*]] = add nsw i32 [[TMP31]], [[ADD_29]]
1237; CHECK-NEXT:    store i32 [[ADD_30]], i32* [[RES:%.*]], align 16
1238; CHECK-NEXT:    ret void
1239;
1240; STORE-LABEL: @i32_red_example32(
1241; STORE-NEXT:  entry:
1242; STORE-NEXT:    [[TMP0:%.*]] = load <32 x i32>, <32 x i32>* bitcast ([32 x i32]* @arr_i32 to <32 x i32>*), align 16
1243; STORE-NEXT:    [[TMP1:%.*]] = call i32 @llvm.vector.reduce.add.v32i32(<32 x i32> [[TMP0]])
1244; STORE-NEXT:    store i32 [[TMP1]], i32* [[RES:%.*]], align 16
1245; STORE-NEXT:    ret void
1246;
1247entry:
1248  %0 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 0), align 16
1249  %1 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 1), align 4
1250  %add = add nsw i32 %1, %0
1251  %2 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 2), align 8
1252  %add.1 = add nsw i32 %2, %add
1253  %3 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 3), align 4
1254  %add.2 = add nsw i32 %3, %add.1
1255  %4 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 4), align 16
1256  %add.3 = add nsw i32 %4, %add.2
1257  %5 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 5), align 4
1258  %add.4 = add nsw i32 %5, %add.3
1259  %6 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 6), align 8
1260  %add.5 = add nsw i32 %6, %add.4
1261  %7 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 7), align 4
1262  %add.6 = add nsw i32 %7, %add.5
1263  %8 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 8), align 16
1264  %add.7 = add nsw i32 %8, %add.6
1265  %9 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 9), align 4
1266  %add.8 = add nsw i32 %9, %add.7
1267  %10 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 10), align 8
1268  %add.9 = add nsw i32 %10, %add.8
1269  %11 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 11), align 4
1270  %add.10 = add nsw i32 %11, %add.9
1271  %12 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 12), align 16
1272  %add.11 = add nsw i32 %12, %add.10
1273  %13 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 13), align 4
1274  %add.12 = add nsw i32 %13, %add.11
1275  %14 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 14), align 8
1276  %add.13 = add nsw i32 %14, %add.12
1277  %15 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 15), align 4
1278  %add.14 = add nsw i32 %15, %add.13
1279  %16 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 16), align 16
1280  %add.15 = add nsw i32 %16, %add.14
1281  %17 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 17), align 4
1282  %add.16 = add nsw i32 %17, %add.15
1283  %18 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 18), align 8
1284  %add.17 = add nsw i32 %18, %add.16
1285  %19 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 19), align 4
1286  %add.18 = add nsw i32 %19, %add.17
1287  %20 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 20), align 16
1288  %add.19 = add nsw i32 %20, %add.18
1289  %21 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 21), align 4
1290  %add.20 = add nsw i32 %21, %add.19
1291  %22 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 22), align 8
1292  %add.21 = add nsw i32 %22, %add.20
1293  %23 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 23), align 4
1294  %add.22 = add nsw i32 %23, %add.21
1295  %24 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 24), align 16
1296  %add.23 = add nsw i32 %24, %add.22
1297  %25 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 25), align 4
1298  %add.24 = add nsw i32 %25, %add.23
1299  %26 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 26), align 8
1300  %add.25 = add nsw i32 %26, %add.24
1301  %27 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 27), align 4
1302  %add.26 = add nsw i32 %27, %add.25
1303  %28 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 28), align 16
1304  %add.27 = add nsw i32 %28, %add.26
1305  %29 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 29), align 4
1306  %add.28 = add nsw i32 %29, %add.27
1307  %30 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 30), align 8
1308  %add.29 = add nsw i32 %30, %add.28
1309  %31 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 31), align 4
1310  %add.30 = add nsw i32 %31, %add.29
1311  store i32 %add.30, i32* %res, align 16
1312  ret void
1313}
1314
1315declare i32 @foobar(i32)
1316
1317define void @i32_red_call(i32 %val) {
1318; ALL-LABEL: @i32_red_call(
1319; ALL-NEXT:  entry:
1320; ALL-NEXT:    [[TMP0:%.*]] = load <8 x i32>, <8 x i32>* bitcast ([32 x i32]* @arr_i32 to <8 x i32>*), align 16
1321; ALL-NEXT:    [[TMP1:%.*]] = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> [[TMP0]])
1322; ALL-NEXT:    [[RES:%.*]] = call i32 @foobar(i32 [[TMP1]])
1323; ALL-NEXT:    ret void
1324;
1325entry:
1326  %0 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 0), align 16
1327  %1 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 1), align 4
1328  %add = add nsw i32 %1, %0
1329  %2 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 2), align 8
1330  %add.1 = add nsw i32 %2, %add
1331  %3 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 3), align 4
1332  %add.2 = add nsw i32 %3, %add.1
1333  %4 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 4), align 16
1334  %add.3 = add nsw i32 %4, %add.2
1335  %5 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 5), align 4
1336  %add.4 = add nsw i32 %5, %add.3
1337  %6 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 6), align 8
1338  %add.5 = add nsw i32 %6, %add.4
1339  %7 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 7), align 4
1340  %add.6 = add nsw i32 %7, %add.5
1341  %res = call i32 @foobar(i32 %add.6)
1342  ret void
1343}
1344
1345define void @i32_red_invoke(i32 %val) personality i32 (...)* @__gxx_personality_v0 {
1346; ALL-LABEL: @i32_red_invoke(
1347; ALL-NEXT:  entry:
1348; ALL-NEXT:    [[TMP0:%.*]] = load <8 x i32>, <8 x i32>* bitcast ([32 x i32]* @arr_i32 to <8 x i32>*), align 16
1349; ALL-NEXT:    [[TMP1:%.*]] = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> [[TMP0]])
1350; ALL-NEXT:    [[RES:%.*]] = invoke i32 @foobar(i32 [[TMP1]])
1351; ALL-NEXT:    to label [[NORMAL:%.*]] unwind label [[EXCEPTION:%.*]]
1352; ALL:       exception:
1353; ALL-NEXT:    [[CLEANUP:%.*]] = landingpad i8
1354; ALL-NEXT:    cleanup
1355; ALL-NEXT:    br label [[NORMAL]]
1356; ALL:       normal:
1357; ALL-NEXT:    ret void
1358;
1359entry:
1360  %0 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 0), align 16
1361  %1 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 1), align 4
1362  %add = add nsw i32 %1, %0
1363  %2 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 2), align 8
1364  %add.1 = add nsw i32 %2, %add
1365  %3 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 3), align 4
1366  %add.2 = add nsw i32 %3, %add.1
1367  %4 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 4), align 16
1368  %add.3 = add nsw i32 %4, %add.2
1369  %5 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 5), align 4
1370  %add.4 = add nsw i32 %5, %add.3
1371  %6 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 6), align 8
1372  %add.5 = add nsw i32 %6, %add.4
1373  %7 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr_i32, i64 0, i64 7), align 4
1374  %add.6 = add nsw i32 %7, %add.5
1375  %res = invoke i32 @foobar(i32 %add.6) to label %normal unwind label %exception
1376exception:
1377  %cleanup = landingpad i8 cleanup
1378  br label %normal
1379normal:
1380  ret void
1381}
1382
1383; Test case from PR47670. Reduction result is used as incoming value in phi.
1384define i32 @reduction_result_used_in_phi(i32* nocapture readonly %data, i1 zeroext %b) {
1385; ALL-LABEL: @reduction_result_used_in_phi(
1386; ALL-NEXT:  entry:
1387; ALL-NEXT:    br i1 [[B:%.*]], label [[BB:%.*]], label [[EXIT:%.*]]
1388; ALL:       bb:
1389; ALL-NEXT:    [[IDX_1:%.*]] = getelementptr inbounds i32, i32* [[DATA:%.*]], i64 1
1390; ALL-NEXT:    [[IDX_2:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 2
1391; ALL-NEXT:    [[IDX_3:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 3
1392; ALL-NEXT:    [[TMP0:%.*]] = bitcast i32* [[DATA]] to <4 x i32>*
1393; ALL-NEXT:    [[TMP1:%.*]] = load <4 x i32>, <4 x i32>* [[TMP0]], align 4
1394; ALL-NEXT:    [[TMP2:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[TMP1]])
1395; ALL-NEXT:    br label [[EXIT]]
1396; ALL:       exit:
1397; ALL-NEXT:    [[SUM_1:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[TMP2]], [[BB]] ]
1398; ALL-NEXT:    ret i32 [[SUM_1]]
1399;
1400entry:
1401  br i1 %b, label %bb, label %exit
1402
1403bb:
1404  %l.0 = load i32, i32* %data, align 4
1405  %idx.1 = getelementptr inbounds i32, i32* %data, i64 1
1406  %l.1 = load i32, i32* %idx.1, align 4
1407  %add.1 = add i32 %l.1, %l.0
1408  %idx.2 = getelementptr inbounds i32, i32* %data, i64 2
1409  %l.2 = load i32, i32* %idx.2, align 4
1410  %add.2 = add i32 %l.2, %add.1
1411  %idx.3 = getelementptr inbounds i32, i32* %data, i64 3
1412  %l.3 = load i32, i32* %idx.3, align 4
1413  %add.3 = add i32 %l.3, %add.2
1414  br label %exit
1415
1416exit:
1417  %sum.1 = phi i32 [ 0, %entry ], [ %add.3, %bb]
1418  ret i32 %sum.1
1419}
1420
1421define i32 @reduction_result_used_in_phi_loop(i32* nocapture readonly %data, i1 zeroext %b) {
1422; ALL-LABEL: @reduction_result_used_in_phi_loop(
1423; ALL-NEXT:  entry:
1424; ALL-NEXT:    br i1 [[B:%.*]], label [[BB:%.*]], label [[EXIT:%.*]]
1425; ALL:       bb:
1426; ALL-NEXT:    [[IDX_1:%.*]] = getelementptr inbounds i32, i32* [[DATA:%.*]], i64 1
1427; ALL-NEXT:    [[IDX_2:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 2
1428; ALL-NEXT:    [[IDX_3:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 3
1429; ALL-NEXT:    [[TMP0:%.*]] = bitcast i32* [[DATA]] to <4 x i32>*
1430; ALL-NEXT:    [[TMP1:%.*]] = load <4 x i32>, <4 x i32>* [[TMP0]], align 4
1431; ALL-NEXT:    [[TMP2:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[TMP1]])
1432; ALL-NEXT:    br label [[EXIT]]
1433; ALL:       exit:
1434; ALL-NEXT:    [[SUM_1:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[TMP2]], [[BB]] ]
1435; ALL-NEXT:    ret i32 [[SUM_1]]
1436;
1437entry:
1438  br i1 %b, label %bb, label %exit
1439
1440bb:
1441  %l.0 = load i32, i32* %data, align 4
1442  %idx.1 = getelementptr inbounds i32, i32* %data, i64 1
1443  %l.1 = load i32, i32* %idx.1, align 4
1444  %add.1 = add i32 %l.1, %l.0
1445  %idx.2 = getelementptr inbounds i32, i32* %data, i64 2
1446  %l.2 = load i32, i32* %idx.2, align 4
1447  %add.2 = add i32 %l.2, %add.1
1448  %idx.3 = getelementptr inbounds i32, i32* %data, i64 3
1449  %l.3 = load i32, i32* %idx.3, align 4
1450  %add.3 = add i32 %l.3, %add.2
1451  br label %exit
1452
1453exit:
1454  %sum.1 = phi i32 [ 0, %entry ], [ %add.3, %bb]
1455  ret i32 %sum.1
1456}
1457
1458; Make sure we do not crash or infinite loop on ill-formed IR.
1459
1460define void @unreachable_block() {
1461; ALL-LABEL: @unreachable_block(
1462; ALL-NEXT:  bb.0:
1463; ALL-NEXT:    br label [[BB_1:%.*]]
1464; ALL:       dead:
1465; ALL-NEXT:    [[T0:%.*]] = add i16 [[T0]], undef
1466; ALL-NEXT:    br label [[BB_1]]
1467; ALL:       bb.1:
1468; ALL-NEXT:    [[T1:%.*]] = phi i16 [ undef, [[BB_0:%.*]] ], [ [[T0]], [[DEAD:%.*]] ]
1469; ALL-NEXT:    ret void
1470;
1471bb.0:
1472  br label %bb.1
1473
1474dead:
1475  %t0 = add i16 %t0, undef ; unreachable IR may depend on itself
1476  br label %bb.1
1477
1478bb.1:
1479  %t1 = phi i16 [ undef, %bb.0 ], [ %t0, %dead ]
1480  ret void
1481}
1482
1483; The FMF on the reduction should match the incoming insts.
1484
1485define float @fadd_v4f32_fmf(float* %p) {
1486; ALL-LABEL: @fadd_v4f32_fmf(
1487; ALL-NEXT:    [[P1:%.*]] = getelementptr inbounds float, float* [[P:%.*]], i64 1
1488; ALL-NEXT:    [[P2:%.*]] = getelementptr inbounds float, float* [[P]], i64 2
1489; ALL-NEXT:    [[P3:%.*]] = getelementptr inbounds float, float* [[P]], i64 3
1490; ALL-NEXT:    [[TMP1:%.*]] = bitcast float* [[P]] to <4 x float>*
1491; ALL-NEXT:    [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4
1492; ALL-NEXT:    [[TMP3:%.*]] = call reassoc nsz float @llvm.vector.reduce.fadd.v4f32(float -0.000000e+00, <4 x float> [[TMP2]])
1493; ALL-NEXT:    ret float [[TMP3]]
1494;
1495  %p1 = getelementptr inbounds float, float* %p, i64 1
1496  %p2 = getelementptr inbounds float, float* %p, i64 2
1497  %p3 = getelementptr inbounds float, float* %p, i64 3
1498  %t0 = load float, float* %p, align 4
1499  %t1 = load float, float* %p1, align 4
1500  %t2 = load float, float* %p2, align 4
1501  %t3 = load float, float* %p3, align 4
1502  %add1 = fadd reassoc nsz float %t1, %t0
1503  %add2 = fadd reassoc nsz float %t2, %add1
1504  %add3 = fadd reassoc nsz float %t3, %add2
1505  ret float %add3
1506}
1507
1508; The minimal FMF for fadd reduction are "reassoc nsz".
1509; Only the common FMF of all operations in the reduction propagate to the result.
1510; In this example, "contract nnan arcp" are dropped, but "ninf" transfers with the required flags.
1511
1512define float @fadd_v4f32_fmf_intersect(float* %p) {
1513; ALL-LABEL: @fadd_v4f32_fmf_intersect(
1514; ALL-NEXT:    [[P1:%.*]] = getelementptr inbounds float, float* [[P:%.*]], i64 1
1515; ALL-NEXT:    [[P2:%.*]] = getelementptr inbounds float, float* [[P]], i64 2
1516; ALL-NEXT:    [[P3:%.*]] = getelementptr inbounds float, float* [[P]], i64 3
1517; ALL-NEXT:    [[TMP1:%.*]] = bitcast float* [[P]] to <4 x float>*
1518; ALL-NEXT:    [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4
1519; ALL-NEXT:    [[TMP3:%.*]] = call reassoc ninf nsz float @llvm.vector.reduce.fadd.v4f32(float -0.000000e+00, <4 x float> [[TMP2]])
1520; ALL-NEXT:    ret float [[TMP3]]
1521;
1522  %p1 = getelementptr inbounds float, float* %p, i64 1
1523  %p2 = getelementptr inbounds float, float* %p, i64 2
1524  %p3 = getelementptr inbounds float, float* %p, i64 3
1525  %t0 = load float, float* %p, align 4
1526  %t1 = load float, float* %p1, align 4
1527  %t2 = load float, float* %p2, align 4
1528  %t3 = load float, float* %p3, align 4
1529  %add1 = fadd ninf reassoc nsz nnan float %t1, %t0
1530  %add2 = fadd ninf reassoc nsz nnan arcp float %t2, %add1
1531  %add3 = fadd ninf reassoc nsz contract float %t3, %add2
1532  ret float %add3
1533}
1534
1535declare i32 @__gxx_personality_v0(...)
1536