1*cee313d2SEric Christopher; RUN: opt < %s -loop-reroll -S | FileCheck %s
2*cee313d2SEric Christophertarget datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
3*cee313d2SEric Christophertarget triple = "x86_64-unknown-linux-gnu"
4*cee313d2SEric Christopher
5*cee313d2SEric Christopher; int foo(int a);
6*cee313d2SEric Christopher; void bar(int *x) {
7*cee313d2SEric Christopher;   for (int i = 0; i < 500; i += 3) {
8*cee313d2SEric Christopher;     foo(i);
9*cee313d2SEric Christopher;     foo(i+1);
10*cee313d2SEric Christopher;     foo(i+2);
11*cee313d2SEric Christopher;   }
12*cee313d2SEric Christopher; }
13*cee313d2SEric Christopher
14*cee313d2SEric Christopher; Function Attrs: nounwind uwtable
15*cee313d2SEric Christopherdefine void @bar(i32* nocapture readnone %x) #0 {
16*cee313d2SEric Christopherentry:
17*cee313d2SEric Christopher  br label %for.body
18*cee313d2SEric Christopher
19*cee313d2SEric Christopherfor.body:                                         ; preds = %for.body, %entry
20*cee313d2SEric Christopher  %i.08 = phi i32 [ 0, %entry ], [ %add3, %for.body ]
21*cee313d2SEric Christopher  %call = tail call i32 @foo(i32 %i.08) #1
22*cee313d2SEric Christopher  %add = add nsw i32 %i.08, 1
23*cee313d2SEric Christopher  %call1 = tail call i32 @foo(i32 %add) #1
24*cee313d2SEric Christopher  %add2 = add nsw i32 %i.08, 2
25*cee313d2SEric Christopher  %call3 = tail call i32 @foo(i32 %add2) #1
26*cee313d2SEric Christopher  %add3 = add nsw i32 %i.08, 3
27*cee313d2SEric Christopher  %exitcond = icmp sge i32 %add3, 500
28*cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
29*cee313d2SEric Christopher
30*cee313d2SEric Christopher; CHECK-LABEL: @bar
31*cee313d2SEric Christopher
32*cee313d2SEric Christopher; CHECK: for.body:
33*cee313d2SEric Christopher; CHECK: %indvar = phi i32 [ %indvar.next, %for.body ], [ 0, %entry ]
34*cee313d2SEric Christopher; CHECK: %call = tail call i32 @foo(i32 %indvar) #1
35*cee313d2SEric Christopher; CHECK: %indvar.next = add i32 %indvar, 1
36*cee313d2SEric Christopher; CHECK: %exitcond1 = icmp eq i32 %indvar, 500
37*cee313d2SEric Christopher; CHECK: br i1 %exitcond1, label %for.end, label %for.body
38*cee313d2SEric Christopher
39*cee313d2SEric Christopher; CHECK: ret
40*cee313d2SEric Christopher
41*cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
42*cee313d2SEric Christopher  ret void
43*cee313d2SEric Christopher}
44*cee313d2SEric Christopher
45*cee313d2SEric Christopherdeclare i32 @foo(i32)
46*cee313d2SEric Christopher
47*cee313d2SEric Christopher; void hi1(int *x) {
48*cee313d2SEric Christopher;   for (int i = 0; i < 1500; i += 3) {
49*cee313d2SEric Christopher;     x[i] = foo(0);
50*cee313d2SEric Christopher;     x[i+1] = foo(0);
51*cee313d2SEric Christopher;     x[i+2] = foo(0);
52*cee313d2SEric Christopher;   }
53*cee313d2SEric Christopher; }
54*cee313d2SEric Christopher
55*cee313d2SEric Christopher; Function Attrs: nounwind uwtable
56*cee313d2SEric Christopherdefine void @hi1(i32* nocapture %x) #0 {
57*cee313d2SEric Christopherentry:
58*cee313d2SEric Christopher  br label %for.body
59*cee313d2SEric Christopher
60*cee313d2SEric Christopherfor.body:                                         ; preds = %entry, %for.body
61*cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
62*cee313d2SEric Christopher  %call = tail call i32 @foo(i32 0) #1
63*cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %x, i64 %indvars.iv
64*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx, align 4
65*cee313d2SEric Christopher  %call1 = tail call i32 @foo(i32 0) #1
66*cee313d2SEric Christopher  %0 = add nsw i64 %indvars.iv, 1
67*cee313d2SEric Christopher  %arrayidx3 = getelementptr inbounds i32, i32* %x, i64 %0
68*cee313d2SEric Christopher  store i32 %call1, i32* %arrayidx3, align 4
69*cee313d2SEric Christopher  %call4 = tail call i32 @foo(i32 0) #1
70*cee313d2SEric Christopher  %1 = add nsw i64 %indvars.iv, 2
71*cee313d2SEric Christopher  %arrayidx7 = getelementptr inbounds i32, i32* %x, i64 %1
72*cee313d2SEric Christopher  store i32 %call4, i32* %arrayidx7, align 4
73*cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 3
74*cee313d2SEric Christopher  %2 = trunc i64 %indvars.iv.next to i32
75*cee313d2SEric Christopher  %cmp = icmp slt i32 %2, 1500
76*cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
77*cee313d2SEric Christopher
78*cee313d2SEric Christopher; CHECK-LABEL: @hi1
79*cee313d2SEric Christopher
80*cee313d2SEric Christopher; CHECK: for.body:
81*cee313d2SEric Christopher; CHECK: %indvar = phi i64 [ %indvar.next, %for.body ], [ 0, %entry ]
82*cee313d2SEric Christopher; CHECK: %0 = trunc i64 %indvar to i32
83*cee313d2SEric Christopher; CHECK: %call = tail call i32 @foo(i32 0) #1
84*cee313d2SEric Christopher; CHECK: %arrayidx = getelementptr inbounds i32, i32* %x, i64 %indvar
85*cee313d2SEric Christopher; CHECK: store i32 %call, i32* %arrayidx, align 4
86*cee313d2SEric Christopher; CHECK: %indvar.next = add i64 %indvar, 1
87*cee313d2SEric Christopher; CHECK: %exitcond = icmp eq i32 %0, 1499
88*cee313d2SEric Christopher; CHECK: br i1 %exitcond, label %for.end, label %for.body
89*cee313d2SEric Christopher
90*cee313d2SEric Christopher; CHECK: ret
91*cee313d2SEric Christopher
92*cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
93*cee313d2SEric Christopher  ret void
94*cee313d2SEric Christopher}
95*cee313d2SEric Christopher
96*cee313d2SEric Christopher; void hi2(int *x) {
97*cee313d2SEric Christopher;   for (int i = 0; i < 500; ++i) {
98*cee313d2SEric Christopher;     x[3*i] = foo(0);
99*cee313d2SEric Christopher;     x[3*i+1] = foo(0);
100*cee313d2SEric Christopher;     x[3*i+2] = foo(0);
101*cee313d2SEric Christopher;   }
102*cee313d2SEric Christopher; }
103*cee313d2SEric Christopher
104*cee313d2SEric Christopher; Function Attrs: nounwind uwtable
105*cee313d2SEric Christopherdefine void @hi2(i32* nocapture %x) #0 {
106*cee313d2SEric Christopherentry:
107*cee313d2SEric Christopher  br label %for.body
108*cee313d2SEric Christopher
109*cee313d2SEric Christopherfor.body:                                         ; preds = %for.body, %entry
110*cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
111*cee313d2SEric Christopher  %call = tail call i32 @foo(i32 0) #1
112*cee313d2SEric Christopher  %0 = mul nsw i64 %indvars.iv, 3
113*cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %x, i64 %0
114*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx, align 4
115*cee313d2SEric Christopher  %call1 = tail call i32 @foo(i32 0) #1
116*cee313d2SEric Christopher  %1 = add nsw i64 %0, 1
117*cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds i32, i32* %x, i64 %1
118*cee313d2SEric Christopher  store i32 %call1, i32* %arrayidx4, align 4
119*cee313d2SEric Christopher  %call5 = tail call i32 @foo(i32 0) #1
120*cee313d2SEric Christopher  %2 = add nsw i64 %0, 2
121*cee313d2SEric Christopher  %arrayidx9 = getelementptr inbounds i32, i32* %x, i64 %2
122*cee313d2SEric Christopher  store i32 %call5, i32* %arrayidx9, align 4
123*cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
124*cee313d2SEric Christopher  %exitcond = icmp eq i64 %indvars.iv.next, 500
125*cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
126*cee313d2SEric Christopher
127*cee313d2SEric Christopher; CHECK-LABEL: @hi2
128*cee313d2SEric Christopher
129*cee313d2SEric Christopher; CHECK: for.body:
130*cee313d2SEric Christopher; CHECK: %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
131*cee313d2SEric Christopher; CHECK: %call = tail call i32 @foo(i32 0) #1
132*cee313d2SEric Christopher; CHECK: %arrayidx = getelementptr inbounds i32, i32* %x, i64 %indvars.iv
133*cee313d2SEric Christopher; CHECK: store i32 %call, i32* %arrayidx, align 4
134*cee313d2SEric Christopher; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
135*cee313d2SEric Christopher; CHECK: %exitcond1 = icmp eq i64 %indvars.iv, 1499
136*cee313d2SEric Christopher; CHECK: br i1 %exitcond1, label %for.end, label %for.body
137*cee313d2SEric Christopher
138*cee313d2SEric Christopher; CHECK: ret
139*cee313d2SEric Christopher
140*cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
141*cee313d2SEric Christopher  ret void
142*cee313d2SEric Christopher}
143*cee313d2SEric Christopher
144*cee313d2SEric Christopher; void goo(float alpha, float *a, float *b) {
145*cee313d2SEric Christopher;   for (int i = 0; i < 3200; i += 5) {
146*cee313d2SEric Christopher;     a[i] += alpha * b[i];
147*cee313d2SEric Christopher;     a[i + 1] += alpha * b[i + 1];
148*cee313d2SEric Christopher;     a[i + 2] += alpha * b[i + 2];
149*cee313d2SEric Christopher;     a[i + 3] += alpha * b[i + 3];
150*cee313d2SEric Christopher;     a[i + 4] += alpha * b[i + 4];
151*cee313d2SEric Christopher;   }
152*cee313d2SEric Christopher; }
153*cee313d2SEric Christopher
154*cee313d2SEric Christopher; Function Attrs: nounwind uwtable
155*cee313d2SEric Christopherdefine void @goo(float %alpha, float* nocapture %a, float* nocapture readonly %b) #0 {
156*cee313d2SEric Christopherentry:
157*cee313d2SEric Christopher  br label %for.body
158*cee313d2SEric Christopher
159*cee313d2SEric Christopherfor.body:                                         ; preds = %entry, %for.body
160*cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
161*cee313d2SEric Christopher  %arrayidx = getelementptr inbounds float, float* %b, i64 %indvars.iv
162*cee313d2SEric Christopher  %0 = load float, float* %arrayidx, align 4
163*cee313d2SEric Christopher  %mul = fmul float %0, %alpha
164*cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds float, float* %a, i64 %indvars.iv
165*cee313d2SEric Christopher  %1 = load float, float* %arrayidx2, align 4
166*cee313d2SEric Christopher  %add = fadd float %1, %mul
167*cee313d2SEric Christopher  store float %add, float* %arrayidx2, align 4
168*cee313d2SEric Christopher  %2 = add nsw i64 %indvars.iv, 1
169*cee313d2SEric Christopher  %arrayidx5 = getelementptr inbounds float, float* %b, i64 %2
170*cee313d2SEric Christopher  %3 = load float, float* %arrayidx5, align 4
171*cee313d2SEric Christopher  %mul6 = fmul float %3, %alpha
172*cee313d2SEric Christopher  %arrayidx9 = getelementptr inbounds float, float* %a, i64 %2
173*cee313d2SEric Christopher  %4 = load float, float* %arrayidx9, align 4
174*cee313d2SEric Christopher  %add10 = fadd float %4, %mul6
175*cee313d2SEric Christopher  store float %add10, float* %arrayidx9, align 4
176*cee313d2SEric Christopher  %5 = add nsw i64 %indvars.iv, 2
177*cee313d2SEric Christopher  %arrayidx13 = getelementptr inbounds float, float* %b, i64 %5
178*cee313d2SEric Christopher  %6 = load float, float* %arrayidx13, align 4
179*cee313d2SEric Christopher  %mul14 = fmul float %6, %alpha
180*cee313d2SEric Christopher  %arrayidx17 = getelementptr inbounds float, float* %a, i64 %5
181*cee313d2SEric Christopher  %7 = load float, float* %arrayidx17, align 4
182*cee313d2SEric Christopher  %add18 = fadd float %7, %mul14
183*cee313d2SEric Christopher  store float %add18, float* %arrayidx17, align 4
184*cee313d2SEric Christopher  %8 = add nsw i64 %indvars.iv, 3
185*cee313d2SEric Christopher  %arrayidx21 = getelementptr inbounds float, float* %b, i64 %8
186*cee313d2SEric Christopher  %9 = load float, float* %arrayidx21, align 4
187*cee313d2SEric Christopher  %mul22 = fmul float %9, %alpha
188*cee313d2SEric Christopher  %arrayidx25 = getelementptr inbounds float, float* %a, i64 %8
189*cee313d2SEric Christopher  %10 = load float, float* %arrayidx25, align 4
190*cee313d2SEric Christopher  %add26 = fadd float %10, %mul22
191*cee313d2SEric Christopher  store float %add26, float* %arrayidx25, align 4
192*cee313d2SEric Christopher  %11 = add nsw i64 %indvars.iv, 4
193*cee313d2SEric Christopher  %arrayidx29 = getelementptr inbounds float, float* %b, i64 %11
194*cee313d2SEric Christopher  %12 = load float, float* %arrayidx29, align 4
195*cee313d2SEric Christopher  %mul30 = fmul float %12, %alpha
196*cee313d2SEric Christopher  %arrayidx33 = getelementptr inbounds float, float* %a, i64 %11
197*cee313d2SEric Christopher  %13 = load float, float* %arrayidx33, align 4
198*cee313d2SEric Christopher  %add34 = fadd float %13, %mul30
199*cee313d2SEric Christopher  store float %add34, float* %arrayidx33, align 4
200*cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 5
201*cee313d2SEric Christopher  %14 = trunc i64 %indvars.iv.next to i32
202*cee313d2SEric Christopher  %cmp = icmp slt i32 %14, 3200
203*cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
204*cee313d2SEric Christopher
205*cee313d2SEric Christopher; CHECK-LABEL: @goo
206*cee313d2SEric Christopher
207*cee313d2SEric Christopher; CHECK: for.body:
208*cee313d2SEric Christopher; CHECK: %indvar = phi i64 [ %indvar.next, %for.body ], [ 0, %entry ]
209*cee313d2SEric Christopher; CHECK: %0 = trunc i64 %indvar to i32
210*cee313d2SEric Christopher; CHECK: %arrayidx = getelementptr inbounds float, float* %b, i64 %indvar
211*cee313d2SEric Christopher; CHECK: %1 = load float, float* %arrayidx, align 4
212*cee313d2SEric Christopher; CHECK: %mul = fmul float %1, %alpha
213*cee313d2SEric Christopher; CHECK: %arrayidx2 = getelementptr inbounds float, float* %a, i64 %indvar
214*cee313d2SEric Christopher; CHECK: %2 = load float, float* %arrayidx2, align 4
215*cee313d2SEric Christopher; CHECK: %add = fadd float %2, %mul
216*cee313d2SEric Christopher; CHECK: store float %add, float* %arrayidx2, align 4
217*cee313d2SEric Christopher; CHECK: %indvar.next = add i64 %indvar, 1
218*cee313d2SEric Christopher; CHECK: %exitcond = icmp eq i32 %0, 3199
219*cee313d2SEric Christopher; CHECK: br i1 %exitcond, label %for.end, label %for.body
220*cee313d2SEric Christopher
221*cee313d2SEric Christopher; CHECK: ret
222*cee313d2SEric Christopher
223*cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
224*cee313d2SEric Christopher  ret void
225*cee313d2SEric Christopher}
226*cee313d2SEric Christopher
227*cee313d2SEric Christopher; void hoo(float alpha, float *a, float *b, int *ip) {
228*cee313d2SEric Christopher;   for (int i = 0; i < 3200; i += 5) {
229*cee313d2SEric Christopher;     a[i] += alpha * b[ip[i]];
230*cee313d2SEric Christopher;     a[i + 1] += alpha * b[ip[i + 1]];
231*cee313d2SEric Christopher;     a[i + 2] += alpha * b[ip[i + 2]];
232*cee313d2SEric Christopher;     a[i + 3] += alpha * b[ip[i + 3]];
233*cee313d2SEric Christopher;     a[i + 4] += alpha * b[ip[i + 4]];
234*cee313d2SEric Christopher;   }
235*cee313d2SEric Christopher; }
236*cee313d2SEric Christopher
237*cee313d2SEric Christopher; Function Attrs: nounwind uwtable
238*cee313d2SEric Christopherdefine void @hoo(float %alpha, float* nocapture %a, float* nocapture readonly %b, i32* nocapture readonly %ip) #0 {
239*cee313d2SEric Christopherentry:
240*cee313d2SEric Christopher  br label %for.body
241*cee313d2SEric Christopher
242*cee313d2SEric Christopherfor.body:                                         ; preds = %entry, %for.body
243*cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
244*cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %ip, i64 %indvars.iv
245*cee313d2SEric Christopher  %0 = load i32, i32* %arrayidx, align 4
246*cee313d2SEric Christopher  %idxprom1 = sext i32 %0 to i64
247*cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds float, float* %b, i64 %idxprom1
248*cee313d2SEric Christopher  %1 = load float, float* %arrayidx2, align 4
249*cee313d2SEric Christopher  %mul = fmul float %1, %alpha
250*cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds float, float* %a, i64 %indvars.iv
251*cee313d2SEric Christopher  %2 = load float, float* %arrayidx4, align 4
252*cee313d2SEric Christopher  %add = fadd float %2, %mul
253*cee313d2SEric Christopher  store float %add, float* %arrayidx4, align 4
254*cee313d2SEric Christopher  %3 = add nsw i64 %indvars.iv, 1
255*cee313d2SEric Christopher  %arrayidx7 = getelementptr inbounds i32, i32* %ip, i64 %3
256*cee313d2SEric Christopher  %4 = load i32, i32* %arrayidx7, align 4
257*cee313d2SEric Christopher  %idxprom8 = sext i32 %4 to i64
258*cee313d2SEric Christopher  %arrayidx9 = getelementptr inbounds float, float* %b, i64 %idxprom8
259*cee313d2SEric Christopher  %5 = load float, float* %arrayidx9, align 4
260*cee313d2SEric Christopher  %mul10 = fmul float %5, %alpha
261*cee313d2SEric Christopher  %arrayidx13 = getelementptr inbounds float, float* %a, i64 %3
262*cee313d2SEric Christopher  %6 = load float, float* %arrayidx13, align 4
263*cee313d2SEric Christopher  %add14 = fadd float %6, %mul10
264*cee313d2SEric Christopher  store float %add14, float* %arrayidx13, align 4
265*cee313d2SEric Christopher  %7 = add nsw i64 %indvars.iv, 2
266*cee313d2SEric Christopher  %arrayidx17 = getelementptr inbounds i32, i32* %ip, i64 %7
267*cee313d2SEric Christopher  %8 = load i32, i32* %arrayidx17, align 4
268*cee313d2SEric Christopher  %idxprom18 = sext i32 %8 to i64
269*cee313d2SEric Christopher  %arrayidx19 = getelementptr inbounds float, float* %b, i64 %idxprom18
270*cee313d2SEric Christopher  %9 = load float, float* %arrayidx19, align 4
271*cee313d2SEric Christopher  %mul20 = fmul float %9, %alpha
272*cee313d2SEric Christopher  %arrayidx23 = getelementptr inbounds float, float* %a, i64 %7
273*cee313d2SEric Christopher  %10 = load float, float* %arrayidx23, align 4
274*cee313d2SEric Christopher  %add24 = fadd float %10, %mul20
275*cee313d2SEric Christopher  store float %add24, float* %arrayidx23, align 4
276*cee313d2SEric Christopher  %11 = add nsw i64 %indvars.iv, 3
277*cee313d2SEric Christopher  %arrayidx27 = getelementptr inbounds i32, i32* %ip, i64 %11
278*cee313d2SEric Christopher  %12 = load i32, i32* %arrayidx27, align 4
279*cee313d2SEric Christopher  %idxprom28 = sext i32 %12 to i64
280*cee313d2SEric Christopher  %arrayidx29 = getelementptr inbounds float, float* %b, i64 %idxprom28
281*cee313d2SEric Christopher  %13 = load float, float* %arrayidx29, align 4
282*cee313d2SEric Christopher  %mul30 = fmul float %13, %alpha
283*cee313d2SEric Christopher  %arrayidx33 = getelementptr inbounds float, float* %a, i64 %11
284*cee313d2SEric Christopher  %14 = load float, float* %arrayidx33, align 4
285*cee313d2SEric Christopher  %add34 = fadd float %14, %mul30
286*cee313d2SEric Christopher  store float %add34, float* %arrayidx33, align 4
287*cee313d2SEric Christopher  %15 = add nsw i64 %indvars.iv, 4
288*cee313d2SEric Christopher  %arrayidx37 = getelementptr inbounds i32, i32* %ip, i64 %15
289*cee313d2SEric Christopher  %16 = load i32, i32* %arrayidx37, align 4
290*cee313d2SEric Christopher  %idxprom38 = sext i32 %16 to i64
291*cee313d2SEric Christopher  %arrayidx39 = getelementptr inbounds float, float* %b, i64 %idxprom38
292*cee313d2SEric Christopher  %17 = load float, float* %arrayidx39, align 4
293*cee313d2SEric Christopher  %mul40 = fmul float %17, %alpha
294*cee313d2SEric Christopher  %arrayidx43 = getelementptr inbounds float, float* %a, i64 %15
295*cee313d2SEric Christopher  %18 = load float, float* %arrayidx43, align 4
296*cee313d2SEric Christopher  %add44 = fadd float %18, %mul40
297*cee313d2SEric Christopher  store float %add44, float* %arrayidx43, align 4
298*cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 5
299*cee313d2SEric Christopher  %19 = trunc i64 %indvars.iv.next to i32
300*cee313d2SEric Christopher  %cmp = icmp slt i32 %19, 3200
301*cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
302*cee313d2SEric Christopher
303*cee313d2SEric Christopher; CHECK-LABEL: @hoo
304*cee313d2SEric Christopher
305*cee313d2SEric Christopher; CHECK: for.body:
306*cee313d2SEric Christopher; CHECK: %indvar = phi i64 [ %indvar.next, %for.body ], [ 0, %entry ]
307*cee313d2SEric Christopher; CHECK: %0 = trunc i64 %indvar to i32
308*cee313d2SEric Christopher; CHECK: %arrayidx = getelementptr inbounds i32, i32* %ip, i64 %indvar
309*cee313d2SEric Christopher; CHECK: %1 = load i32, i32* %arrayidx, align 4
310*cee313d2SEric Christopher; CHECK: %idxprom1 = sext i32 %1 to i64
311*cee313d2SEric Christopher; CHECK: %arrayidx2 = getelementptr inbounds float, float* %b, i64 %idxprom1
312*cee313d2SEric Christopher; CHECK: %2 = load float, float* %arrayidx2, align 4
313*cee313d2SEric Christopher; CHECK: %mul = fmul float %2, %alpha
314*cee313d2SEric Christopher; CHECK: %arrayidx4 = getelementptr inbounds float, float* %a, i64 %indvar
315*cee313d2SEric Christopher; CHECK: %3 = load float, float* %arrayidx4, align 4
316*cee313d2SEric Christopher; CHECK: %add = fadd float %3, %mul
317*cee313d2SEric Christopher; CHECK: store float %add, float* %arrayidx4, align 4
318*cee313d2SEric Christopher; CHECK: %indvar.next = add i64 %indvar, 1
319*cee313d2SEric Christopher; CHECK: %exitcond = icmp eq i32 %0, 3199
320*cee313d2SEric Christopher; CHECK: br i1 %exitcond, label %for.end, label %for.body
321*cee313d2SEric Christopher
322*cee313d2SEric Christopher; CHECK: ret
323*cee313d2SEric Christopher
324*cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
325*cee313d2SEric Christopher  ret void
326*cee313d2SEric Christopher}
327*cee313d2SEric Christopher
328*cee313d2SEric Christopher; void multi1(int *x) {
329*cee313d2SEric Christopher;   y = foo(0)
330*cee313d2SEric Christopher;   for (int i = 0; i < 500; ++i) {
331*cee313d2SEric Christopher;     x[3*i] = y;
332*cee313d2SEric Christopher;     x[3*i+1] = y;
333*cee313d2SEric Christopher;     x[3*i+2] = y;
334*cee313d2SEric Christopher;     x[3*i+6] = y;
335*cee313d2SEric Christopher;     x[3*i+7] = y;
336*cee313d2SEric Christopher;     x[3*i+8] = y;
337*cee313d2SEric Christopher;   }
338*cee313d2SEric Christopher; }
339*cee313d2SEric Christopher
340*cee313d2SEric Christopher; Function Attrs: nounwind uwtable
341*cee313d2SEric Christopherdefine void @multi1(i32* nocapture %x) #0 {
342*cee313d2SEric Christopherentry:
343*cee313d2SEric Christopher  %call = tail call i32 @foo(i32 0) #1
344*cee313d2SEric Christopher  br label %for.body
345*cee313d2SEric Christopher
346*cee313d2SEric Christopherfor.body:                                         ; preds = %for.body, %entry
347*cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
348*cee313d2SEric Christopher  %0 = mul nsw i64 %indvars.iv, 3
349*cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %x, i64 %0
350*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx, align 4
351*cee313d2SEric Christopher  %1 = add nsw i64 %0, 1
352*cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds i32, i32* %x, i64 %1
353*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx4, align 4
354*cee313d2SEric Christopher  %2 = add nsw i64 %0, 2
355*cee313d2SEric Christopher  %arrayidx9 = getelementptr inbounds i32, i32* %x, i64 %2
356*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx9, align 4
357*cee313d2SEric Christopher  %3 = add nsw i64 %0, 6
358*cee313d2SEric Christopher  %arrayidx6 = getelementptr inbounds i32, i32* %x, i64 %3
359*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx6, align 4
360*cee313d2SEric Christopher  %4 = add nsw i64 %0, 7
361*cee313d2SEric Christopher  %arrayidx7 = getelementptr inbounds i32, i32* %x, i64 %4
362*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx7, align 4
363*cee313d2SEric Christopher  %5 = add nsw i64 %0, 8
364*cee313d2SEric Christopher  %arrayidx8 = getelementptr inbounds i32, i32* %x, i64 %5
365*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx8, align 4
366*cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
367*cee313d2SEric Christopher  %exitcond = icmp eq i64 %indvars.iv.next, 500
368*cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
369*cee313d2SEric Christopher
370*cee313d2SEric Christopher; CHECK-LABEL: @multi1
371*cee313d2SEric Christopher
372*cee313d2SEric Christopher; CHECK:for.body:
373*cee313d2SEric Christopher; CHECK:  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
374*cee313d2SEric Christopher; CHECK:  %0 = add i64 %indvars.iv, 6
375*cee313d2SEric Christopher; CHECK:  %arrayidx = getelementptr inbounds i32, i32* %x, i64 %indvars.iv
376*cee313d2SEric Christopher; CHECK:  store i32 %call, i32* %arrayidx, align 4
377*cee313d2SEric Christopher; CHECK:  %arrayidx6 = getelementptr inbounds i32, i32* %x, i64 %0
378*cee313d2SEric Christopher; CHECK:  store i32 %call, i32* %arrayidx6, align 4
379*cee313d2SEric Christopher; CHECK:  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
380*cee313d2SEric Christopher; CHECK:  %exitcond1 = icmp eq i64 %indvars.iv, 1499
381*cee313d2SEric Christopher; CHECK:  br i1 %exitcond1, label %for.end, label %for.body
382*cee313d2SEric Christopher
383*cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
384*cee313d2SEric Christopher  ret void
385*cee313d2SEric Christopher}
386*cee313d2SEric Christopher
387*cee313d2SEric Christopher; void multi2(int *x) {
388*cee313d2SEric Christopher;   y = foo(0)
389*cee313d2SEric Christopher;   for (int i = 0; i < 500; ++i) {
390*cee313d2SEric Christopher;     x[3*i] = y;
391*cee313d2SEric Christopher;     x[3*i+1] = y;
392*cee313d2SEric Christopher;     x[3*i+2] = y;
393*cee313d2SEric Christopher;     x[3*(i+1)] = y;
394*cee313d2SEric Christopher;     x[3*(i+1)+1] = y;
395*cee313d2SEric Christopher;     x[3*(i+1)+2] = y;
396*cee313d2SEric Christopher;   }
397*cee313d2SEric Christopher; }
398*cee313d2SEric Christopher
399*cee313d2SEric Christopher; Function Attrs: nounwind uwtable
400*cee313d2SEric Christopherdefine void @multi2(i32* nocapture %x) #0 {
401*cee313d2SEric Christopherentry:
402*cee313d2SEric Christopher  %call = tail call i32 @foo(i32 0) #1
403*cee313d2SEric Christopher  br label %for.body
404*cee313d2SEric Christopher
405*cee313d2SEric Christopherfor.body:                                         ; preds = %for.body, %entry
406*cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
407*cee313d2SEric Christopher  %0 = mul nsw i64 %indvars.iv, 3
408*cee313d2SEric Christopher  %add = add nsw i64 %indvars.iv, 1
409*cee313d2SEric Christopher  %newmul = mul nsw i64 %add, 3
410*cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %x, i64 %0
411*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx, align 4
412*cee313d2SEric Christopher  %1 = add nsw i64 %0, 1
413*cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds i32, i32* %x, i64 %1
414*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx4, align 4
415*cee313d2SEric Christopher  %2 = add nsw i64 %0, 2
416*cee313d2SEric Christopher  %arrayidx9 = getelementptr inbounds i32, i32* %x, i64 %2
417*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx9, align 4
418*cee313d2SEric Christopher  %arrayidx6 = getelementptr inbounds i32, i32* %x, i64 %newmul
419*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx6, align 4
420*cee313d2SEric Christopher  %3 = add nsw i64 %newmul, 1
421*cee313d2SEric Christopher  %arrayidx7 = getelementptr inbounds i32, i32* %x, i64 %3
422*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx7, align 4
423*cee313d2SEric Christopher  %4 = add nsw i64 %newmul, 2
424*cee313d2SEric Christopher  %arrayidx8 = getelementptr inbounds i32, i32* %x, i64 %4
425*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx8, align 4
426*cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
427*cee313d2SEric Christopher  %exitcond = icmp eq i64 %indvars.iv.next, 500
428*cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
429*cee313d2SEric Christopher
430*cee313d2SEric Christopher; CHECK-LABEL: @multi2
431*cee313d2SEric Christopher
432*cee313d2SEric Christopher; CHECK:for.body:
433*cee313d2SEric Christopher; CHECK:  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
434*cee313d2SEric Christopher; CHECK:  %0 = add i64 %indvars.iv, 3
435*cee313d2SEric Christopher; CHECK:  %arrayidx = getelementptr inbounds i32, i32* %x, i64 %indvars.iv
436*cee313d2SEric Christopher; CHECK:  store i32 %call, i32* %arrayidx, align 4
437*cee313d2SEric Christopher; CHECK:  %arrayidx6 = getelementptr inbounds i32, i32* %x, i64 %0
438*cee313d2SEric Christopher; CHECK:  store i32 %call, i32* %arrayidx6, align 4
439*cee313d2SEric Christopher; CHECK:  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
440*cee313d2SEric Christopher; CHECK:  %exitcond1 = icmp eq i64 %indvars.iv, 1499
441*cee313d2SEric Christopher; CHECK:  br i1 %exitcond1, label %for.end, label %for.body
442*cee313d2SEric Christopher
443*cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
444*cee313d2SEric Christopher  ret void
445*cee313d2SEric Christopher}
446*cee313d2SEric Christopher
447*cee313d2SEric Christopher; void multi3(int *x) {
448*cee313d2SEric Christopher;   y = foo(0)
449*cee313d2SEric Christopher;   for (int i = 0; i < 500; ++i) {
450*cee313d2SEric Christopher;     // Note: No zero index
451*cee313d2SEric Christopher;     x[3*i+3] = y;
452*cee313d2SEric Christopher;     x[3*i+4] = y;
453*cee313d2SEric Christopher;     x[3*i+5] = y;
454*cee313d2SEric Christopher;   }
455*cee313d2SEric Christopher; }
456*cee313d2SEric Christopher
457*cee313d2SEric Christopher; Function Attrs: nounwind uwtable
458*cee313d2SEric Christopherdefine void @multi3(i32* nocapture %x) #0 {
459*cee313d2SEric Christopherentry:
460*cee313d2SEric Christopher  %call = tail call i32 @foo(i32 0) #1
461*cee313d2SEric Christopher  br label %for.body
462*cee313d2SEric Christopher
463*cee313d2SEric Christopherfor.body:                                         ; preds = %for.body, %entry
464*cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
465*cee313d2SEric Christopher  %0 = mul nsw i64 %indvars.iv, 3
466*cee313d2SEric Christopher  %x0 = add nsw i64 %0, 3
467*cee313d2SEric Christopher  %add = add nsw i64 %indvars.iv, 1
468*cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %x, i64 %x0
469*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx, align 4
470*cee313d2SEric Christopher  %1 = add nsw i64 %0, 4
471*cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds i32, i32* %x, i64 %1
472*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx4, align 4
473*cee313d2SEric Christopher  %2 = add nsw i64 %0, 5
474*cee313d2SEric Christopher  %arrayidx9 = getelementptr inbounds i32, i32* %x, i64 %2
475*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx9, align 4
476*cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
477*cee313d2SEric Christopher  %exitcond = icmp eq i64 %indvars.iv.next, 500
478*cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
479*cee313d2SEric Christopher
480*cee313d2SEric Christopher; CHECK-LABEL: @multi3
481*cee313d2SEric Christopher; CHECK: for.body:
482*cee313d2SEric Christopher; CHECK:   %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
483*cee313d2SEric Christopher; CHECK:   %0 = add i64 %indvars.iv, 3
484*cee313d2SEric Christopher; CHECK:   %arrayidx = getelementptr inbounds i32, i32* %x, i64 %0
485*cee313d2SEric Christopher; CHECK:   store i32 %call, i32* %arrayidx, align 4
486*cee313d2SEric Christopher; CHECK:   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
487*cee313d2SEric Christopher; CHECK:   %exitcond1 = icmp eq i64 %indvars.iv, 1499
488*cee313d2SEric Christopher; CHECK:   br i1 %exitcond1, label %for.end, label %for.body
489*cee313d2SEric Christopher
490*cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
491*cee313d2SEric Christopher  ret void
492*cee313d2SEric Christopher}
493*cee313d2SEric Christopher
494*cee313d2SEric Christopher; int foo(int a);
495*cee313d2SEric Christopher; void bar2(int *x, int y, int z) {
496*cee313d2SEric Christopher;   for (int i = 0; i < 500; i += 3) {
497*cee313d2SEric Christopher;     foo(i+y+i*z); // Slightly reordered instruction order
498*cee313d2SEric Christopher;     foo(i+1+y+(i+1)*z);
499*cee313d2SEric Christopher;     foo(i+2+y+(i+2)*z);
500*cee313d2SEric Christopher;   }
501*cee313d2SEric Christopher; }
502*cee313d2SEric Christopher
503*cee313d2SEric Christopher; Function Attrs: nounwind uwtable
504*cee313d2SEric Christopherdefine void @bar2(i32* nocapture readnone %x, i32 %y, i32 %z) #0 {
505*cee313d2SEric Christopherentry:
506*cee313d2SEric Christopher  br label %for.body
507*cee313d2SEric Christopher
508*cee313d2SEric Christopherfor.body:                                         ; preds = %for.body, %entry
509*cee313d2SEric Christopher  %i.08 = phi i32 [ 0, %entry ], [ %add3, %for.body ]
510*cee313d2SEric Christopher
511*cee313d2SEric Christopher  %tmp1 = add i32 %i.08, %y
512*cee313d2SEric Christopher  %tmp2 = mul i32 %i.08, %z
513*cee313d2SEric Christopher  %tmp3 = add i32 %tmp2, %tmp1
514*cee313d2SEric Christopher  %call = tail call i32 @foo(i32 %tmp3) #1
515*cee313d2SEric Christopher
516*cee313d2SEric Christopher  %add = add nsw i32 %i.08, 1
517*cee313d2SEric Christopher  %tmp2a = mul i32 %add, %z
518*cee313d2SEric Christopher  %tmp1a = add i32 %add, %y
519*cee313d2SEric Christopher  %tmp3a = add i32 %tmp2a, %tmp1a
520*cee313d2SEric Christopher  %calla = tail call i32 @foo(i32 %tmp3a) #1
521*cee313d2SEric Christopher
522*cee313d2SEric Christopher  %add2 = add nsw i32 %i.08, 2
523*cee313d2SEric Christopher  %tmp2b = mul i32 %add2, %z
524*cee313d2SEric Christopher  %tmp1b = add i32 %add2, %y
525*cee313d2SEric Christopher  %tmp3b = add i32 %tmp2b, %tmp1b
526*cee313d2SEric Christopher  %callb = tail call i32 @foo(i32 %tmp3b) #1
527*cee313d2SEric Christopher
528*cee313d2SEric Christopher  %add3 = add nsw i32 %i.08, 3
529*cee313d2SEric Christopher
530*cee313d2SEric Christopher  %exitcond = icmp sge i32 %add3, 500
531*cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
532*cee313d2SEric Christopher
533*cee313d2SEric Christopher; CHECK-LABEL: @bar2
534*cee313d2SEric Christopher
535*cee313d2SEric Christopher; CHECK: for.body:
536*cee313d2SEric Christopher; CHECK: %indvar = phi i32 [ %indvar.next, %for.body ], [ 0, %entry ]
537*cee313d2SEric Christopher; CHECK: %tmp1 = add i32 %indvar, %y
538*cee313d2SEric Christopher; CHECK: %tmp2 = mul i32 %indvar, %z
539*cee313d2SEric Christopher; CHECK: %tmp3 = add i32 %tmp2, %tmp1
540*cee313d2SEric Christopher; CHECK: %call = tail call i32 @foo(i32 %tmp3) #1
541*cee313d2SEric Christopher; CHECK: %indvar.next = add i32 %indvar, 1
542*cee313d2SEric Christopher; CHECK: %exitcond1 = icmp eq i32 %indvar, 500
543*cee313d2SEric Christopher; CHECK: br i1 %exitcond1, label %for.end, label %for.body
544*cee313d2SEric Christopher
545*cee313d2SEric Christopher; CHECK: ret
546*cee313d2SEric Christopher
547*cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
548*cee313d2SEric Christopher  ret void
549*cee313d2SEric Christopher}
550*cee313d2SEric Christopher
551*cee313d2SEric Christopher%struct.s = type { i32, i32 }
552*cee313d2SEric Christopher
553*cee313d2SEric Christopher; Function Attrs: nounwind uwtable
554*cee313d2SEric Christopherdefine void @gep1(%struct.s* nocapture %x) #0 {
555*cee313d2SEric Christopherentry:
556*cee313d2SEric Christopher  %call = tail call i32 @foo(i32 0) #1
557*cee313d2SEric Christopher  br label %for.body
558*cee313d2SEric Christopher
559*cee313d2SEric Christopherfor.body:                                         ; preds = %for.body, %entry
560*cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
561*cee313d2SEric Christopher  %0 = mul nsw i64 %indvars.iv, 3
562*cee313d2SEric Christopher  %arrayidx = getelementptr inbounds %struct.s, %struct.s* %x, i64 %0, i32 0
563*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx, align 4
564*cee313d2SEric Christopher  %1 = add nsw i64 %0, 1
565*cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds %struct.s, %struct.s* %x, i64 %1, i32 0
566*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx4, align 4
567*cee313d2SEric Christopher  %2 = add nsw i64 %0, 2
568*cee313d2SEric Christopher  %arrayidx9 = getelementptr inbounds %struct.s, %struct.s* %x, i64 %2, i32 0
569*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx9, align 4
570*cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
571*cee313d2SEric Christopher  %exitcond = icmp eq i64 %indvars.iv.next, 500
572*cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
573*cee313d2SEric Christopher
574*cee313d2SEric Christopher; CHECK-LABEL: @gep1
575*cee313d2SEric Christopher; This test is a crash test only.
576*cee313d2SEric Christopher; CHECK: ret
577*cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
578*cee313d2SEric Christopher  ret void
579*cee313d2SEric Christopher}
580*cee313d2SEric Christopher
581*cee313d2SEric Christopherdefine void @gep-indexing(i32* nocapture %x) {
582*cee313d2SEric Christopherentry:
583*cee313d2SEric Christopher  %call = tail call i32 @foo(i32 0) #1
584*cee313d2SEric Christopher  br label %for.body
585*cee313d2SEric Christopher
586*cee313d2SEric Christopherfor.body:                                         ; preds = %for.body, %entry
587*cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
588*cee313d2SEric Christopher  %0 = mul nsw i64 %indvars.iv, 3
589*cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %x, i64 %0
590*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx, align 4
591*cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds i32, i32* %arrayidx, i64 1
592*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx4, align 4
593*cee313d2SEric Christopher  %arrayidx9 = getelementptr inbounds i32, i32* %arrayidx, i64 2
594*cee313d2SEric Christopher  store i32 %call, i32* %arrayidx9, align 4
595*cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
596*cee313d2SEric Christopher  %exitcond = icmp eq i64 %indvars.iv.next, 500
597*cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
598*cee313d2SEric Christopher
599*cee313d2SEric Christopher; CHECK-LABEL: @gep-indexing
600*cee313d2SEric Christopher; CHECK:      for.body:
601*cee313d2SEric Christopher; CHECK-NEXT:   %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
602*cee313d2SEric Christopher; CHECK-NEXT:   %scevgep = getelementptr i32, i32* %x, i64 %indvars.iv
603*cee313d2SEric Christopher; CHECK-NEXT:   store i32 %call, i32* %scevgep, align 4
604*cee313d2SEric Christopher; CHECK-NEXT:   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
605*cee313d2SEric Christopher; CHECK-NEXT:   %exitcond1 = icmp eq i64 %indvars.iv, 1499
606*cee313d2SEric Christopher; CHECK-NEXT:   br i1 %exitcond1, label %for.end, label %for.body
607*cee313d2SEric Christopher
608*cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
609*cee313d2SEric Christopher  ret void
610*cee313d2SEric Christopher}
611*cee313d2SEric Christopher
612*cee313d2SEric Christopher
613*cee313d2SEric Christopherdefine void @unordered_atomic_ops(i32* noalias %buf_0, i32* noalias %buf_1) {
614*cee313d2SEric Christopher; CHECK-LABEL: @unordered_atomic_ops(
615*cee313d2SEric Christopher
616*cee313d2SEric Christopher; CHECK: for.body:
617*cee313d2SEric Christopher; CHECK-NEXT:   %indvar = phi i32 [ %indvar.next, %for.body ], [ 0, %entry ]
618*cee313d2SEric Christopher; CHECK-NEXT:   %buf0_a = getelementptr i32, i32* %buf_0, i32 %indvar
619*cee313d2SEric Christopher; CHECK-NEXT:   %buf1_a = getelementptr i32, i32* %buf_1, i32 %indvar
620*cee313d2SEric Christopher; CHECK-NEXT:   %va = load atomic i32, i32* %buf0_a unordered, align 4
621*cee313d2SEric Christopher; CHECK-NEXT:   store atomic i32 %va, i32* %buf1_a unordered, align 4
622*cee313d2SEric Christopher; CHECK-NEXT:   %indvar.next = add i32 %indvar, 1
623*cee313d2SEric Christopher; CHECK-NEXT:   %exitcond = icmp eq i32 %indvar, 3199
624*cee313d2SEric Christopher; CHECK-NEXT:   br i1 %exitcond, label %for.end, label %for.body
625*cee313d2SEric Christopher
626*cee313d2SEric Christopherentry:
627*cee313d2SEric Christopher  br label %for.body
628*cee313d2SEric Christopher
629*cee313d2SEric Christopherfor.body:
630*cee313d2SEric Christopher  %indvars.iv = phi i32 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
631*cee313d2SEric Christopher  %indvars.iv.next = add i32 %indvars.iv, 2
632*cee313d2SEric Christopher  %indvars.mid = add i32 %indvars.iv, 1
633*cee313d2SEric Christopher  %buf0_a = getelementptr i32, i32* %buf_0, i32 %indvars.iv
634*cee313d2SEric Christopher  %buf0_b = getelementptr i32, i32* %buf_0, i32 %indvars.mid
635*cee313d2SEric Christopher  %buf1_a = getelementptr i32, i32* %buf_1, i32 %indvars.iv
636*cee313d2SEric Christopher  %buf1_b = getelementptr i32, i32* %buf_1, i32 %indvars.mid
637*cee313d2SEric Christopher  %va = load atomic i32, i32* %buf0_a unordered, align 4
638*cee313d2SEric Christopher  %vb = load atomic i32, i32* %buf0_b unordered, align 4
639*cee313d2SEric Christopher  store atomic i32 %va, i32* %buf1_a unordered, align 4
640*cee313d2SEric Christopher  store atomic i32 %vb, i32* %buf1_b unordered, align 4
641*cee313d2SEric Christopher  %cmp = icmp slt i32 %indvars.iv.next, 3200
642*cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
643*cee313d2SEric Christopher
644*cee313d2SEric Christopherfor.end:
645*cee313d2SEric Christopher  ret void
646*cee313d2SEric Christopher}
647*cee313d2SEric Christopher
648*cee313d2SEric Christopherdefine void @unordered_atomic_ops_nomatch(i32* noalias %buf_0, i32* noalias %buf_1) {
649*cee313d2SEric Christopher; Negative test
650*cee313d2SEric Christopher
651*cee313d2SEric Christopher; CHECK-LABEL: @unordered_atomic_ops_nomatch(
652*cee313d2SEric Christopherentry:
653*cee313d2SEric Christopher  br label %for.body
654*cee313d2SEric Christopher
655*cee313d2SEric Christopherfor.body:
656*cee313d2SEric Christopher; CHECK: for.body:
657*cee313d2SEric Christopher; CHECK:   %indvars.iv.next = add i32 %indvars.iv, 2
658*cee313d2SEric Christopher; CHECK:   %indvars.mid = add i32 %indvars.iv, 1
659*cee313d2SEric Christopher; CHECK:   %cmp = icmp slt i32 %indvars.iv.next, 3200
660*cee313d2SEric Christopher; CHECK:   br i1 %cmp, label %for.body, label %for.end
661*cee313d2SEric Christopher
662*cee313d2SEric Christopher  %indvars.iv = phi i32 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
663*cee313d2SEric Christopher  %indvars.iv.next = add i32 %indvars.iv, 2
664*cee313d2SEric Christopher  %indvars.mid = add i32 %indvars.iv, 1
665*cee313d2SEric Christopher  %buf0_a = getelementptr i32, i32* %buf_0, i32 %indvars.iv
666*cee313d2SEric Christopher  %buf0_b = getelementptr i32, i32* %buf_0, i32 %indvars.mid
667*cee313d2SEric Christopher  %buf1_a = getelementptr i32, i32* %buf_1, i32 %indvars.iv
668*cee313d2SEric Christopher  %buf1_b = getelementptr i32, i32* %buf_1, i32 %indvars.mid
669*cee313d2SEric Christopher  %va = load atomic i32, i32* %buf0_a unordered, align 4
670*cee313d2SEric Christopher  %vb = load atomic i32, i32* %buf0_b unordered, align 4
671*cee313d2SEric Christopher  store i32 %va, i32* %buf1_a, align 4  ;; Not atomic
672*cee313d2SEric Christopher  store atomic i32 %vb, i32* %buf1_b unordered, align 4
673*cee313d2SEric Christopher  %cmp = icmp slt i32 %indvars.iv.next, 3200
674*cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
675*cee313d2SEric Christopher
676*cee313d2SEric Christopherfor.end:
677*cee313d2SEric Christopher  ret void
678*cee313d2SEric Christopher}
679*cee313d2SEric Christopher
680*cee313d2SEric Christopherdefine void @ordered_atomic_ops(i32* noalias %buf_0, i32* noalias %buf_1) {
681*cee313d2SEric Christopher; Negative test
682*cee313d2SEric Christopher
683*cee313d2SEric Christopher; CHECK-LABEL: @ordered_atomic_ops(
684*cee313d2SEric Christopherentry:
685*cee313d2SEric Christopher  br label %for.body
686*cee313d2SEric Christopher
687*cee313d2SEric Christopherfor.body:
688*cee313d2SEric Christopher; CHECK: for.body:
689*cee313d2SEric Christopher; CHECK:   %indvars.iv.next = add i32 %indvars.iv, 2
690*cee313d2SEric Christopher; CHECK:   %indvars.mid = add i32 %indvars.iv, 1
691*cee313d2SEric Christopher; CHECK:   %cmp = icmp slt i32 %indvars.iv.next, 3200
692*cee313d2SEric Christopher; CHECK:   br i1 %cmp, label %for.body, label %for.end
693*cee313d2SEric Christopher
694*cee313d2SEric Christopher  %indvars.iv = phi i32 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
695*cee313d2SEric Christopher  %indvars.iv.next = add i32 %indvars.iv, 2
696*cee313d2SEric Christopher  %indvars.mid = add i32 %indvars.iv, 1
697*cee313d2SEric Christopher  %buf0_a = getelementptr i32, i32* %buf_0, i32 %indvars.iv
698*cee313d2SEric Christopher  %buf0_b = getelementptr i32, i32* %buf_0, i32 %indvars.mid
699*cee313d2SEric Christopher  %buf1_a = getelementptr i32, i32* %buf_1, i32 %indvars.iv
700*cee313d2SEric Christopher  %buf1_b = getelementptr i32, i32* %buf_1, i32 %indvars.mid
701*cee313d2SEric Christopher  %va = load atomic i32, i32* %buf0_a acquire, align 4
702*cee313d2SEric Christopher  %vb = load atomic i32, i32* %buf0_b acquire, align 4
703*cee313d2SEric Christopher  store atomic i32 %va, i32* %buf1_a release, align 4
704*cee313d2SEric Christopher  store atomic i32 %vb, i32* %buf1_b release, align 4
705*cee313d2SEric Christopher  %cmp = icmp slt i32 %indvars.iv.next, 3200
706*cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
707*cee313d2SEric Christopher
708*cee313d2SEric Christopherfor.end:
709*cee313d2SEric Christopher  ret void
710*cee313d2SEric Christopher}
711*cee313d2SEric Christopher
712*cee313d2SEric Christopherdefine void @unordered_atomic_ops_with_fence(i32* noalias %buf_0, i32* noalias %buf_1) {
713*cee313d2SEric Christopher; CHECK-LABEL: @unordered_atomic_ops_with_fence(
714*cee313d2SEric Christopherentry:
715*cee313d2SEric Christopher  br label %for.body
716*cee313d2SEric Christopher
717*cee313d2SEric Christopherfor.body:
718*cee313d2SEric Christopher; CHECK: for.body:
719*cee313d2SEric Christopher; CHECK:  %va = load atomic i32, i32* %buf0_a unordered, align 4
720*cee313d2SEric Christopher; CHECK-NEXT:  %vb = load atomic i32, i32* %buf0_b unordered, align 4
721*cee313d2SEric Christopher; CHECK-NEXT:  fence seq_cst
722*cee313d2SEric Christopher; CHECK-NEXT:  store atomic i32 %va, i32* %buf1_a unordered, align 4
723*cee313d2SEric Christopher; CHECK-NEXT:  store atomic i32 %vb, i32* %buf1_b unordered, align 4
724*cee313d2SEric Christopher
725*cee313d2SEric Christopher  %indvars.iv = phi i32 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
726*cee313d2SEric Christopher  %indvars.iv.next = add i32 %indvars.iv, 2
727*cee313d2SEric Christopher  %indvars.mid = add i32 %indvars.iv, 1
728*cee313d2SEric Christopher  %buf0_a = getelementptr i32, i32* %buf_0, i32 %indvars.iv
729*cee313d2SEric Christopher  %buf0_b = getelementptr i32, i32* %buf_0, i32 %indvars.mid
730*cee313d2SEric Christopher  %buf1_a = getelementptr i32, i32* %buf_1, i32 %indvars.iv
731*cee313d2SEric Christopher  %buf1_b = getelementptr i32, i32* %buf_1, i32 %indvars.mid
732*cee313d2SEric Christopher  %va = load atomic i32, i32* %buf0_a unordered, align 4
733*cee313d2SEric Christopher  %vb = load atomic i32, i32* %buf0_b unordered, align 4
734*cee313d2SEric Christopher  fence seq_cst
735*cee313d2SEric Christopher  store atomic i32 %va, i32* %buf1_a unordered, align 4
736*cee313d2SEric Christopher  store atomic i32 %vb, i32* %buf1_b unordered, align 4
737*cee313d2SEric Christopher  %cmp = icmp slt i32 %indvars.iv.next, 3200
738*cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
739*cee313d2SEric Christopher
740*cee313d2SEric Christopherfor.end:
741*cee313d2SEric Christopher  ret void
742*cee313d2SEric Christopher}
743*cee313d2SEric Christopher
744*cee313d2SEric Christopherdefine void @pointer_bitcast_baseinst(i16* %arg, i8* %arg1, i64 %arg2) {
745*cee313d2SEric Christopher; CHECK-LABEL: @pointer_bitcast_baseinst(
746*cee313d2SEric Christopher; CHECK:       bb3:
747*cee313d2SEric Christopher; CHECK-NEXT:    %indvar = phi i64 [ %indvar.next, %bb3 ], [ 0, %bb ]
748*cee313d2SEric Christopher; CHECK-NEXT:    %4 = shl i64 %indvar, 3
749*cee313d2SEric Christopher; CHECK-NEXT:    %5 = add i64 %4, 1
750*cee313d2SEric Christopher; CHECK-NEXT:    %tmp5 = shl nuw i64 %5, 1
751*cee313d2SEric Christopher; CHECK-NEXT:    %tmp6 = getelementptr i8, i8* %arg1, i64 %tmp5
752*cee313d2SEric Christopher; CHECK-NEXT:    %tmp7 = bitcast i8* %tmp6 to <8 x i16>*
753*cee313d2SEric Christopher; CHECK-NEXT:    %tmp8 = load <8 x i16>, <8 x i16>* %tmp7, align 2
754*cee313d2SEric Christopher; CHECK-NEXT:    %tmp13 = getelementptr i16, i16* %arg, i64 %5
755*cee313d2SEric Christopher; CHECK-NEXT:    %tmp14 = bitcast i16* %tmp13 to <8 x i16>*
756*cee313d2SEric Christopher; CHECK-NEXT:    store <8 x i16> %tmp8, <8 x i16>* %tmp14, align 2
757*cee313d2SEric Christopher; CHECK-NEXT:    %indvar.next = add i64 %indvar, 1
758*cee313d2SEric Christopher; CHECK-NEXT:    %exitcond = icmp eq i64 %indvar, %3
759*cee313d2SEric Christopher; CHECK-NEXT:    br i1 %exitcond, label %bb19, label %bb3
760*cee313d2SEric Christopherbb:
761*cee313d2SEric Christopher  br label %bb3
762*cee313d2SEric Christopher
763*cee313d2SEric Christopherbb3:                                              ; preds = %bb3, %bb
764*cee313d2SEric Christopher  %tmp = phi i64 [ 1, %bb ], [ %tmp17, %bb3 ]
765*cee313d2SEric Christopher  %tmp4 = add nuw i64 %tmp, 8
766*cee313d2SEric Christopher  %tmp5 = shl nuw i64 %tmp, 1
767*cee313d2SEric Christopher  %tmp6 = getelementptr i8, i8* %arg1, i64 %tmp5
768*cee313d2SEric Christopher  %tmp7 = bitcast i8* %tmp6 to <8 x i16>*
769*cee313d2SEric Christopher  %tmp8 = load <8 x i16>, <8 x i16>* %tmp7, align 2
770*cee313d2SEric Christopher  %tmp9 = shl i64 %tmp4, 1
771*cee313d2SEric Christopher  %tmp10 = getelementptr i8, i8* %arg1, i64 %tmp9
772*cee313d2SEric Christopher  %tmp11 = bitcast i8* %tmp10 to <8 x i16>*
773*cee313d2SEric Christopher  %tmp12 = load <8 x i16>, <8 x i16>* %tmp11, align 2
774*cee313d2SEric Christopher  %tmp13 = getelementptr i16, i16* %arg, i64 %tmp
775*cee313d2SEric Christopher  %tmp14 = bitcast i16* %tmp13 to <8 x i16>*
776*cee313d2SEric Christopher  store <8 x i16> %tmp8, <8 x i16>* %tmp14, align 2
777*cee313d2SEric Christopher  %tmp15 = getelementptr i16, i16* %arg, i64 %tmp4
778*cee313d2SEric Christopher  %tmp16 = bitcast i16* %tmp15 to <8 x i16>*
779*cee313d2SEric Christopher  store <8 x i16> %tmp12, <8 x i16>* %tmp16, align 2
780*cee313d2SEric Christopher  %tmp17 = add nuw nsw i64 %tmp, 16
781*cee313d2SEric Christopher  %tmp18 = icmp eq i64 %tmp17, %arg2
782*cee313d2SEric Christopher  br i1 %tmp18, label %bb19, label %bb3
783*cee313d2SEric Christopher
784*cee313d2SEric Christopherbb19:                                             ; preds = %bb3
785*cee313d2SEric Christopher  ret void
786*cee313d2SEric Christopher}
787*cee313d2SEric Christopher
788*cee313d2SEric Christopherdefine void @bad_step(i32* nocapture readnone %x) #0 {
789*cee313d2SEric Christopherentry:
790*cee313d2SEric Christopher  br label %for.body
791*cee313d2SEric Christopher
792*cee313d2SEric Christopherfor.body:                                         ; preds = %for.body, %entry
793*cee313d2SEric Christopher  %i.08 = phi i32 [ 0, %entry ], [ %add3, %for.body ]
794*cee313d2SEric Christopher  %call = tail call i32 @foo(i32 %i.08) #1
795*cee313d2SEric Christopher  %add = add nsw i32 %i.08, 2
796*cee313d2SEric Christopher  %call1 = tail call i32 @foo(i32 %add) #1
797*cee313d2SEric Christopher  %add2 = add nsw i32 %i.08, 3
798*cee313d2SEric Christopher  %call3 = tail call i32 @foo(i32 %add2) #1
799*cee313d2SEric Christopher  %add3 = add nsw i32 %i.08, 6
800*cee313d2SEric Christopher  %exitcond = icmp sge i32 %add3, 500
801*cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
802*cee313d2SEric Christopher
803*cee313d2SEric Christopher; CHECK-LABEL: @bad_step
804*cee313d2SEric Christopher; CHECK: %add = add nsw i32 %i.08, 2
805*cee313d2SEric Christopher; CHECK: %add2 = add nsw i32 %i.08, 3
806*cee313d2SEric Christopher; CHECK: %add3 = add nsw i32 %i.08, 6
807*cee313d2SEric Christopher
808*cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
809*cee313d2SEric Christopher  ret void
810*cee313d2SEric Christopher}
811*cee313d2SEric Christopher
812*cee313d2SEric Christopherattributes #0 = { nounwind uwtable }
813*cee313d2SEric Christopherattributes #1 = { nounwind }
814*cee313d2SEric Christopher
815