1*15fefcb9SArthur Eubanks; RUN: opt < %s -passes='default<O1>,loop-vectorize,dce,instcombine' -force-vector-interleave=1 -force-vector-width=4 -S | FileCheck %s
2cee313d2SEric Christopher
3cee313d2SEric Christophertarget datalayout = "e-p:32:32:32-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:64:128-a0:0:64-n32-S64"
4cee313d2SEric Christopher
5cee313d2SEric Christopher%struct.anon = type { [100 x i32], i32, [100 x i32] }
6cee313d2SEric Christopher%struct.anon.0 = type { [100 x [100 x i32]], i32, [100 x [100 x i32]] }
7cee313d2SEric Christopher
8cee313d2SEric Christopher@Foo = common global %struct.anon zeroinitializer, align 4
9cee313d2SEric Christopher@Bar = common global %struct.anon.0 zeroinitializer, align 4
10cee313d2SEric Christopher
11cee313d2SEric Christopher@PB = external global i32*
12cee313d2SEric Christopher@PA = external global i32*
13cee313d2SEric Christopher
14cee313d2SEric Christopher
15cee313d2SEric Christopher;; === First, the tests that should always vectorize, whether statically or by adding run-time checks ===
16cee313d2SEric Christopher
17cee313d2SEric Christopher
18cee313d2SEric Christopher; /// Different objects, positive induction, constant distance
19cee313d2SEric Christopher; int noAlias01 (int a) {
20cee313d2SEric Christopher;   int i;
21cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
22cee313d2SEric Christopher;     Foo.A[i] = Foo.B[i] + a;
23cee313d2SEric Christopher;   return Foo.A[a];
24cee313d2SEric Christopher; }
25cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias01(
26cee313d2SEric Christopher; CHECK: add nsw <4 x i32>
27cee313d2SEric Christopher; CHECK: ret
28cee313d2SEric Christopher
29cee313d2SEric Christopherdefine i32 @noAlias01(i32 %a) nounwind {
30cee313d2SEric Christopherentry:
31cee313d2SEric Christopher  %a.addr = alloca i32, align 4
32cee313d2SEric Christopher  %i = alloca i32, align 4
33cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
34cee313d2SEric Christopher  store i32 0, i32* %i, align 4
35cee313d2SEric Christopher  br label %for.cond
36cee313d2SEric Christopher
37cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
38cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
39cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
40cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
41cee313d2SEric Christopher
42cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
43cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
44cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 2), i32 0, i32 %1
45cee313d2SEric Christopher  %2 = load i32, i32* %arrayidx, align 4
46cee313d2SEric Christopher  %3 = load i32, i32* %a.addr, align 4
47cee313d2SEric Christopher  %add = add nsw i32 %2, %3
48cee313d2SEric Christopher  %4 = load i32, i32* %i, align 4
49cee313d2SEric Christopher  %arrayidx1 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %4
50cee313d2SEric Christopher  store i32 %add, i32* %arrayidx1, align 4
51cee313d2SEric Christopher  br label %for.inc
52cee313d2SEric Christopher
53cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
54cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
55cee313d2SEric Christopher  %inc = add nsw i32 %5, 1
56cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
57cee313d2SEric Christopher  br label %for.cond
58cee313d2SEric Christopher
59cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
60cee313d2SEric Christopher  %6 = load i32, i32* %a.addr, align 4
61cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %6
62cee313d2SEric Christopher  %7 = load i32, i32* %arrayidx2, align 4
63cee313d2SEric Christopher  ret i32 %7
64cee313d2SEric Christopher}
65cee313d2SEric Christopher
66cee313d2SEric Christopher; /// Different objects, positive induction with widening slide
67cee313d2SEric Christopher; int noAlias02 (int a) {
68cee313d2SEric Christopher;   int i;
69cee313d2SEric Christopher;   for (i=0; i<SIZE-10; i++)
70cee313d2SEric Christopher;     Foo.A[i] = Foo.B[i+10] + a;
71cee313d2SEric Christopher;   return Foo.A[a];
72cee313d2SEric Christopher; }
73cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias02(
74cee313d2SEric Christopher; CHECK: add nsw <4 x i32>
75cee313d2SEric Christopher; CHECK: ret
76cee313d2SEric Christopher
77cee313d2SEric Christopherdefine i32 @noAlias02(i32 %a) {
78cee313d2SEric Christopherentry:
79cee313d2SEric Christopher  %a.addr = alloca i32, align 4
80cee313d2SEric Christopher  %i = alloca i32, align 4
81cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
82cee313d2SEric Christopher  store i32 0, i32* %i, align 4
83cee313d2SEric Christopher  br label %for.cond
84cee313d2SEric Christopher
85cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
86cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
87cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 90
88cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
89cee313d2SEric Christopher
90cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
91cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
92cee313d2SEric Christopher  %add = add nsw i32 %1, 10
93cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 2), i32 0, i32 %add
94cee313d2SEric Christopher  %2 = load i32, i32* %arrayidx, align 4
95cee313d2SEric Christopher  %3 = load i32, i32* %a.addr, align 4
96cee313d2SEric Christopher  %add1 = add nsw i32 %2, %3
97cee313d2SEric Christopher  %4 = load i32, i32* %i, align 4
98cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %4
99cee313d2SEric Christopher  store i32 %add1, i32* %arrayidx2, align 4
100cee313d2SEric Christopher  br label %for.inc
101cee313d2SEric Christopher
102cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
103cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
104cee313d2SEric Christopher  %inc = add nsw i32 %5, 1
105cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
106cee313d2SEric Christopher  br label %for.cond
107cee313d2SEric Christopher
108cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
109cee313d2SEric Christopher  %6 = load i32, i32* %a.addr, align 4
110cee313d2SEric Christopher  %arrayidx3 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %6
111cee313d2SEric Christopher  %7 = load i32, i32* %arrayidx3, align 4
112cee313d2SEric Christopher  ret i32 %7
113cee313d2SEric Christopher}
114cee313d2SEric Christopher
115cee313d2SEric Christopher; /// Different objects, positive induction with shortening slide
116cee313d2SEric Christopher; int noAlias03 (int a) {
117cee313d2SEric Christopher;   int i;
118cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
119cee313d2SEric Christopher;     Foo.A[i+10] = Foo.B[i] + a;
120cee313d2SEric Christopher;   return Foo.A[a];
121cee313d2SEric Christopher; }
122cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias03(
123cee313d2SEric Christopher; CHECK: add nsw <4 x i32>
124cee313d2SEric Christopher; CHECK: ret
125cee313d2SEric Christopher
126cee313d2SEric Christopherdefine i32 @noAlias03(i32 %a) {
127cee313d2SEric Christopherentry:
128cee313d2SEric Christopher  %a.addr = alloca i32, align 4
129cee313d2SEric Christopher  %i = alloca i32, align 4
130cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
131cee313d2SEric Christopher  store i32 0, i32* %i, align 4
132cee313d2SEric Christopher  br label %for.cond
133cee313d2SEric Christopher
134cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
135cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
136cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
137cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
138cee313d2SEric Christopher
139cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
140cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
141cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 2), i32 0, i32 %1
142cee313d2SEric Christopher  %2 = load i32, i32* %arrayidx, align 4
143cee313d2SEric Christopher  %3 = load i32, i32* %a.addr, align 4
144cee313d2SEric Christopher  %add = add nsw i32 %2, %3
145cee313d2SEric Christopher  %4 = load i32, i32* %i, align 4
146cee313d2SEric Christopher  %add1 = add nsw i32 %4, 10
147cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %add1
148cee313d2SEric Christopher  store i32 %add, i32* %arrayidx2, align 4
149cee313d2SEric Christopher  br label %for.inc
150cee313d2SEric Christopher
151cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
152cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
153cee313d2SEric Christopher  %inc = add nsw i32 %5, 1
154cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
155cee313d2SEric Christopher  br label %for.cond
156cee313d2SEric Christopher
157cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
158cee313d2SEric Christopher  %6 = load i32, i32* %a.addr, align 4
159cee313d2SEric Christopher  %arrayidx3 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %6
160cee313d2SEric Christopher  %7 = load i32, i32* %arrayidx3, align 4
161cee313d2SEric Christopher  ret i32 %7
162cee313d2SEric Christopher}
163cee313d2SEric Christopher
164cee313d2SEric Christopher; /// Pointer access, positive stride, run-time check added
165cee313d2SEric Christopher; int noAlias04 (int a) {
166cee313d2SEric Christopher;   int i;
167cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
168cee313d2SEric Christopher;     *(PA+i) = *(PB+i) + a;
169cee313d2SEric Christopher;   return *(PA+a);
170cee313d2SEric Christopher; }
171cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias04(
172cee313d2SEric Christopher; CHECK-NOT: add nsw <4 x i32>
173cee313d2SEric Christopher; CHECK: ret
174cee313d2SEric Christopher;
175cee313d2SEric Christopher; TODO: This test vectorizes (with run-time check) on real targets with -O3)
176cee313d2SEric Christopher; Check why it's not being vectorized even when forcing vectorization
177cee313d2SEric Christopher
178cee313d2SEric Christopherdefine i32 @noAlias04(i32 %a) #0 {
179cee313d2SEric Christopherentry:
180cee313d2SEric Christopher  %a.addr = alloca i32, align 4
181cee313d2SEric Christopher  %i = alloca i32, align 4
182cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
183cee313d2SEric Christopher  store i32 0, i32* %i, align 4
184cee313d2SEric Christopher  br label %for.cond
185cee313d2SEric Christopher
186cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
187cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
188cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
189cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
190cee313d2SEric Christopher
191cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
192cee313d2SEric Christopher  %1 = load i32*, i32** @PB, align 4
193cee313d2SEric Christopher  %2 = load i32, i32* %i, align 4
194cee313d2SEric Christopher  %add.ptr = getelementptr inbounds i32, i32* %1, i32 %2
195cee313d2SEric Christopher  %3 = load i32, i32* %add.ptr, align 4
196cee313d2SEric Christopher  %4 = load i32, i32* %a.addr, align 4
197cee313d2SEric Christopher  %add = add nsw i32 %3, %4
198cee313d2SEric Christopher  %5 = load i32*, i32** @PA, align 4
199cee313d2SEric Christopher  %6 = load i32, i32* %i, align 4
200cee313d2SEric Christopher  %add.ptr1 = getelementptr inbounds i32, i32* %5, i32 %6
201cee313d2SEric Christopher  store i32 %add, i32* %add.ptr1, align 4
202cee313d2SEric Christopher  br label %for.inc
203cee313d2SEric Christopher
204cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
205cee313d2SEric Christopher  %7 = load i32, i32* %i, align 4
206cee313d2SEric Christopher  %inc = add nsw i32 %7, 1
207cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
208cee313d2SEric Christopher  br label %for.cond
209cee313d2SEric Christopher
210cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
211cee313d2SEric Christopher  %8 = load i32*, i32** @PA, align 4
212cee313d2SEric Christopher  %9 = load i32, i32* %a.addr, align 4
213cee313d2SEric Christopher  %add.ptr2 = getelementptr inbounds i32, i32* %8, i32 %9
214cee313d2SEric Christopher  %10 = load i32, i32* %add.ptr2, align 4
215cee313d2SEric Christopher  ret i32 %10
216cee313d2SEric Christopher}
217cee313d2SEric Christopher
218cee313d2SEric Christopher; /// Different objects, positive induction, multi-array
219cee313d2SEric Christopher; int noAlias05 (int a) {
220cee313d2SEric Christopher;   int i, N=10;
221cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
222cee313d2SEric Christopher;     Bar.A[N][i] = Bar.B[N][i] + a;
223cee313d2SEric Christopher;   return Bar.A[N][a];
224cee313d2SEric Christopher; }
225cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias05(
226cee313d2SEric Christopher; CHECK: add nsw <4 x i32>
227cee313d2SEric Christopher; CHECK: ret
228cee313d2SEric Christopher
229cee313d2SEric Christopherdefine i32 @noAlias05(i32 %a) #0 {
230cee313d2SEric Christopherentry:
231cee313d2SEric Christopher  %a.addr = alloca i32, align 4
232cee313d2SEric Christopher  %i = alloca i32, align 4
233cee313d2SEric Christopher  %N = alloca i32, align 4
234cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
235cee313d2SEric Christopher  store i32 10, i32* %N, align 4
236cee313d2SEric Christopher  store i32 0, i32* %i, align 4
237cee313d2SEric Christopher  br label %for.cond
238cee313d2SEric Christopher
239cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
240cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
241cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
242cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
243cee313d2SEric Christopher
244cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
245cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
246cee313d2SEric Christopher  %2 = load i32, i32* %N, align 4
247cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* getelementptr inbounds (%struct.anon.0, %struct.anon.0* @Bar, i32 0, i32 2), i32 0, i32 %2
248cee313d2SEric Christopher  %arrayidx1 = getelementptr inbounds [100 x i32], [100 x i32]* %arrayidx, i32 0, i32 %1
249cee313d2SEric Christopher  %3 = load i32, i32* %arrayidx1, align 4
250cee313d2SEric Christopher  %4 = load i32, i32* %a.addr, align 4
251cee313d2SEric Christopher  %add = add nsw i32 %3, %4
252cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
253cee313d2SEric Christopher  %6 = load i32, i32* %N, align 4
254cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* getelementptr inbounds (%struct.anon.0, %struct.anon.0* @Bar, i32 0, i32 0), i32 0, i32 %6
255cee313d2SEric Christopher  %arrayidx3 = getelementptr inbounds [100 x i32], [100 x i32]* %arrayidx2, i32 0, i32 %5
256cee313d2SEric Christopher  store i32 %add, i32* %arrayidx3, align 4
257cee313d2SEric Christopher  br label %for.inc
258cee313d2SEric Christopher
259cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
260cee313d2SEric Christopher  %7 = load i32, i32* %i, align 4
261cee313d2SEric Christopher  %inc = add nsw i32 %7, 1
262cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
263cee313d2SEric Christopher  br label %for.cond
264cee313d2SEric Christopher
265cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
266cee313d2SEric Christopher  %8 = load i32, i32* %a.addr, align 4
267cee313d2SEric Christopher  %9 = load i32, i32* %N, align 4
268cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* getelementptr inbounds (%struct.anon.0, %struct.anon.0* @Bar, i32 0, i32 0), i32 0, i32 %9
269cee313d2SEric Christopher  %arrayidx5 = getelementptr inbounds [100 x i32], [100 x i32]* %arrayidx4, i32 0, i32 %8
270cee313d2SEric Christopher  %10 = load i32, i32* %arrayidx5, align 4
271cee313d2SEric Christopher  ret i32 %10
272cee313d2SEric Christopher}
273cee313d2SEric Christopher
274cee313d2SEric Christopher; /// Same objects, positive induction, multi-array, different sub-elements
275cee313d2SEric Christopher; int noAlias06 (int a) {
276cee313d2SEric Christopher;   int i, N=10;
277cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
278cee313d2SEric Christopher;     Bar.A[N][i] = Bar.A[N+1][i] + a;
279cee313d2SEric Christopher;   return Bar.A[N][a];
280cee313d2SEric Christopher; }
281cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias06(
282cee313d2SEric Christopher; CHECK: add nsw <4 x i32>
283cee313d2SEric Christopher; CHECK: ret
284cee313d2SEric Christopher
285cee313d2SEric Christopherdefine i32 @noAlias06(i32 %a) #0 {
286cee313d2SEric Christopherentry:
287cee313d2SEric Christopher  %a.addr = alloca i32, align 4
288cee313d2SEric Christopher  %i = alloca i32, align 4
289cee313d2SEric Christopher  %N = alloca i32, align 4
290cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
291cee313d2SEric Christopher  store i32 10, i32* %N, align 4
292cee313d2SEric Christopher  store i32 0, i32* %i, align 4
293cee313d2SEric Christopher  br label %for.cond
294cee313d2SEric Christopher
295cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
296cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
297cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
298cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
299cee313d2SEric Christopher
300cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
301cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
302cee313d2SEric Christopher  %2 = load i32, i32* %N, align 4
303cee313d2SEric Christopher  %add = add nsw i32 %2, 1
304cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* getelementptr inbounds (%struct.anon.0, %struct.anon.0* @Bar, i32 0, i32 0), i32 0, i32 %add
305cee313d2SEric Christopher  %arrayidx1 = getelementptr inbounds [100 x i32], [100 x i32]* %arrayidx, i32 0, i32 %1
306cee313d2SEric Christopher  %3 = load i32, i32* %arrayidx1, align 4
307cee313d2SEric Christopher  %4 = load i32, i32* %a.addr, align 4
308cee313d2SEric Christopher  %add2 = add nsw i32 %3, %4
309cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
310cee313d2SEric Christopher  %6 = load i32, i32* %N, align 4
311cee313d2SEric Christopher  %arrayidx3 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* getelementptr inbounds (%struct.anon.0, %struct.anon.0* @Bar, i32 0, i32 0), i32 0, i32 %6
312cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds [100 x i32], [100 x i32]* %arrayidx3, i32 0, i32 %5
313cee313d2SEric Christopher  store i32 %add2, i32* %arrayidx4, align 4
314cee313d2SEric Christopher  br label %for.inc
315cee313d2SEric Christopher
316cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
317cee313d2SEric Christopher  %7 = load i32, i32* %i, align 4
318cee313d2SEric Christopher  %inc = add nsw i32 %7, 1
319cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
320cee313d2SEric Christopher  br label %for.cond
321cee313d2SEric Christopher
322cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
323cee313d2SEric Christopher  %8 = load i32, i32* %a.addr, align 4
324cee313d2SEric Christopher  %9 = load i32, i32* %N, align 4
325cee313d2SEric Christopher  %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* getelementptr inbounds (%struct.anon.0, %struct.anon.0* @Bar, i32 0, i32 0), i32 0, i32 %9
326cee313d2SEric Christopher  %arrayidx6 = getelementptr inbounds [100 x i32], [100 x i32]* %arrayidx5, i32 0, i32 %8
327cee313d2SEric Christopher  %10 = load i32, i32* %arrayidx6, align 4
328cee313d2SEric Christopher  ret i32 %10
329cee313d2SEric Christopher}
330cee313d2SEric Christopher
331cee313d2SEric Christopher; /// Different objects, negative induction, constant distance
332cee313d2SEric Christopher; int noAlias07 (int a) {
333cee313d2SEric Christopher;   int i;
334cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
335cee313d2SEric Christopher;     Foo.A[SIZE-i-1] = Foo.B[SIZE-i-1] + a;
336cee313d2SEric Christopher;   return Foo.A[a];
337cee313d2SEric Christopher; }
338cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias07(
339cee313d2SEric Christopher; CHECK: store <4 x i32>
340cee313d2SEric Christopher; CHECK: ret
341cee313d2SEric Christopherdefine i32 @noAlias07(i32 %a) #0 {
342cee313d2SEric Christopherentry:
343cee313d2SEric Christopher  %a.addr = alloca i32, align 4
344cee313d2SEric Christopher  %i = alloca i32, align 4
345cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
346cee313d2SEric Christopher  store i32 0, i32* %i, align 4
347cee313d2SEric Christopher  br label %for.cond
348cee313d2SEric Christopher
349cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
350cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
351cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
352cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
353cee313d2SEric Christopher
354cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
355cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
356cee313d2SEric Christopher  %sub = sub nsw i32 100, %1
357cee313d2SEric Christopher  %sub1 = sub nsw i32 %sub, 1
358cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 2), i32 0, i32 %sub1
359cee313d2SEric Christopher  %2 = load i32, i32* %arrayidx, align 4
360cee313d2SEric Christopher  %3 = load i32, i32* %a.addr, align 4
361cee313d2SEric Christopher  %add = add nsw i32 %2, %3
362cee313d2SEric Christopher  %4 = load i32, i32* %i, align 4
363cee313d2SEric Christopher  %sub2 = sub nsw i32 100, %4
364cee313d2SEric Christopher  %sub3 = sub nsw i32 %sub2, 1
365cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %sub3
366cee313d2SEric Christopher  store i32 %add, i32* %arrayidx4, align 4
367cee313d2SEric Christopher  br label %for.inc
368cee313d2SEric Christopher
369cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
370cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
371cee313d2SEric Christopher  %inc = add nsw i32 %5, 1
372cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
373cee313d2SEric Christopher  br label %for.cond
374cee313d2SEric Christopher
375cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
376cee313d2SEric Christopher  %6 = load i32, i32* %a.addr, align 4
377cee313d2SEric Christopher  %arrayidx5 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %6
378cee313d2SEric Christopher  %7 = load i32, i32* %arrayidx5, align 4
379cee313d2SEric Christopher  ret i32 %7
380cee313d2SEric Christopher}
381cee313d2SEric Christopher
382cee313d2SEric Christopher; /// Different objects, negative induction, shortening slide
383cee313d2SEric Christopher; int noAlias08 (int a) {
384cee313d2SEric Christopher;   int i;
385cee313d2SEric Christopher;   for (i=0; i<SIZE-10; i++)
386cee313d2SEric Christopher;     Foo.A[SIZE-i-1] = Foo.B[SIZE-i-10] + a;
387cee313d2SEric Christopher;   return Foo.A[a];
388cee313d2SEric Christopher; }
389cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias08(
390cee313d2SEric Christopher; CHECK: load <4 x i32>
391cee313d2SEric Christopher; CHECK: ret
392cee313d2SEric Christopher
393cee313d2SEric Christopherdefine i32 @noAlias08(i32 %a) #0 {
394cee313d2SEric Christopherentry:
395cee313d2SEric Christopher  %a.addr = alloca i32, align 4
396cee313d2SEric Christopher  %i = alloca i32, align 4
397cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
398cee313d2SEric Christopher  store i32 0, i32* %i, align 4
399cee313d2SEric Christopher  br label %for.cond
400cee313d2SEric Christopher
401cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
402cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
403cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 90
404cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
405cee313d2SEric Christopher
406cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
407cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
408cee313d2SEric Christopher  %sub = sub nsw i32 100, %1
409cee313d2SEric Christopher  %sub1 = sub nsw i32 %sub, 10
410cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 2), i32 0, i32 %sub1
411cee313d2SEric Christopher  %2 = load i32, i32* %arrayidx, align 4
412cee313d2SEric Christopher  %3 = load i32, i32* %a.addr, align 4
413cee313d2SEric Christopher  %add = add nsw i32 %2, %3
414cee313d2SEric Christopher  %4 = load i32, i32* %i, align 4
415cee313d2SEric Christopher  %sub2 = sub nsw i32 100, %4
416cee313d2SEric Christopher  %sub3 = sub nsw i32 %sub2, 1
417cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %sub3
418cee313d2SEric Christopher  store i32 %add, i32* %arrayidx4, align 4
419cee313d2SEric Christopher  br label %for.inc
420cee313d2SEric Christopher
421cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
422cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
423cee313d2SEric Christopher  %inc = add nsw i32 %5, 1
424cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
425cee313d2SEric Christopher  br label %for.cond
426cee313d2SEric Christopher
427cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
428cee313d2SEric Christopher  %6 = load i32, i32* %a.addr, align 4
429cee313d2SEric Christopher  %arrayidx5 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %6
430cee313d2SEric Christopher  %7 = load i32, i32* %arrayidx5, align 4
431cee313d2SEric Christopher  ret i32 %7
432cee313d2SEric Christopher}
433cee313d2SEric Christopher
434cee313d2SEric Christopher; /// Different objects, negative induction, widening slide
435cee313d2SEric Christopher; int noAlias09 (int a) {
436cee313d2SEric Christopher;   int i;
437cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
438cee313d2SEric Christopher;     Foo.A[SIZE-i-10] = Foo.B[SIZE-i-1] + a;
439cee313d2SEric Christopher;   return Foo.A[a];
440cee313d2SEric Christopher; }
441cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias09(
442cee313d2SEric Christopher; CHECK: load <4 x i32>
443cee313d2SEric Christopher; CHECK: ret
444cee313d2SEric Christopher
445cee313d2SEric Christopherdefine i32 @noAlias09(i32 %a) #0 {
446cee313d2SEric Christopherentry:
447cee313d2SEric Christopher  %a.addr = alloca i32, align 4
448cee313d2SEric Christopher  %i = alloca i32, align 4
449cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
450cee313d2SEric Christopher  store i32 0, i32* %i, align 4
451cee313d2SEric Christopher  br label %for.cond
452cee313d2SEric Christopher
453cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
454cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
455cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
456cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
457cee313d2SEric Christopher
458cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
459cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
460cee313d2SEric Christopher  %sub = sub nsw i32 100, %1
461cee313d2SEric Christopher  %sub1 = sub nsw i32 %sub, 1
462cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 2), i32 0, i32 %sub1
463cee313d2SEric Christopher  %2 = load i32, i32* %arrayidx, align 4
464cee313d2SEric Christopher  %3 = load i32, i32* %a.addr, align 4
465cee313d2SEric Christopher  %add = add nsw i32 %2, %3
466cee313d2SEric Christopher  %4 = load i32, i32* %i, align 4
467cee313d2SEric Christopher  %sub2 = sub nsw i32 100, %4
468cee313d2SEric Christopher  %sub3 = sub nsw i32 %sub2, 10
469cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %sub3
470cee313d2SEric Christopher  store i32 %add, i32* %arrayidx4, align 4
471cee313d2SEric Christopher  br label %for.inc
472cee313d2SEric Christopher
473cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
474cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
475cee313d2SEric Christopher  %inc = add nsw i32 %5, 1
476cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
477cee313d2SEric Christopher  br label %for.cond
478cee313d2SEric Christopher
479cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
480cee313d2SEric Christopher  %6 = load i32, i32* %a.addr, align 4
481cee313d2SEric Christopher  %arrayidx5 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %6
482cee313d2SEric Christopher  %7 = load i32, i32* %arrayidx5, align 4
483cee313d2SEric Christopher  ret i32 %7
484cee313d2SEric Christopher}
485cee313d2SEric Christopher
486cee313d2SEric Christopher; /// Pointer access, negative stride, run-time check added
487cee313d2SEric Christopher; int noAlias10 (int a) {
488cee313d2SEric Christopher;   int i;
489cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
490cee313d2SEric Christopher;     *(PA+SIZE-i-1) = *(PB+SIZE-i-1) + a;
491cee313d2SEric Christopher;   return *(PA+a);
492cee313d2SEric Christopher; }
493cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias10(
494cee313d2SEric Christopher; CHECK-NOT: sub {{.*}} <4 x i32>
495cee313d2SEric Christopher; CHECK: ret
496cee313d2SEric Christopher;
497cee313d2SEric Christopher; TODO: This test vectorizes (with run-time check) on real targets with -O3)
498cee313d2SEric Christopher; Check why it's not being vectorized even when forcing vectorization
499cee313d2SEric Christopher
500cee313d2SEric Christopherdefine i32 @noAlias10(i32 %a) #0 {
501cee313d2SEric Christopherentry:
502cee313d2SEric Christopher  %a.addr = alloca i32, align 4
503cee313d2SEric Christopher  %i = alloca i32, align 4
504cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
505cee313d2SEric Christopher  store i32 0, i32* %i, align 4
506cee313d2SEric Christopher  br label %for.cond
507cee313d2SEric Christopher
508cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
509cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
510cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
511cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
512cee313d2SEric Christopher
513cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
514cee313d2SEric Christopher  %1 = load i32*, i32** @PB, align 4
515cee313d2SEric Christopher  %add.ptr = getelementptr inbounds i32, i32* %1, i32 100
516cee313d2SEric Christopher  %2 = load i32, i32* %i, align 4
517cee313d2SEric Christopher  %idx.neg = sub i32 0, %2
518cee313d2SEric Christopher  %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 %idx.neg
519cee313d2SEric Christopher  %add.ptr2 = getelementptr inbounds i32, i32* %add.ptr1, i32 -1
520cee313d2SEric Christopher  %3 = load i32, i32* %add.ptr2, align 4
521cee313d2SEric Christopher  %4 = load i32, i32* %a.addr, align 4
522cee313d2SEric Christopher  %add = add nsw i32 %3, %4
523cee313d2SEric Christopher  %5 = load i32*, i32** @PA, align 4
524cee313d2SEric Christopher  %add.ptr3 = getelementptr inbounds i32, i32* %5, i32 100
525cee313d2SEric Christopher  %6 = load i32, i32* %i, align 4
526cee313d2SEric Christopher  %idx.neg4 = sub i32 0, %6
527cee313d2SEric Christopher  %add.ptr5 = getelementptr inbounds i32, i32* %add.ptr3, i32 %idx.neg4
528cee313d2SEric Christopher  %add.ptr6 = getelementptr inbounds i32, i32* %add.ptr5, i32 -1
529cee313d2SEric Christopher  store i32 %add, i32* %add.ptr6, align 4
530cee313d2SEric Christopher  br label %for.inc
531cee313d2SEric Christopher
532cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
533cee313d2SEric Christopher  %7 = load i32, i32* %i, align 4
534cee313d2SEric Christopher  %inc = add nsw i32 %7, 1
535cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
536cee313d2SEric Christopher  br label %for.cond
537cee313d2SEric Christopher
538cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
539cee313d2SEric Christopher  %8 = load i32*, i32** @PA, align 4
540cee313d2SEric Christopher  %9 = load i32, i32* %a.addr, align 4
541cee313d2SEric Christopher  %add.ptr7 = getelementptr inbounds i32, i32* %8, i32 %9
542cee313d2SEric Christopher  %10 = load i32, i32* %add.ptr7, align 4
543cee313d2SEric Christopher  ret i32 %10
544cee313d2SEric Christopher}
545cee313d2SEric Christopher
546cee313d2SEric Christopher; /// Different objects, negative induction, multi-array
547cee313d2SEric Christopher; int noAlias11 (int a) {
548cee313d2SEric Christopher;   int i, N=10;
549cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
550cee313d2SEric Christopher;     Bar.A[N][SIZE-i-1] = Bar.B[N][SIZE-i-1] + a;
551cee313d2SEric Christopher;   return Bar.A[N][a];
552cee313d2SEric Christopher; }
553cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias11(
554cee313d2SEric Christopher; CHECK: store <4 x i32>
555cee313d2SEric Christopher; CHECK: ret
556cee313d2SEric Christopher
557cee313d2SEric Christopherdefine i32 @noAlias11(i32 %a) #0 {
558cee313d2SEric Christopherentry:
559cee313d2SEric Christopher  %a.addr = alloca i32, align 4
560cee313d2SEric Christopher  %i = alloca i32, align 4
561cee313d2SEric Christopher  %N = alloca i32, align 4
562cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
563cee313d2SEric Christopher  store i32 10, i32* %N, align 4
564cee313d2SEric Christopher  store i32 0, i32* %i, align 4
565cee313d2SEric Christopher  br label %for.cond
566cee313d2SEric Christopher
567cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
568cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
569cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
570cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
571cee313d2SEric Christopher
572cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
573cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
574cee313d2SEric Christopher  %sub = sub nsw i32 100, %1
575cee313d2SEric Christopher  %sub1 = sub nsw i32 %sub, 1
576cee313d2SEric Christopher  %2 = load i32, i32* %N, align 4
577cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* getelementptr inbounds (%struct.anon.0, %struct.anon.0* @Bar, i32 0, i32 2), i32 0, i32 %2
578cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds [100 x i32], [100 x i32]* %arrayidx, i32 0, i32 %sub1
579cee313d2SEric Christopher  %3 = load i32, i32* %arrayidx2, align 4
580cee313d2SEric Christopher  %4 = load i32, i32* %a.addr, align 4
581cee313d2SEric Christopher  %add = add nsw i32 %3, %4
582cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
583cee313d2SEric Christopher  %sub3 = sub nsw i32 100, %5
584cee313d2SEric Christopher  %sub4 = sub nsw i32 %sub3, 1
585cee313d2SEric Christopher  %6 = load i32, i32* %N, align 4
586cee313d2SEric Christopher  %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* getelementptr inbounds (%struct.anon.0, %struct.anon.0* @Bar, i32 0, i32 0), i32 0, i32 %6
587cee313d2SEric Christopher  %arrayidx6 = getelementptr inbounds [100 x i32], [100 x i32]* %arrayidx5, i32 0, i32 %sub4
588cee313d2SEric Christopher  store i32 %add, i32* %arrayidx6, align 4
589cee313d2SEric Christopher  br label %for.inc
590cee313d2SEric Christopher
591cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
592cee313d2SEric Christopher  %7 = load i32, i32* %i, align 4
593cee313d2SEric Christopher  %inc = add nsw i32 %7, 1
594cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
595cee313d2SEric Christopher  br label %for.cond
596cee313d2SEric Christopher
597cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
598cee313d2SEric Christopher  %8 = load i32, i32* %a.addr, align 4
599cee313d2SEric Christopher  %9 = load i32, i32* %N, align 4
600cee313d2SEric Christopher  %arrayidx7 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* getelementptr inbounds (%struct.anon.0, %struct.anon.0* @Bar, i32 0, i32 0), i32 0, i32 %9
601cee313d2SEric Christopher  %arrayidx8 = getelementptr inbounds [100 x i32], [100 x i32]* %arrayidx7, i32 0, i32 %8
602cee313d2SEric Christopher  %10 = load i32, i32* %arrayidx8, align 4
603cee313d2SEric Christopher  ret i32 %10
604cee313d2SEric Christopher}
605cee313d2SEric Christopher
606cee313d2SEric Christopher; /// Same objects, negative induction, multi-array, different sub-elements
607cee313d2SEric Christopher; int noAlias12 (int a) {
608cee313d2SEric Christopher;   int i, N=10;
609cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
610cee313d2SEric Christopher;     Bar.A[N][SIZE-i-1] = Bar.A[N+1][SIZE-i-1] + a;
611cee313d2SEric Christopher;   return Bar.A[N][a];
612cee313d2SEric Christopher; }
613cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias12(
614cee313d2SEric Christopher; CHECK: store <4 x i32>
615cee313d2SEric Christopher; CHECK: ret
616cee313d2SEric Christopher
617cee313d2SEric Christopherdefine i32 @noAlias12(i32 %a) #0 {
618cee313d2SEric Christopherentry:
619cee313d2SEric Christopher  %a.addr = alloca i32, align 4
620cee313d2SEric Christopher  %i = alloca i32, align 4
621cee313d2SEric Christopher  %N = alloca i32, align 4
622cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
623cee313d2SEric Christopher  store i32 10, i32* %N, align 4
624cee313d2SEric Christopher  store i32 0, i32* %i, align 4
625cee313d2SEric Christopher  br label %for.cond
626cee313d2SEric Christopher
627cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
628cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
629cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
630cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
631cee313d2SEric Christopher
632cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
633cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
634cee313d2SEric Christopher  %sub = sub nsw i32 100, %1
635cee313d2SEric Christopher  %sub1 = sub nsw i32 %sub, 1
636cee313d2SEric Christopher  %2 = load i32, i32* %N, align 4
637cee313d2SEric Christopher  %add = add nsw i32 %2, 1
638cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* getelementptr inbounds (%struct.anon.0, %struct.anon.0* @Bar, i32 0, i32 0), i32 0, i32 %add
639cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds [100 x i32], [100 x i32]* %arrayidx, i32 0, i32 %sub1
640cee313d2SEric Christopher  %3 = load i32, i32* %arrayidx2, align 4
641cee313d2SEric Christopher  %4 = load i32, i32* %a.addr, align 4
642cee313d2SEric Christopher  %add3 = add nsw i32 %3, %4
643cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
644cee313d2SEric Christopher  %sub4 = sub nsw i32 100, %5
645cee313d2SEric Christopher  %sub5 = sub nsw i32 %sub4, 1
646cee313d2SEric Christopher  %6 = load i32, i32* %N, align 4
647cee313d2SEric Christopher  %arrayidx6 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* getelementptr inbounds (%struct.anon.0, %struct.anon.0* @Bar, i32 0, i32 0), i32 0, i32 %6
648cee313d2SEric Christopher  %arrayidx7 = getelementptr inbounds [100 x i32], [100 x i32]* %arrayidx6, i32 0, i32 %sub5
649cee313d2SEric Christopher  store i32 %add3, i32* %arrayidx7, align 4
650cee313d2SEric Christopher  br label %for.inc
651cee313d2SEric Christopher
652cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
653cee313d2SEric Christopher  %7 = load i32, i32* %i, align 4
654cee313d2SEric Christopher  %inc = add nsw i32 %7, 1
655cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
656cee313d2SEric Christopher  br label %for.cond
657cee313d2SEric Christopher
658cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
659cee313d2SEric Christopher  %8 = load i32, i32* %a.addr, align 4
660cee313d2SEric Christopher  %9 = load i32, i32* %N, align 4
661cee313d2SEric Christopher  %arrayidx8 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* getelementptr inbounds (%struct.anon.0, %struct.anon.0* @Bar, i32 0, i32 0), i32 0, i32 %9
662cee313d2SEric Christopher  %arrayidx9 = getelementptr inbounds [100 x i32], [100 x i32]* %arrayidx8, i32 0, i32 %8
663cee313d2SEric Christopher  %10 = load i32, i32* %arrayidx9, align 4
664cee313d2SEric Christopher  ret i32 %10
665cee313d2SEric Christopher}
666cee313d2SEric Christopher
667cee313d2SEric Christopher; /// Same objects, positive induction, constant distance, just enough for vector size
668cee313d2SEric Christopher; int noAlias13 (int a) {
669cee313d2SEric Christopher;   int i;
670cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
671cee313d2SEric Christopher;     Foo.A[i] = Foo.A[i+4] + a;
672cee313d2SEric Christopher;   return Foo.A[a];
673cee313d2SEric Christopher; }
674cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias13(
675cee313d2SEric Christopher; CHECK: add nsw <4 x i32>
676cee313d2SEric Christopher; CHECK: ret
677cee313d2SEric Christopher
678cee313d2SEric Christopherdefine i32 @noAlias13(i32 %a) #0 {
679cee313d2SEric Christopherentry:
680cee313d2SEric Christopher  %a.addr = alloca i32, align 4
681cee313d2SEric Christopher  %i = alloca i32, align 4
682cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
683cee313d2SEric Christopher  store i32 0, i32* %i, align 4
684cee313d2SEric Christopher  br label %for.cond
685cee313d2SEric Christopher
686cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
687cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
688cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
689cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
690cee313d2SEric Christopher
691cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
692cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
693cee313d2SEric Christopher  %add = add nsw i32 %1, 4
694cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %add
695cee313d2SEric Christopher  %2 = load i32, i32* %arrayidx, align 4
696cee313d2SEric Christopher  %3 = load i32, i32* %a.addr, align 4
697cee313d2SEric Christopher  %add1 = add nsw i32 %2, %3
698cee313d2SEric Christopher  %4 = load i32, i32* %i, align 4
699cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %4
700cee313d2SEric Christopher  store i32 %add1, i32* %arrayidx2, align 4
701cee313d2SEric Christopher  br label %for.inc
702cee313d2SEric Christopher
703cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
704cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
705cee313d2SEric Christopher  %inc = add nsw i32 %5, 1
706cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
707cee313d2SEric Christopher  br label %for.cond
708cee313d2SEric Christopher
709cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
710cee313d2SEric Christopher  %6 = load i32, i32* %a.addr, align 4
711cee313d2SEric Christopher  %arrayidx3 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %6
712cee313d2SEric Christopher  %7 = load i32, i32* %arrayidx3, align 4
713cee313d2SEric Christopher  ret i32 %7
714cee313d2SEric Christopher}
715cee313d2SEric Christopher
716cee313d2SEric Christopher; /// Same objects, negative induction, constant distance, just enough for vector size
717cee313d2SEric Christopher; int noAlias14 (int a) {
718cee313d2SEric Christopher;   int i;
719cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
720cee313d2SEric Christopher;     Foo.A[SIZE-i-1] = Foo.A[SIZE-i-5] + a;
721cee313d2SEric Christopher;   return Foo.A[a];
722cee313d2SEric Christopher; }
723cee313d2SEric Christopher; CHECK-LABEL: define i32 @noAlias14(
724cee313d2SEric Christopher; CHECK: load <4 x i32>
725cee313d2SEric Christopher; CHECK: ret
726cee313d2SEric Christopher
727cee313d2SEric Christopherdefine i32 @noAlias14(i32 %a) #0 {
728cee313d2SEric Christopherentry:
729cee313d2SEric Christopher  %a.addr = alloca i32, align 4
730cee313d2SEric Christopher  %i = alloca i32, align 4
731cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
732cee313d2SEric Christopher  store i32 0, i32* %i, align 4
733cee313d2SEric Christopher  br label %for.cond
734cee313d2SEric Christopher
735cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
736cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
737cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
738cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
739cee313d2SEric Christopher
740cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
741cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
742cee313d2SEric Christopher  %sub = sub nsw i32 100, %1
743cee313d2SEric Christopher  %sub1 = sub nsw i32 %sub, 5
744cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %sub1
745cee313d2SEric Christopher  %2 = load i32, i32* %arrayidx, align 4
746cee313d2SEric Christopher  %3 = load i32, i32* %a.addr, align 4
747cee313d2SEric Christopher  %add = add nsw i32 %2, %3
748cee313d2SEric Christopher  %4 = load i32, i32* %i, align 4
749cee313d2SEric Christopher  %sub2 = sub nsw i32 100, %4
750cee313d2SEric Christopher  %sub3 = sub nsw i32 %sub2, 1
751cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %sub3
752cee313d2SEric Christopher  store i32 %add, i32* %arrayidx4, align 4
753cee313d2SEric Christopher  br label %for.inc
754cee313d2SEric Christopher
755cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
756cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
757cee313d2SEric Christopher  %inc = add nsw i32 %5, 1
758cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
759cee313d2SEric Christopher  br label %for.cond
760cee313d2SEric Christopher
761cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
762cee313d2SEric Christopher  %6 = load i32, i32* %a.addr, align 4
763cee313d2SEric Christopher  %arrayidx5 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %6
764cee313d2SEric Christopher  %7 = load i32, i32* %arrayidx5, align 4
765cee313d2SEric Christopher  ret i32 %7
766cee313d2SEric Christopher}
767cee313d2SEric Christopher
768cee313d2SEric Christopher
769cee313d2SEric Christopher;; === Now, the tests that we could vectorize with induction changes or run-time checks ===
770cee313d2SEric Christopher
771cee313d2SEric Christopher
772cee313d2SEric Christopher; /// Different objects, swapped induction, alias at the end
773cee313d2SEric Christopher; int mayAlias01 (int a) {
774cee313d2SEric Christopher;   int i;
775cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
776cee313d2SEric Christopher;     Foo.A[i] = Foo.B[SIZE-i-1] + a;
777cee313d2SEric Christopher;   return Foo.A[a];
778cee313d2SEric Christopher; }
779cee313d2SEric Christopher; CHECK-LABEL: define i32 @mayAlias01(
780cee313d2SEric Christopher; CHECK-NOT: add nsw <4 x i32>
781cee313d2SEric Christopher; CHECK: ret
782cee313d2SEric Christopher
783cee313d2SEric Christopherdefine i32 @mayAlias01(i32 %a) nounwind {
784cee313d2SEric Christopherentry:
785cee313d2SEric Christopher  %a.addr = alloca i32, align 4
786cee313d2SEric Christopher  %i = alloca i32, align 4
787cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
788cee313d2SEric Christopher  store i32 0, i32* %i, align 4
789cee313d2SEric Christopher  br label %for.cond
790cee313d2SEric Christopher
791cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
792cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
793cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
794cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
795cee313d2SEric Christopher
796cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
797cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
798cee313d2SEric Christopher  %sub = sub nsw i32 100, %1
799cee313d2SEric Christopher  %sub1 = sub nsw i32 %sub, 1
800cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 2), i32 0, i32 %sub1
801cee313d2SEric Christopher  %2 = load i32, i32* %arrayidx, align 4
802cee313d2SEric Christopher  %3 = load i32, i32* %a.addr, align 4
803cee313d2SEric Christopher  %add = add nsw i32 %2, %3
804cee313d2SEric Christopher  %4 = load i32, i32* %i, align 4
805cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %4
806cee313d2SEric Christopher  store i32 %add, i32* %arrayidx2, align 4
807cee313d2SEric Christopher  br label %for.inc
808cee313d2SEric Christopher
809cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
810cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
811cee313d2SEric Christopher  %inc = add nsw i32 %5, 1
812cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
813cee313d2SEric Christopher  br label %for.cond
814cee313d2SEric Christopher
815cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
816cee313d2SEric Christopher  %6 = load i32, i32* %a.addr, align 4
817cee313d2SEric Christopher  %arrayidx3 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %6
818cee313d2SEric Christopher  %7 = load i32, i32* %arrayidx3, align 4
819cee313d2SEric Christopher  ret i32 %7
820cee313d2SEric Christopher}
821cee313d2SEric Christopher
822cee313d2SEric Christopher; /// Different objects, swapped induction, alias at the beginning
823cee313d2SEric Christopher; int mayAlias02 (int a) {
824cee313d2SEric Christopher;   int i;
825cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
826cee313d2SEric Christopher;     Foo.A[SIZE-i-1] = Foo.B[i] + a;
827cee313d2SEric Christopher;   return Foo.A[a];
828cee313d2SEric Christopher; }
829cee313d2SEric Christopher; CHECK-LABEL: define i32 @mayAlias02(
830cee313d2SEric Christopher; CHECK-NOT: add nsw <4 x i32>
831cee313d2SEric Christopher; CHECK: ret
832cee313d2SEric Christopher
833cee313d2SEric Christopherdefine i32 @mayAlias02(i32 %a) nounwind {
834cee313d2SEric Christopherentry:
835cee313d2SEric Christopher  %a.addr = alloca i32, align 4
836cee313d2SEric Christopher  %i = alloca i32, align 4
837cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
838cee313d2SEric Christopher  store i32 0, i32* %i, align 4
839cee313d2SEric Christopher  br label %for.cond
840cee313d2SEric Christopher
841cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
842cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
843cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
844cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
845cee313d2SEric Christopher
846cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
847cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
848cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 2), i32 0, i32 %1
849cee313d2SEric Christopher  %2 = load i32, i32* %arrayidx, align 4
850cee313d2SEric Christopher  %3 = load i32, i32* %a.addr, align 4
851cee313d2SEric Christopher  %add = add nsw i32 %2, %3
852cee313d2SEric Christopher  %4 = load i32, i32* %i, align 4
853cee313d2SEric Christopher  %sub = sub nsw i32 100, %4
854cee313d2SEric Christopher  %sub1 = sub nsw i32 %sub, 1
855cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %sub1
856cee313d2SEric Christopher  store i32 %add, i32* %arrayidx2, align 4
857cee313d2SEric Christopher  br label %for.inc
858cee313d2SEric Christopher
859cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
860cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
861cee313d2SEric Christopher  %inc = add nsw i32 %5, 1
862cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
863cee313d2SEric Christopher  br label %for.cond
864cee313d2SEric Christopher
865cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
866cee313d2SEric Christopher  %6 = load i32, i32* %a.addr, align 4
867cee313d2SEric Christopher  %arrayidx3 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %6
868cee313d2SEric Christopher  %7 = load i32, i32* %arrayidx3, align 4
869cee313d2SEric Christopher  ret i32 %7
870cee313d2SEric Christopher}
871cee313d2SEric Christopher
872cee313d2SEric Christopher; /// Pointer access, run-time check added
873cee313d2SEric Christopher; int mayAlias03 (int a) {
874cee313d2SEric Christopher;   int i;
875cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
876cee313d2SEric Christopher;     *(PA+i) = *(PB+SIZE-i-1) + a;
877cee313d2SEric Christopher;   return *(PA+a);
878cee313d2SEric Christopher; }
879cee313d2SEric Christopher; CHECK-LABEL: define i32 @mayAlias03(
880cee313d2SEric Christopher; CHECK-NOT: add nsw <4 x i32>
881cee313d2SEric Christopher; CHECK: ret
882cee313d2SEric Christopher
883cee313d2SEric Christopherdefine i32 @mayAlias03(i32 %a) nounwind {
884cee313d2SEric Christopherentry:
885cee313d2SEric Christopher  %a.addr = alloca i32, align 4
886cee313d2SEric Christopher  %i = alloca i32, align 4
887cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
888cee313d2SEric Christopher  store i32 0, i32* %i, align 4
889cee313d2SEric Christopher  br label %for.cond
890cee313d2SEric Christopher
891cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
892cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
893cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
894cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
895cee313d2SEric Christopher
896cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
897cee313d2SEric Christopher  %1 = load i32*, i32** @PB, align 4
898cee313d2SEric Christopher  %add.ptr = getelementptr inbounds i32, i32* %1, i32 100
899cee313d2SEric Christopher  %2 = load i32, i32* %i, align 4
900cee313d2SEric Christopher  %idx.neg = sub i32 0, %2
901cee313d2SEric Christopher  %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 %idx.neg
902cee313d2SEric Christopher  %add.ptr2 = getelementptr inbounds i32, i32* %add.ptr1, i32 -1
903cee313d2SEric Christopher  %3 = load i32, i32* %add.ptr2, align 4
904cee313d2SEric Christopher  %4 = load i32, i32* %a.addr, align 4
905cee313d2SEric Christopher  %add = add nsw i32 %3, %4
906cee313d2SEric Christopher  %5 = load i32*, i32** @PA, align 4
907cee313d2SEric Christopher  %6 = load i32, i32* %i, align 4
908cee313d2SEric Christopher  %add.ptr3 = getelementptr inbounds i32, i32* %5, i32 %6
909cee313d2SEric Christopher  store i32 %add, i32* %add.ptr3, align 4
910cee313d2SEric Christopher  br label %for.inc
911cee313d2SEric Christopher
912cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
913cee313d2SEric Christopher  %7 = load i32, i32* %i, align 4
914cee313d2SEric Christopher  %inc = add nsw i32 %7, 1
915cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
916cee313d2SEric Christopher  br label %for.cond
917cee313d2SEric Christopher
918cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
919cee313d2SEric Christopher  %8 = load i32*, i32** @PA, align 4
920cee313d2SEric Christopher  %9 = load i32, i32* %a.addr, align 4
921cee313d2SEric Christopher  %add.ptr4 = getelementptr inbounds i32, i32* %8, i32 %9
922cee313d2SEric Christopher  %10 = load i32, i32* %add.ptr4, align 4
923cee313d2SEric Christopher  ret i32 %10
924cee313d2SEric Christopher}
925cee313d2SEric Christopher
926cee313d2SEric Christopher
927cee313d2SEric Christopher;; === Finally, the tests that should only vectorize with care (or if we ignore undefined behaviour at all) ===
928cee313d2SEric Christopher
929cee313d2SEric Christopher
930cee313d2SEric Christopher; int mustAlias01 (int a) {
931cee313d2SEric Christopher;   int i;
932cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
933cee313d2SEric Christopher;     Foo.A[i+10] = Foo.B[SIZE-i-1] + a;
934cee313d2SEric Christopher;   return Foo.A[a];
935cee313d2SEric Christopher; }
936cee313d2SEric Christopher; CHECK-LABEL: define i32 @mustAlias01(
937cee313d2SEric Christopher; CHECK-NOT: add nsw <4 x i32>
938cee313d2SEric Christopher; CHECK: ret
939cee313d2SEric Christopher
940cee313d2SEric Christopherdefine i32 @mustAlias01(i32 %a) nounwind {
941cee313d2SEric Christopherentry:
942cee313d2SEric Christopher  %a.addr = alloca i32, align 4
943cee313d2SEric Christopher  %i = alloca i32, align 4
944cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
945cee313d2SEric Christopher  store i32 0, i32* %i, align 4
946cee313d2SEric Christopher  br label %for.cond
947cee313d2SEric Christopher
948cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
949cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
950cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
951cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
952cee313d2SEric Christopher
953cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
954cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
955cee313d2SEric Christopher  %sub = sub nsw i32 100, %1
956cee313d2SEric Christopher  %sub1 = sub nsw i32 %sub, 1
957cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 2), i32 0, i32 %sub1
958cee313d2SEric Christopher  %2 = load i32, i32* %arrayidx, align 4
959cee313d2SEric Christopher  %3 = load i32, i32* %a.addr, align 4
960cee313d2SEric Christopher  %add = add nsw i32 %2, %3
961cee313d2SEric Christopher  %4 = load i32, i32* %i, align 4
962cee313d2SEric Christopher  %add2 = add nsw i32 %4, 10
963cee313d2SEric Christopher  %arrayidx3 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %add2
964cee313d2SEric Christopher  store i32 %add, i32* %arrayidx3, align 4
965cee313d2SEric Christopher  br label %for.inc
966cee313d2SEric Christopher
967cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
968cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
969cee313d2SEric Christopher  %inc = add nsw i32 %5, 1
970cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
971cee313d2SEric Christopher  br label %for.cond
972cee313d2SEric Christopher
973cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
974cee313d2SEric Christopher  %6 = load i32, i32* %a.addr, align 4
975cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %6
976cee313d2SEric Christopher  %7 = load i32, i32* %arrayidx4, align 4
977cee313d2SEric Christopher  ret i32 %7
978cee313d2SEric Christopher}
979cee313d2SEric Christopher
980cee313d2SEric Christopher; int mustAlias02 (int a) {
981cee313d2SEric Christopher;   int i;
982cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
983cee313d2SEric Christopher;     Foo.A[i] = Foo.B[SIZE-i-10] + a;
984cee313d2SEric Christopher;   return Foo.A[a];
985cee313d2SEric Christopher; }
986cee313d2SEric Christopher; CHECK-LABEL: define i32 @mustAlias02(
987cee313d2SEric Christopher; CHECK-NOT: add nsw <4 x i32>
988cee313d2SEric Christopher; CHECK: ret
989cee313d2SEric Christopher
990cee313d2SEric Christopherdefine i32 @mustAlias02(i32 %a) nounwind {
991cee313d2SEric Christopherentry:
992cee313d2SEric Christopher  %a.addr = alloca i32, align 4
993cee313d2SEric Christopher  %i = alloca i32, align 4
994cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
995cee313d2SEric Christopher  store i32 0, i32* %i, align 4
996cee313d2SEric Christopher  br label %for.cond
997cee313d2SEric Christopher
998cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
999cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
1000cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
1001cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
1002cee313d2SEric Christopher
1003cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
1004cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
1005cee313d2SEric Christopher  %sub = sub nsw i32 100, %1
1006cee313d2SEric Christopher  %sub1 = sub nsw i32 %sub, 10
1007cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 2), i32 0, i32 %sub1
1008cee313d2SEric Christopher  %2 = load i32, i32* %arrayidx, align 4
1009cee313d2SEric Christopher  %3 = load i32, i32* %a.addr, align 4
1010cee313d2SEric Christopher  %add = add nsw i32 %2, %3
1011cee313d2SEric Christopher  %4 = load i32, i32* %i, align 4
1012cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %4
1013cee313d2SEric Christopher  store i32 %add, i32* %arrayidx2, align 4
1014cee313d2SEric Christopher  br label %for.inc
1015cee313d2SEric Christopher
1016cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
1017cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
1018cee313d2SEric Christopher  %inc = add nsw i32 %5, 1
1019cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
1020cee313d2SEric Christopher  br label %for.cond
1021cee313d2SEric Christopher
1022cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
1023cee313d2SEric Christopher  %6 = load i32, i32* %a.addr, align 4
1024cee313d2SEric Christopher  %arrayidx3 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %6
1025cee313d2SEric Christopher  %7 = load i32, i32* %arrayidx3, align 4
1026cee313d2SEric Christopher  ret i32 %7
1027cee313d2SEric Christopher}
1028cee313d2SEric Christopher
1029cee313d2SEric Christopher; int mustAlias03 (int a) {
1030cee313d2SEric Christopher;   int i;
1031cee313d2SEric Christopher;   for (i=0; i<SIZE; i++)
1032cee313d2SEric Christopher;     Foo.A[i+10] = Foo.B[SIZE-i-10] + a;
1033cee313d2SEric Christopher;   return Foo.A[a];
1034cee313d2SEric Christopher; }
1035cee313d2SEric Christopher; CHECK-LABEL: define i32 @mustAlias03(
1036cee313d2SEric Christopher; CHECK-NOT: add nsw <4 x i32>
1037cee313d2SEric Christopher; CHECK: ret
1038cee313d2SEric Christopher
1039cee313d2SEric Christopherdefine i32 @mustAlias03(i32 %a) nounwind {
1040cee313d2SEric Christopherentry:
1041cee313d2SEric Christopher  %a.addr = alloca i32, align 4
1042cee313d2SEric Christopher  %i = alloca i32, align 4
1043cee313d2SEric Christopher  store i32 %a, i32* %a.addr, align 4
1044cee313d2SEric Christopher  store i32 0, i32* %i, align 4
1045cee313d2SEric Christopher  br label %for.cond
1046cee313d2SEric Christopher
1047cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
1048cee313d2SEric Christopher  %0 = load i32, i32* %i, align 4
1049cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 100
1050cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
1051cee313d2SEric Christopher
1052cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
1053cee313d2SEric Christopher  %1 = load i32, i32* %i, align 4
1054cee313d2SEric Christopher  %sub = sub nsw i32 100, %1
1055cee313d2SEric Christopher  %sub1 = sub nsw i32 %sub, 10
1056cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 2), i32 0, i32 %sub1
1057cee313d2SEric Christopher  %2 = load i32, i32* %arrayidx, align 4
1058cee313d2SEric Christopher  %3 = load i32, i32* %a.addr, align 4
1059cee313d2SEric Christopher  %add = add nsw i32 %2, %3
1060cee313d2SEric Christopher  %4 = load i32, i32* %i, align 4
1061cee313d2SEric Christopher  %add2 = add nsw i32 %4, 10
1062cee313d2SEric Christopher  %arrayidx3 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %add2
1063cee313d2SEric Christopher  store i32 %add, i32* %arrayidx3, align 4
1064cee313d2SEric Christopher  br label %for.inc
1065cee313d2SEric Christopher
1066cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
1067cee313d2SEric Christopher  %5 = load i32, i32* %i, align 4
1068cee313d2SEric Christopher  %inc = add nsw i32 %5, 1
1069cee313d2SEric Christopher  store i32 %inc, i32* %i, align 4
1070cee313d2SEric Christopher  br label %for.cond
1071cee313d2SEric Christopher
1072cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
1073cee313d2SEric Christopher  %6 = load i32, i32* %a.addr, align 4
1074cee313d2SEric Christopher  %arrayidx4 = getelementptr inbounds [100 x i32], [100 x i32]* getelementptr inbounds (%struct.anon, %struct.anon* @Foo, i32 0, i32 0), i32 0, i32 %6
1075cee313d2SEric Christopher  %7 = load i32, i32* %arrayidx4, align 4
1076cee313d2SEric Christopher  ret i32 %7
1077cee313d2SEric Christopher}
1078