1 ; RUN: opt < %s -basic-aa -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 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
17 ; CHECK-LABEL: test_with_lshr
18 ; CHECK: NoAlias: i8* %a, i8* %b
20 define 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
25 %b = getelementptr inbounds i8, i8* %2, i64 %3
29 ; CHECK-LABEL: test_with_lshr_different_sizes
30 ; CHECK: NoAlias: i16* %m2.idx, i8* %m1
32 define void @test_with_lshr_different_sizes(i64 %i) {
33 %m0 = tail call i8* @malloc(i64 120)
34 %m1 = getelementptr inbounds i8, i8* %m0, i64 1
35 %m2 = getelementptr inbounds i8, i8* %m0, i64 2
37 %m2.i16 = bitcast i8* %m2 to i16*
38 %m2.idx = getelementptr inbounds i16, i16* %m2.i16, i64 %idx
42 ; CHECK-LABEL: test_with_a_loop
43 ; CHECK: NoAlias: i8* %a, i8* %b
45 define void @test_with_a_loop(i8* %mem) {
49 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]
50 %a = getelementptr inbounds i8, i8* %mem, i64 8
51 %a.plus1 = getelementptr inbounds i8, i8* %mem, i64 16
52 %i.64 = zext i32 %i to i64
53 %b = getelementptr inbounds i8, i8* %a.plus1, i64 %i.64
54 %i.plus1 = add nuw nsw i32 %i, 1
55 %cmp = icmp eq i32 %i.plus1, 10
56 br i1 %cmp, label %for.loop.exit, label %for.loop
62 ; CHECK-LABEL: test_with_varying_base_pointer_in_loop
63 ; CHECK: NoAlias: i8* %a, i8* %b
65 define void @test_with_varying_base_pointer_in_loop(i8* %mem.orig) {
69 %mem = phi i8* [ %mem.orig, %0 ], [ %mem.plus1, %for.loop ]
70 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]
71 %a = getelementptr inbounds i8, i8* %mem, i64 8
72 %a.plus1 = getelementptr inbounds i8, i8* %mem, i64 16
73 %i.64 = zext i32 %i to i64
74 %b = getelementptr inbounds i8, i8* %a.plus1, i64 %i.64
75 %i.plus1 = add nuw nsw i32 %i, 1
76 %mem.plus1 = getelementptr inbounds i8, i8* %mem, i64 8
77 %cmp = icmp eq i32 %i.plus1, 10
78 br i1 %cmp, label %for.loop.exit, label %for.loop
84 ; CHECK-LABEL: test_sign_extension
85 ; CHECK: MayAlias: i64* %b.i64, i8* %a
87 define void @test_sign_extension(i32 %p) {
88 %1 = tail call i8* @malloc(i64 120)
89 %p.64 = zext i32 %p to i64
90 %a = getelementptr inbounds i8, i8* %1, i64 %p.64
91 %p.minus1 = add i32 %p, -1
92 %p.minus1.64 = zext i32 %p.minus1 to i64
93 %b.i8 = getelementptr inbounds i8, i8* %1, i64 %p.minus1.64
94 %b.i64 = bitcast i8* %b.i8 to i64*
98 ; CHECK-LABEL: test_fe_tools
99 ; CHECK: MayAlias: i32* %a, i32* %b
101 define void @test_fe_tools([8 x i32]* %values) {
105 %i = phi i32 [ 0, %reorder ], [ %i.next, %for.loop ]
106 %idxprom = zext i32 %i to i64
107 %b = getelementptr inbounds [8 x i32], [8 x i32]* %values, i64 0, i64 %idxprom
108 %i.next = add nuw nsw i32 %i, 1
109 %1 = icmp eq i32 %i.next, 10
110 br i1 %1, label %for.loop.exit, label %for.loop
113 %a = getelementptr inbounds [8 x i32], [8 x i32]* %values, i64 0, i64 1
120 @b = global i32 0, align 4
121 @d = global i32 0, align 4
123 ; CHECK-LABEL: test_spec2006
124 ; CHECK: MayAlias: i32** %x, i32** %y
126 define void @test_spec2006() {
127 %h = alloca [1 x [2 x i32*]], align 16
128 %d.val = load i32, i32* @d, align 4
129 %d.promoted = sext i32 %d.val to i64
130 %1 = icmp slt i32 %d.val, 2
131 br i1 %1, label %.lr.ph, label %3
136 ; <label>:2 ; preds = %.lr.ph, %2
137 %i = phi i32 [ %d.val, %.lr.ph ], [ %i.plus1, %2 ]
138 %i.promoted = sext i32 %i to i64
139 %x = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 %d.promoted, i64 %i.promoted
140 %i.plus1 = add nsw i32 %i, 1
141 %cmp = icmp slt i32 %i.plus1, 2
142 br i1 %cmp, label %2, label %3
144 ; <label>:3 ; preds = %._crit_edge, %0
145 %y = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 0, i64 1
149 ; CHECK-LABEL: test_modulo_analysis_easy_case
150 ; CHECK: NoAlias: i32** %x, i32** %y
152 define void @test_modulo_analysis_easy_case(i64 %i) {
153 %h = alloca [1 x [2 x i32*]], align 16
154 %x = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 %i, i64 0
155 %y = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 0, i64 1
159 ; CHECK-LABEL: test_modulo_analysis_in_loop
160 ; CHECK: NoAlias: i32** %x, i32** %y
162 define void @test_modulo_analysis_in_loop() {
163 %h = alloca [1 x [2 x i32*]], align 16
167 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]
168 %i.promoted = sext i32 %i to i64
169 %x = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 %i.promoted, i64 0
170 %y = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 0, i64 1
171 %i.plus1 = add nsw i32 %i, 1
172 %cmp = icmp slt i32 %i.plus1, 2
173 br i1 %cmp, label %for.loop, label %for.loop.exit
179 ; CHECK-LABEL: test_modulo_analysis_with_global
180 ; CHECK: MayAlias: i32** %x, i32** %y
182 define void @test_modulo_analysis_with_global() {
183 %h = alloca [1 x [2 x i32*]], align 16
184 %b = load i32, i32* @b, align 4
185 %b.promoted = sext i32 %b to i64
189 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]
190 %i.promoted = sext i32 %i to i64
191 %x = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 %i.promoted, i64 %b.promoted
192 %y = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 0, i64 1
193 %i.plus1 = add nsw i32 %i, 1
194 %cmp = icmp slt i32 %i.plus1, 2
195 br i1 %cmp, label %for.loop, label %for.loop.exit
201 ; CHECK-LABEL: test_const_eval
202 ; CHECK: NoAlias: i8* %a, i8* %b
203 define void @test_const_eval(i8* %ptr, i64 %offset) {
204 %a = getelementptr inbounds i8, i8* %ptr, i64 %offset
205 %a.dup = getelementptr inbounds i8, i8* %ptr, i64 %offset
206 %three = zext i32 3 to i64
207 %b = getelementptr inbounds i8, i8* %a.dup, i64 %three
211 ; CHECK-LABEL: test_const_eval_scaled
212 ; CHECK: MustAlias: i8* %a, i8* %b
213 define void @test_const_eval_scaled(i8* %ptr) {
214 %three = zext i32 3 to i64
215 %six = mul i64 %three, 2
216 %a = getelementptr inbounds i8, i8* %ptr, i64 %six
217 %b = getelementptr inbounds i8, i8* %ptr, i64 6
221 ; CHECK-LABEL: Function: foo
222 ; CHECK: MustAlias: float* %arrayidx, float* %arrayidx4.84
223 define float @foo(i32 *%A, float %rend, float** %wayar) {
225 %x0 = load i32, i32* %A, align 4
226 %conv = sext i32 %x0 to i64
227 %mul = shl nsw i64 %conv, 3
228 %call = tail call i8* @malloc(i64 %mul)
229 %x1 = bitcast i8* %call to float*
231 %sub = add nsw i32 %x0, -1
232 %idxprom = sext i32 %sub to i64
233 %arrayidx = getelementptr inbounds float, float* %x1, i64 %idxprom
234 store float %rend, float* %arrayidx, align 8
236 %indvars.iv76.83 = add nsw i64 %conv, -1
237 %arrayidx4.84 = getelementptr inbounds float, float* %x1, i64 %indvars.iv76.83
238 %x4 = load float, float* %arrayidx4.84, align 8
243 ; CHECK-LABEL: Function: test_shl_nuw_zext
244 ; CHECK: MustAlias: i8* %p.1, i8* %p.2
245 define void @test_shl_nuw_zext(i8* %p, i32 %x) {
246 %shl = shl nuw i32 %x, 1
247 %shl.ext = zext i32 %shl to i64
248 %ext = zext i32 %x to i64
249 %ext.shl = shl nuw i64 %ext, 1
250 %p.1 = getelementptr i8, i8* %p, i64 %shl.ext
251 %p.2 = getelementptr i8, i8* %p, i64 %ext.shl
255 ; CHECK-LABEL: Function: test_shl_nsw_sext
256 ; CHECK: MustAlias: i8* %p.1, i8* %p.2
257 define void @test_shl_nsw_sext(i8* %p, i32 %x) {
258 %shl = shl nsw i32 %x, 1
259 %shl.ext = sext i32 %shl to i64
260 %ext = sext i32 %x to i64
261 %ext.shl = shl nsw i64 %ext, 1
262 %p.1 = getelementptr i8, i8* %p, i64 %shl.ext
263 %p.2 = getelementptr i8, i8* %p, i64 %ext.shl
267 ; CHECK-LABEL: Function: test_implicit_sext
268 ; CHECK: MayAlias: i8* %p.1, i8* %p.2
269 define void @test_implicit_sext(i8* %p, i32 %x) {
271 %ext = sext i32 %x to i64
272 %ext.add = add i64 %ext, 1
273 %p.1 = getelementptr i8, i8* %p, i32 %add
274 %p.2 = getelementptr i8, i8* %p, i64 %ext.add
278 ; CHECK-LABEL: Function: test_partial_decomposition
279 ; CHECK: MustAlias: i8* %p.1, i8* %p.2
280 define void @test_partial_decomposition(i8* %p, i32 %x) {
282 %add.1 = add nsw i32 %add, 1
283 %add.2 = add nsw i32 %add, 1
284 %p.1 = getelementptr i8, i8* %p, i32 %add.1
285 %p.2 = getelementptr i8, i8* %p, i32 %add.2
289 ; Function Attrs: nounwind
290 declare noalias i8* @malloc(i64)