1; RUN: opt < %s -basicaa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
2target 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"
3target triple = "x86_64-unknown-linux-gnu"
4
5; CHECK-LABEL: test_with_zext
6; CHECK:  NoAlias: i8* %a, i8* %b
7
8define void @test_with_zext() {
9  %1 = tail call i8* @malloc(i64 120)
10  %a = getelementptr inbounds i8, i8* %1, i64 8
11  %2 = getelementptr inbounds i8, i8* %1, i64 16
12  %3 = zext i32 3 to i64
13  %b = getelementptr inbounds i8, i8* %2, i64 %3
14  ret void
15}
16
17; CHECK-LABEL: test_with_lshr
18; CHECK:  NoAlias: i8* %a, i8* %b
19
20define void @test_with_lshr(i64 %i) {
21  %1 = tail call i8* @malloc(i64 120)
22  %a = getelementptr inbounds i8, i8* %1, i64 8
23  %2 = getelementptr inbounds i8, i8* %1, i64 16
24  %3 = lshr i64 %i, 2
25  %b = getelementptr inbounds i8, i8* %2, i64 %3
26  ret void
27}
28
29; CHECK-LABEL: test_with_a_loop
30; CHECK:  NoAlias: i8* %a, i8* %b
31
32define void @test_with_a_loop(i8* %mem) {
33  br label %for.loop
34
35for.loop:
36  %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]
37  %a = getelementptr inbounds i8, i8* %mem, i64 8
38  %a.plus1 = getelementptr inbounds i8, i8* %mem, i64 16
39  %i.64 = zext i32 %i to i64
40  %b = getelementptr inbounds i8, i8* %a.plus1, i64 %i.64
41  %i.plus1 = add nuw nsw i32 %i, 1
42  %cmp = icmp eq i32 %i.plus1, 10
43  br i1 %cmp, label %for.loop.exit, label %for.loop
44
45for.loop.exit:
46  ret void
47}
48
49; CHECK-LABEL: test_with_varying_base_pointer_in_loop
50; CHECK:  NoAlias: i8* %a, i8* %b
51
52define void @test_with_varying_base_pointer_in_loop(i8* %mem.orig) {
53  br label %for.loop
54
55for.loop:
56  %mem = phi i8* [ %mem.orig, %0 ], [ %mem.plus1, %for.loop ]
57  %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]
58  %a = getelementptr inbounds i8, i8* %mem, i64 8
59  %a.plus1 = getelementptr inbounds i8, i8* %mem, i64 16
60  %i.64 = zext i32 %i to i64
61  %b = getelementptr inbounds i8, i8* %a.plus1, i64 %i.64
62  %i.plus1 = add nuw nsw i32 %i, 1
63  %mem.plus1 = getelementptr inbounds i8, i8* %mem, i64 8
64  %cmp = icmp eq i32 %i.plus1, 10
65  br i1 %cmp, label %for.loop.exit, label %for.loop
66
67for.loop.exit:
68  ret void
69}
70
71; CHECK-LABEL: test_sign_extension
72; CHECK:  PartialAlias: i64* %b.i64, i8* %a
73
74define void @test_sign_extension(i32 %p) {
75  %1 = tail call i8* @malloc(i64 120)
76  %p.64 = zext i32 %p to i64
77  %a = getelementptr inbounds i8, i8* %1, i64 %p.64
78  %p.minus1 = add i32 %p, -1
79  %p.minus1.64 = zext i32 %p.minus1 to i64
80  %b.i8 = getelementptr inbounds i8, i8* %1, i64 %p.minus1.64
81  %b.i64 = bitcast i8* %b.i8 to i64*
82  ret void
83}
84
85; CHECK-LABEL: test_fe_tools
86; CHECK:  PartialAlias: i32* %a, i32* %b
87
88define void @test_fe_tools([8 x i32]* %values) {
89  br label %reorder
90
91for.loop:
92  %i = phi i32 [ 0, %reorder ], [ %i.next, %for.loop ]
93  %idxprom = zext i32 %i to i64
94  %b = getelementptr inbounds [8 x i32], [8 x i32]* %values, i64 0, i64 %idxprom
95  %i.next = add nuw nsw i32 %i, 1
96  %1 = icmp eq i32 %i.next, 10
97  br i1 %1, label %for.loop.exit, label %for.loop
98
99reorder:
100  %a = getelementptr inbounds [8 x i32], [8 x i32]* %values, i64 0, i64 1
101  br label %for.loop
102
103for.loop.exit:
104  ret void
105}
106
107@b = global i32 0, align 4
108@d = global i32 0, align 4
109
110; CHECK-LABEL: test_spec2006
111; CHECK:  PartialAlias: i32** %x, i32** %y
112
113define void @test_spec2006() {
114  %h = alloca [1 x [2 x i32*]], align 16
115  %d.val = load i32, i32* @d, align 4
116  %d.promoted = sext i32 %d.val to i64
117  %1 = icmp slt i32 %d.val, 2
118  br i1 %1, label %.lr.ph, label %3
119
120.lr.ph:                                           ; preds = %0
121  br label %2
122
123; <label>:2                                       ; preds = %.lr.ph, %2
124  %i = phi i32 [ %d.val, %.lr.ph ], [ %i.plus1, %2 ]
125  %i.promoted = sext i32 %i to i64
126  %x = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 %d.promoted, i64 %i.promoted
127  %i.plus1 = add nsw i32 %i, 1
128  %cmp = icmp slt i32 %i.plus1, 2
129  br i1 %cmp, label %2, label %3
130
131; <label>:3                                      ; preds = %._crit_edge, %0
132  %y = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 0, i64 1
133  ret void
134}
135
136; CHECK-LABEL: test_modulo_analysis_easy_case
137; CHECK:  NoAlias: i32** %x, i32** %y
138
139define void @test_modulo_analysis_easy_case(i64 %i) {
140  %h = alloca [1 x [2 x i32*]], align 16
141  %x = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 %i, i64 0
142  %y = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 0, i64 1
143  ret void
144}
145
146; CHECK-LABEL: test_modulo_analysis_in_loop
147; CHECK:  NoAlias: i32** %x, i32** %y
148
149define void @test_modulo_analysis_in_loop() {
150  %h = alloca [1 x [2 x i32*]], align 16
151  br label %for.loop
152
153for.loop:
154  %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]
155  %i.promoted = sext i32 %i to i64
156  %x = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 %i.promoted, i64 0
157  %y = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 0, i64 1
158  %i.plus1 = add nsw i32 %i, 1
159  %cmp = icmp slt i32 %i.plus1, 2
160  br i1 %cmp, label %for.loop, label %for.loop.exit
161
162for.loop.exit:
163  ret void
164}
165
166; CHECK-LABEL: test_modulo_analysis_with_global
167; CHECK:  PartialAlias: i32** %x, i32** %y
168
169define void @test_modulo_analysis_with_global() {
170  %h = alloca [1 x [2 x i32*]], align 16
171  %b = load i32, i32* @b, align 4
172  %b.promoted = sext i32 %b to i64
173  br label %for.loop
174
175for.loop:
176  %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]
177  %i.promoted = sext i32 %i to i64
178  %x = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 %i.promoted, i64 %b.promoted
179  %y = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 0, i64 1
180  %i.plus1 = add nsw i32 %i, 1
181  %cmp = icmp slt i32 %i.plus1, 2
182  br i1 %cmp, label %for.loop, label %for.loop.exit
183
184for.loop.exit:
185  ret void
186}
187
188; CHECK-LABEL: test_const_eval
189; CHECK: NoAlias: i8* %a, i8* %b
190define void @test_const_eval(i8* %ptr, i64 %offset) {
191  %a = getelementptr inbounds i8, i8* %ptr, i64 %offset
192  %a.dup = getelementptr inbounds i8, i8* %ptr, i64 %offset
193  %three = zext i32 3 to i64
194  %b = getelementptr inbounds i8, i8* %a.dup, i64 %three
195  ret void
196}
197
198; CHECK-LABEL: test_const_eval_scaled
199; CHECK: MustAlias: i8* %a, i8* %b
200define void @test_const_eval_scaled(i8* %ptr) {
201  %three = zext i32 3 to i64
202  %six = mul i64 %three, 2
203  %a = getelementptr inbounds i8, i8* %ptr, i64 %six
204  %b = getelementptr inbounds i8, i8* %ptr, i64 6
205  ret void
206}
207
208; CHECK-LABEL: Function: foo
209; CHECK: MustAlias:    float* %arrayidx, float* %arrayidx4.84
210define float @foo(i32 *%A, float %rend, float** %wayar)  {
211entry:
212  %x0 = load i32, i32* %A, align 4
213  %conv = sext i32 %x0 to i64
214  %mul = shl nsw i64 %conv, 3
215  %call = tail call i8* @malloc(i64 %mul)
216  %x1 = bitcast i8* %call to float*
217
218  %sub = add nsw i32 %x0, -1
219  %idxprom = sext i32 %sub to i64
220  %arrayidx = getelementptr inbounds float, float* %x1, i64 %idxprom
221  store float %rend, float* %arrayidx, align 8
222
223  %indvars.iv76.83 = add nsw i64 %conv, -1
224  %arrayidx4.84 = getelementptr inbounds float, float* %x1, i64 %indvars.iv76.83
225  %x4 = load float, float* %arrayidx4.84, align 8
226
227  ret float %x4
228}
229
230; Function Attrs: nounwind
231declare noalias i8* @malloc(i64)
232