1target datalayout =
2"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
3
4; RUN: opt < %s -basic-aa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
5
6; ptr_phi and ptr2_phi do not alias.
7; CHECK: test_noalias_1
8; CHECK: NoAlias: i32* %ptr2_phi, i32* %ptr_phi
9; CHECK: NoAlias: i32* %ptr2_inc, i32* %ptr_inc
10define i32 @test_noalias_1(i32* %ptr2, i32 %count, i32* %coeff) {
11entry:
12  %ptr = getelementptr inbounds i32, i32* %ptr2, i64 1
13  br label %while.body
14
15while.body:
16  %num = phi i32 [ %count, %entry ], [ %dec, %while.body ]
17  %ptr_phi = phi i32* [ %ptr, %entry ], [ %ptr_inc, %while.body ]
18  %ptr2_phi = phi i32* [ %ptr2, %entry ], [ %ptr2_inc, %while.body ]
19  %result.09 = phi i32 [ 0 , %entry ], [ %add, %while.body ]
20  %dec = add nsw i32 %num, -1
21  %0 = load i32, i32* %ptr_phi, align 4
22  store i32 %0, i32* %ptr2_phi, align 4
23  %1 = load i32, i32* %coeff, align 4
24  %2 = load i32, i32* %ptr_phi, align 4
25  %mul = mul nsw i32 %1, %2
26  %add = add nsw i32 %mul, %result.09
27  %tobool = icmp eq i32 %dec, 0
28  %ptr_inc = getelementptr inbounds i32, i32* %ptr_phi, i64 1
29  %ptr2_inc = getelementptr inbounds i32, i32* %ptr2_phi, i64 1
30  br i1 %tobool, label %the_exit, label %while.body
31
32the_exit:
33  ret i32 %add
34}
35
36; CHECK: test_noalias_2
37; CHECK: NoAlias: i32* %ptr_outer_phi, i32* %ptr_outer_phi2
38; CHECK: NoAlias: i32* %ptr2_inc_outer, i32* %ptr_inc_outer
39; CHECK: NoAlias: i32* %ptr2_phi, i32* %ptr_phi
40; CHECK: NoAlias: i32* %ptr2_inc, i32* %ptr_inc
41define i32 @test_noalias_2(i32* %ptr2, i32 %count, i32* %coeff) {
42entry:
43  %ptr = getelementptr inbounds i32, i32* %ptr2, i64 1
44  br label %outer.while.header
45
46outer.while.header:
47  %ptr_outer_phi = phi i32* [%ptr_inc_outer, %outer.while.backedge], [ %ptr, %entry]
48  %ptr_outer_phi2 = phi i32* [%ptr2_inc_outer, %outer.while.backedge], [ %ptr2, %entry]
49  %num.outer = phi i32 [ %count, %entry ], [ %dec.outer, %outer.while.backedge ]
50  br label %while.body
51
52while.body:
53  %num = phi i32 [ %count, %outer.while.header ], [ %dec, %while.body ]
54  %ptr_phi = phi i32* [ %ptr_outer_phi, %outer.while.header ], [ %ptr_inc, %while.body ]
55  %ptr2_phi = phi i32* [ %ptr_outer_phi2, %outer.while.header ], [ %ptr2_inc, %while.body ]
56  %result.09 = phi i32 [ 0 , %outer.while.header ], [ %add, %while.body ]
57  %dec = add nsw i32 %num, -1
58  %0 = load i32, i32* %ptr_phi, align 4
59  store i32 %0, i32* %ptr2_phi, align 4
60  %1 = load i32, i32* %coeff, align 4
61  %2 = load i32, i32* %ptr_phi, align 4
62  %mul = mul nsw i32 %1, %2
63  %add = add nsw i32 %mul, %result.09
64  %tobool = icmp eq i32 %dec, 0
65  %ptr_inc = getelementptr inbounds i32, i32* %ptr_phi, i64 1
66  %ptr2_inc = getelementptr inbounds i32, i32* %ptr2_phi, i64 1
67  br i1 %tobool, label %outer.while.backedge, label %while.body
68
69outer.while.backedge:
70  %ptr_inc_outer = getelementptr inbounds i32, i32* %ptr_phi, i64 1
71  %ptr2_inc_outer = getelementptr inbounds i32, i32* %ptr2_phi, i64 1
72  %dec.outer = add nsw i32 %num.outer, -1
73  %br.cond = icmp eq i32 %dec.outer, 0
74  br i1 %br.cond, label %the_exit, label %outer.while.header
75
76the_exit:
77  ret i32 %add
78}
79
80; CHECK: test_noalias_3
81; CHECK: MayAlias: i8* %ptr2_phi, i8* %ptr_phi
82define i32 @test_noalias_3(i8* noalias %x, i8* noalias %y, i8* noalias %z,
83                           i32 %count) {
84entry:
85  br label %while.body
86
87while.body:
88  %num = phi i32 [ %count, %entry ], [ %dec, %while.body ]
89  %ptr_phi = phi i8* [ %x, %entry ], [ %z, %while.body ]
90  %ptr2_phi = phi i8* [ %y, %entry ], [ %ptr_phi, %while.body ]
91  %dec = add nsw i32 %num, -1
92  %tobool = icmp eq i32 %dec, 0
93  br i1 %tobool, label %the_exit, label %while.body
94
95the_exit:
96  ret i32 1
97}
98
99; CHECK-LABEL: test_different_stride_noalias
100; CHECK: NoAlias: i16* %y.base, i8* %x.base
101; CHECK: NoAlias: i16* %y, i8* %x
102; CHECK: NoAlias: i16* %y.next, i8* %x.next
103define void @test_different_stride_noalias(i1 %c, i8* noalias %x.base, i16* noalias %y.base) {
104entry:
105  br label %loop
106
107loop:
108  %x = phi i8* [ %x.base, %entry ], [ %x.next, %loop ]
109  %y = phi i16* [ %y.base, %entry ], [ %y.next, %loop ]
110  %x.next = getelementptr i8, i8* %x, i64 1
111  %y.next = getelementptr i16, i16* %y, i64 1
112  br i1 %c, label %loop, label %exit
113
114exit:
115  ret void
116}
117
118; CHECK-LABEL: test_no_loop_mustalias
119; CHECK: MustAlias: i16* %z16, i8* %z8
120define void @test_no_loop_mustalias(i1 %c, i8* noalias %x8, i8* noalias %y8) {
121  br i1 %c, label %if, label %else
122
123if:
124  %x16 = bitcast i8* %x8 to i16*
125  br label %end
126
127else:
128  %y16 = bitcast i8* %y8 to i16*
129  br label %end
130
131end:
132  %z8 = phi i8* [ %x8, %if ], [ %y8, %else ]
133  %z16 = phi i16* [ %x16, %if ], [ %y16, %else ]
134  ret void
135}
136
137; CHECK-LABEL: test_same_stride_mustalias
138; CHECK: MustAlias: i4* %y.base, i8* %x.base
139; CHECK: MayAlias: i4* %y, i8* %x
140; CHECK: MayAlias: i4* %y.next, i8* %x.next
141; TODO: (x, y) could be MustAlias
142define void @test_same_stride_mustalias(i1 %c, i8* noalias %x.base) {
143entry:
144  %y.base = bitcast i8* %x.base to i4*
145  br label %loop
146
147loop:
148  %x = phi i8* [ %x.base, %entry ], [ %x.next, %loop ]
149  %y = phi i4* [ %y.base, %entry ], [ %y.next, %loop ]
150  %x.next = getelementptr i8, i8* %x, i64 1
151  %y.next = getelementptr i4, i4* %y, i64 1
152  br i1 %c, label %loop, label %exit
153
154exit:
155  ret void
156}
157
158; CHECK-LABEL: test_different_stride_mustalias
159; CHECK: MustAlias: i16* %y.base, i8* %x.base
160; CHECK: MayAlias: i16* %y, i8* %x
161; CHECK: MayAlias: i16* %y.next, i8* %x.next
162; Even though the base pointers MustAlias, the different strides don't preserve
163; this property across iterations.
164define void @test_different_stride_mustalias(i1 %c, i8* noalias %x.base) {
165entry:
166  %y.base = bitcast i8* %x.base to i16*
167  br label %loop
168
169loop:
170  %x = phi i8* [ %x.base, %entry ], [ %x.next, %loop ]
171  %y = phi i16* [ %y.base, %entry ], [ %y.next, %loop ]
172  %x.next = getelementptr i8, i8* %x, i64 1
173  %y.next = getelementptr i16, i16* %y, i64 1
174  br i1 %c, label %loop, label %exit
175
176exit:
177  ret void
178}
179