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