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