1 ; RUN: opt < %s -aa-pipeline=basic-aa -passes=aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
2 target 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"
3 target triple = "x86_64-unknown-linux-gnu"
5 ; CHECK-LABEL: test_with_zext
6 ; CHECK: NoAlias: i8* %a, i8* %b
8 define void @test_with_zext() {
9 %1 = tail call ptr @malloc(i64 120)
10 %a = getelementptr inbounds i8, ptr %1, i64 8
11 %2 = getelementptr inbounds i8, ptr %1, i64 16
12 %3 = zext i32 3 to i64
13 %b = getelementptr inbounds i8, ptr %2, i64 %3
19 ; CHECK-LABEL: test_with_lshr
20 ; CHECK: NoAlias: i8* %a, i8* %b
22 define void @test_with_lshr(i64 %i) {
23 %1 = tail call ptr @malloc(i64 120)
24 %a = getelementptr inbounds i8, ptr %1, i64 8
25 %2 = getelementptr inbounds i8, ptr %1, i64 16
27 %b = getelementptr inbounds i8, ptr %2, i64 %3
33 ; CHECK-LABEL: test_with_lshr_different_sizes
34 ; CHECK: NoAlias: i8* %m1, i16* %m2.idx
36 define void @test_with_lshr_different_sizes(i64 %i) {
37 %m0 = tail call ptr @malloc(i64 120)
38 %m1 = getelementptr inbounds i8, ptr %m0, i64 1
40 %m2 = getelementptr inbounds i8, ptr %m0, i64 2
42 %m2.idx = getelementptr inbounds i16, ptr %m2, i64 %idx
47 ; CHECK-LABEL: test_with_a_loop
48 ; CHECK: NoAlias: i8* %a, i8* %b
50 define void @test_with_a_loop(ptr %mem) {
54 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]
55 %a = getelementptr inbounds i8, ptr %mem, i64 8
57 %a.plus1 = getelementptr inbounds i8, ptr %mem, i64 16
58 %i.64 = zext i32 %i to i64
59 %b = getelementptr inbounds i8, ptr %a.plus1, i64 %i.64
61 %i.plus1 = add nuw nsw i32 %i, 1
62 %cmp = icmp eq i32 %i.plus1, 10
63 br i1 %cmp, label %for.loop.exit, label %for.loop
69 ; CHECK-LABEL: test_with_varying_base_pointer_in_loop
70 ; CHECK: NoAlias: i8* %a, i8* %b
72 define void @test_with_varying_base_pointer_in_loop(ptr %mem.orig) {
76 %mem = phi ptr [ %mem.orig, %0 ], [ %mem.plus1, %for.loop ]
77 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]
78 %a = getelementptr inbounds i8, ptr %mem, i64 8
80 %a.plus1 = getelementptr inbounds i8, ptr %mem, i64 16
81 %i.64 = zext i32 %i to i64
82 %b = getelementptr inbounds i8, ptr %a.plus1, i64 %i.64
84 %i.plus1 = add nuw nsw i32 %i, 1
85 %mem.plus1 = getelementptr inbounds i8, ptr %mem, i64 8
86 %cmp = icmp eq i32 %i.plus1, 10
87 br i1 %cmp, label %for.loop.exit, label %for.loop
93 ; CHECK-LABEL: test_sign_extension
94 ; CHECK: MayAlias: i8* %a, i64* %b.i8
96 define void @test_sign_extension(i32 %p) {
97 %1 = tail call ptr @malloc(i64 120)
98 %p.64 = zext i32 %p to i64
99 %a = getelementptr inbounds i8, ptr %1, i64 %p.64
101 %p.minus1 = add i32 %p, -1
102 %p.minus1.64 = zext i32 %p.minus1 to i64
103 %b.i8 = getelementptr inbounds i8, ptr %1, i64 %p.minus1.64
108 ; CHECK-LABEL: test_fe_tools
109 ; CHECK: MayAlias: i32* %a, i32* %b
111 define void @test_fe_tools(ptr %values) {
115 %i = phi i32 [ 0, %reorder ], [ %i.next, %for.loop ]
116 %idxprom = zext i32 %i to i64
117 %b = getelementptr inbounds [8 x i32], ptr %values, i64 0, i64 %idxprom
119 %i.next = add nuw nsw i32 %i, 1
120 %cmp = icmp eq i32 %i.next, 10
121 br i1 %cmp, label %for.loop.exit, label %for.loop
124 %a = getelementptr inbounds [8 x i32], ptr %values, i64 0, i64 1
132 @b = global i32 0, align 4
133 @d = global i32 0, align 4
135 ; CHECK-LABEL: test_spec2006
136 ; CHECK: MayAlias: ptr* %x, ptr* %y
138 define void @test_spec2006() {
139 %h = alloca [1 x [2 x ptr]], align 16
140 %d.val = load i32, ptr @d, align 4
141 %d.promoted = sext i32 %d.val to i64
142 %1 = icmp slt i32 %d.val, 2
143 br i1 %1, label %.lr.ph, label %bb3
149 %i = phi i32 [ %d.val, %.lr.ph ], [ %i.plus1, %bb2 ]
150 %i.promoted = sext i32 %i to i64
151 %x = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 %d.promoted, i64 %i.promoted
153 %i.plus1 = add nsw i32 %i, 1
154 %cmp = icmp slt i32 %i.plus1, 2
155 br i1 %cmp, label %bb2, label %bb3
158 %y = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 0, i64 1
163 ; CHECK-LABEL: test_modulo_analysis_easy_case
164 ; CHECK: NoAlias: ptr* %x, ptr* %y
166 define void @test_modulo_analysis_easy_case(i64 %i) {
167 %h = alloca [1 x [2 x ptr]], align 16
168 %x = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 %i, i64 0
169 %y = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 0, i64 1
175 ; CHECK-LABEL: test_modulo_analysis_in_loop
176 ; CHECK: NoAlias: ptr* %x, ptr* %y
178 define void @test_modulo_analysis_in_loop() {
179 %h = alloca [1 x [2 x ptr]], align 16
183 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]
184 %i.promoted = sext i32 %i to i64
185 %x = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 %i.promoted, i64 0
186 %y = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 0, i64 1
189 %i.plus1 = add nsw i32 %i, 1
190 %cmp = icmp slt i32 %i.plus1, 2
191 br i1 %cmp, label %for.loop, label %for.loop.exit
197 ; CHECK-LABEL: test_modulo_analysis_with_global
198 ; CHECK: MayAlias: ptr* %x, ptr* %y
200 define void @test_modulo_analysis_with_global() {
201 %h = alloca [1 x [2 x ptr]], align 16
202 %b = load i32, ptr @b, align 4
203 %b.promoted = sext i32 %b to i64
207 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]
208 %i.promoted = sext i32 %i to i64
209 %x = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 %i.promoted, i64 %b.promoted
210 %y = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 0, i64 1
213 %i.plus1 = add nsw i32 %i, 1
214 %cmp = icmp slt i32 %i.plus1, 2
215 br i1 %cmp, label %for.loop, label %for.loop.exit
221 ; CHECK-LABEL: test_const_eval
222 ; CHECK: NoAlias: i8* %a, i8* %b
223 define void @test_const_eval(ptr %ptr, i64 %offset) {
224 %a = getelementptr inbounds i8, ptr %ptr, i64 %offset
225 %a.dup = getelementptr inbounds i8, ptr %ptr, i64 %offset
226 %three = zext i32 3 to i64
227 %b = getelementptr inbounds i8, ptr %a.dup, i64 %three
233 ; CHECK-LABEL: test_const_eval_scaled
234 ; CHECK: MustAlias: i8* %a, i8* %b
235 define void @test_const_eval_scaled(ptr %ptr) {
236 %three = zext i32 3 to i64
237 %six = mul i64 %three, 2
238 %a = getelementptr inbounds i8, ptr %ptr, i64 %six
239 %b = getelementptr inbounds i8, ptr %ptr, i64 6
245 ; CHECK-LABEL: Function: foo
246 ; CHECK: MustAlias: float* %arrayidx, float* %arrayidx4.84
247 define float @foo(ptr %A, float %rend, ptr %wayar) {
249 %x0 = load i32, ptr %A, align 4
250 %conv = sext i32 %x0 to i64
251 %mul = shl nsw i64 %conv, 3
252 %call = tail call ptr @malloc(i64 %mul)
254 %sub = add nsw i32 %x0, -1
255 %idxprom = sext i32 %sub to i64
256 %arrayidx = getelementptr inbounds float, ptr %call, i64 %idxprom
257 store float %rend, ptr %arrayidx, align 8
259 %indvars.iv76.83 = add nsw i64 %conv, -1
260 %arrayidx4.84 = getelementptr inbounds float, ptr %call, i64 %indvars.iv76.83
261 %x4 = load float, ptr %arrayidx4.84, align 8
266 ; CHECK-LABEL: Function: test_shl_nuw_zext
267 ; CHECK: MustAlias: i8* %p.1, i8* %p.2
268 define void @test_shl_nuw_zext(ptr %p, i32 %x) {
269 %shl = shl nuw i32 %x, 1
270 %shl.ext = zext i32 %shl to i64
271 %ext = zext i32 %x to i64
272 %ext.shl = shl nuw i64 %ext, 1
273 %p.1 = getelementptr i8, ptr %p, i64 %shl.ext
274 %p.2 = getelementptr i8, ptr %p, i64 %ext.shl
280 ; CHECK-LABEL: Function: test_shl_nsw_sext
281 ; CHECK: MustAlias: i8* %p.1, i8* %p.2
282 define void @test_shl_nsw_sext(ptr %p, i32 %x) {
283 %shl = shl nsw i32 %x, 1
284 %shl.ext = sext i32 %shl to i64
285 %ext = sext i32 %x to i64
286 %ext.shl = shl nsw i64 %ext, 1
287 %p.1 = getelementptr i8, ptr %p, i64 %shl.ext
288 %p.2 = getelementptr i8, ptr %p, i64 %ext.shl
294 ; CHECK-LABEL: Function: test_implicit_sext
295 ; CHECK: MayAlias: i8* %p.1, i8* %p.2
296 define void @test_implicit_sext(ptr %p, i32 %x) {
298 %ext = sext i32 %x to i64
299 %ext.add = add i64 %ext, 1
300 %p.1 = getelementptr i8, ptr %p, i32 %add
301 %p.2 = getelementptr i8, ptr %p, i64 %ext.add
307 ; CHECK-LABEL: Function: test_partial_decomposition
308 ; CHECK: MustAlias: i8* %p.1, i8* %p.2
309 define void @test_partial_decomposition(ptr %p, i32 %x) {
311 %add.1 = add nsw i32 %add, 1
312 %add.2 = add nsw i32 %add, 1
313 %p.1 = getelementptr i8, ptr %p, i32 %add.1
314 %p.2 = getelementptr i8, ptr %p, i32 %add.2
320 ; Function Attrs: nounwind
321 declare noalias ptr @malloc(i64)