blob: 3d9f2583b3abf4d12fdb33da57e07ee0b0621a25 [file] [log] [blame]
Dan Gohman3c7d3082009-09-11 18:01:28 +00001; RUN: opt < %s -disable-output -analyze -lda | FileCheck %s
Andreas Bolkae2fc6c72009-07-23 15:56:53 +00002
3@x = common global [256 x i32] zeroinitializer, align 4
4@y = common global [256 x i32] zeroinitializer, align 4
5
Andreas Bolkaa6ee19c2009-07-28 23:40:40 +00006;; for (i = 0; i < 256; i++)
Andreas Bolka7c76cd52009-08-02 23:28:14 +00007;; x[i] = x[255 - i] + y[i]
Andreas Bolkae2fc6c72009-07-23 15:56:53 +00008
9define void @f1(...) nounwind {
10entry:
11 br label %for.body
12
13for.body:
14 %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]
Andreas Bolka7c76cd52009-08-02 23:28:14 +000015 %i.255 = sub i64 255, %i
Andreas Bolka542dea82009-08-05 04:03:29 +000016 %y.ld.addr = getelementptr [256 x i32]* @y, i64 0, i64 %i
17 %x.ld.addr = getelementptr [256 x i32]* @x, i64 0, i64 %i.255
Andreas Bolkae2fc6c72009-07-23 15:56:53 +000018 %x.st.addr = getelementptr [256 x i32]* @x, i64 0, i64 %i
19 %x = load i32* %x.ld.addr ; 0
20 %y = load i32* %y.ld.addr ; 1
21 %r = add i32 %y, %x
22 store i32 %r, i32* %x.st.addr ; 2
23; CHECK: 0,2: dep
24; CHECK: 1,2: ind
25 %i.next = add i64 %i, 1
26 %exitcond = icmp eq i64 %i.next, 256
27 br i1 %exitcond, label %for.end, label %for.body
28
29for.end:
30 ret void
31}
32
Andreas Bolka7c76cd52009-08-02 23:28:14 +000033;; for (i = 0; i < 100; i++)
34;; x[i] = x[255 - i] + y[i]
Andreas Bolkae2fc6c72009-07-23 15:56:53 +000035
36define void @f2(...) nounwind {
37entry:
38 br label %for.body
39
40for.body:
41 %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]
Andreas Bolka542dea82009-08-05 04:03:29 +000042 %i.255 = sub i64 255, %i
Andreas Bolkae2fc6c72009-07-23 15:56:53 +000043 %y.ld.addr = getelementptr [256 x i32]* @y, i64 0, i64 %i
Andreas Bolka542dea82009-08-05 04:03:29 +000044 %x.ld.addr = getelementptr [256 x i32]* @x, i64 0, i64 %i.255
Andreas Bolkae2fc6c72009-07-23 15:56:53 +000045 %x.st.addr = getelementptr [256 x i32]* @x, i64 0, i64 %i
46 %x = load i32* %x.ld.addr ; 0
47 %y = load i32* %y.ld.addr ; 1
48 %r = add i32 %y, %x
49 store i32 %r, i32* %x.st.addr ; 2
50; CHECK: 0,2: dep
51; CHECK: 1,2: ind
52 %i.next = add i64 %i, 1
Andreas Bolka7c76cd52009-08-02 23:28:14 +000053 %exitcond = icmp eq i64 %i.next, 100
Andreas Bolkae2fc6c72009-07-23 15:56:53 +000054 br i1 %exitcond, label %for.end, label %for.body
55
56for.end:
57 ret void
58}
59
Andreas Bolka7c76cd52009-08-02 23:28:14 +000060;; // the first iteration (i=0) leads to an out-of-bounds access of x. as the
61;; // result of this access is undefined, _any_ dependence result is safe.
62;; for (i = 0; i < 256; i++)
Andreas Bolkaa6ee19c2009-07-28 23:40:40 +000063;; x[i] = x[256 - i] + y[i]
Andreas Bolkae2fc6c72009-07-23 15:56:53 +000064
65define void @f3(...) nounwind {
66entry:
67 br label %for.body
68
69for.body:
70 %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]
71 %i.256 = sub i64 0, %i
72 %y.ld.addr = getelementptr [256 x i32]* @y, i64 0, i64 %i
73 %x.ld.addr = getelementptr [256 x i32]* @x, i64 1, i64 %i.256
74 %x.st.addr = getelementptr [256 x i32]* @x, i64 0, i64 %i
75 %x = load i32* %x.ld.addr ; 0
76 %y = load i32* %y.ld.addr ; 1
77 %r = add i32 %y, %x
78 store i32 %r, i32* %x.st.addr ; 2
79; CHECK: 0,2: dep
Andreas Bolka7c76cd52009-08-02 23:28:14 +000080; CHECK: 1,2:
81 %i.next = add i64 %i, 1
82 %exitcond = icmp eq i64 %i.next, 256
83 br i1 %exitcond, label %for.end, label %for.body
84
85for.end:
86 ret void
87}
88
89;; // slightly contrived but valid IR for the following loop, where all
90;; // accesses in all iterations are within bounds. while this example's first
91;; // (ZIV-)subscript is (0, 1), accesses are dependent.
92;; for (i = 1; i < 256; i++)
93;; x[i] = x[256 - i] + y[i]
94
95define void @f4(...) nounwind {
96entry:
97 br label %for.body
98
99for.body:
100 %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]
101 %i.1 = add i64 1, %i
102 %i.256 = sub i64 -1, %i
103 %y.ld.addr = getelementptr [256 x i32]* @y, i64 0, i64 %i.1
104 %x.ld.addr = getelementptr [256 x i32]* @x, i64 1, i64 %i.256
105 %x.st.addr = getelementptr [256 x i32]* @x, i64 0, i64 %i.1
106 %x = load i32* %x.ld.addr ; 0
107 %y = load i32* %y.ld.addr ; 1
108 %r = add i32 %y, %x
109 store i32 %r, i32* %x.st.addr ; 2
110; CHECK: 0,2: dep
Andreas Bolkae2fc6c72009-07-23 15:56:53 +0000111; CHECK: 1,2: ind
112 %i.next = add i64 %i, 1
Andreas Bolka7c76cd52009-08-02 23:28:14 +0000113 %exitcond = icmp eq i64 %i.next, 256
Andreas Bolkae2fc6c72009-07-23 15:56:53 +0000114 br i1 %exitcond, label %for.end, label %for.body
115
116for.end:
117 ret void
118}