1 ; RUN: opt < %s -aa-pipeline=basic-aa -passes=aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
3 target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
4 target triple = "i386-unknown-linux-gnu"
6 declare ptr @random.i32(ptr %ptr)
7 declare ptr @random.i8(ptr %ptr)
9 ; CHECK-LABEL: Function: arr:
10 ; CHECK-DAG: MayAlias: i32* %alloca, i32* %p0
11 ; CHECK-DAG: NoAlias: i32* %alloca, i32* %p1
13 %alloca = alloca i32, i32 4
14 %random = call ptr @random.i32(ptr %alloca)
15 %p0 = getelementptr inbounds i32, ptr %random, i32 0
16 %p1 = getelementptr inbounds i32, ptr %random, i32 1
23 ; CHECK-LABEL: Function: arg:
24 ; CHECK-DAG: MayAlias: i32* %arg, i32* %p0
25 ; CHECK-DAG: MayAlias: i32* %arg, i32* %p1
26 define void @arg(ptr %arg) {
27 %random = call ptr @random.i32(ptr %arg)
28 %p0 = getelementptr inbounds i32, ptr %random, i32 0
29 %p1 = getelementptr inbounds i32, ptr %random, i32 1
37 ; CHECK-LABEL: Function: global:
38 ; CHECK-DAG: MayAlias: i32* %random, i32* @gv
39 ; CHECK-DAG: NoAlias: i32* %p1, i32* @gv
40 define void @global() {
41 %random = call ptr @random.i32(ptr @gv)
42 %p1 = getelementptr inbounds i32, ptr %random, i32 1
49 ; CHECK-LABEL: Function: struct:
50 ; CHECK-DAG: MayAlias: i32* %alloca, i32* %p0
51 ; CHECK-DAG: MayAlias: i32* %f1, i32* %p0
52 ; CHECK-DAG: NoAlias: i32* %alloca, i32* %p1
53 ; CHECK-DAG: MayAlias: i32* %f1, i32* %p1
54 %struct = type { i32, i32, i32 }
55 define void @struct() {
56 %alloca = alloca %struct
57 %random = call ptr @random.i32(ptr %alloca)
58 %f1 = getelementptr inbounds %struct, ptr %alloca, i32 0, i32 1
59 %p0 = getelementptr inbounds i32, ptr %random, i32 0
60 %p1 = getelementptr inbounds i32, ptr %random, i32 1
68 ; CHECK-LABEL: Function: complex1:
69 ; CHECK-DAG: MayAlias: i32* %a2.0, i32* %r2.0
70 ; CHECK-DAG: NoAlias: i32* %a2.0, i32* %r2.1
71 ; CHECK-DAG: MayAlias: i32* %a2.0, i32* %r2.i
72 ; CHECK-DAG: MayAlias: i32* %a2.0, i32* %r2.1i
73 ; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.0
74 ; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.1
75 ; CHECK-DAG: MayAlias: i32* %a1, i32* %r2.i
76 ; CHECK-DAG: MayAlias: i32* %a1, i32* %r2.1i
77 %complex = type { i32, i32, [4 x i32] }
78 define void @complex1(i32 %i) {
79 %alloca = alloca %complex
80 %r.i32 = call ptr @random.i32(ptr %alloca)
81 %a1 = getelementptr inbounds %complex, ptr %alloca, i32 0, i32 1
82 %a2.0 = getelementptr inbounds %complex, ptr %alloca, i32 0, i32 2, i32 0
83 %r2.0 = getelementptr inbounds %complex, ptr %r.i32, i32 0, i32 2, i32 0
84 %r2.1 = getelementptr inbounds %complex, ptr %r.i32, i32 0, i32 2, i32 1
85 %r2.i = getelementptr inbounds %complex, ptr %r.i32, i32 0, i32 2, i32 %i
86 %r2.1i = getelementptr inbounds i32, ptr %r2.1, i32 %i
96 ; CHECK-LABEL: Function: complex2:
97 ; CHECK-DAG: NoAlias: i32* %alloca, i32* %p120
98 ; CHECK-DAG: MayAlias: i32* %alloca, i32* %pi20
99 ; CHECK-DAG: MayAlias: i32* %alloca, i32* %pij1
100 ; CHECK-DAG: MayAlias: i32* %a3, i32* %pij1
101 %inner = type { i32, i32 }
102 %outer = type { i32, i32, [10 x %inner] }
103 declare ptr @rand_outer(ptr %p)
104 define void @complex2(i32 %i, i32 %j) {
105 %alloca = alloca i32, i32 128
106 %a3 = getelementptr inbounds i32, ptr %alloca, i32 3
107 %random = call ptr @rand_outer(ptr %alloca)
108 %p120 = getelementptr inbounds %outer, ptr %random, i32 1, i32 2, i32 2, i32 0
109 %pi20 = getelementptr inbounds %outer, ptr %random, i32 %i, i32 2, i32 2, i32 0
110 %pij1 = getelementptr inbounds %outer, ptr %random, i32 %i, i32 2, i32 %j, i32 1
111 load i32, ptr %alloca
119 ; CHECK-LABEL: Function: pointer_offset:
120 ; CHECK-DAG: MayAlias: ptr* %add.ptr, ptr* %x
121 ; CHECK-DAG: MayAlias: ptr* %add.ptr, ptr* %q2
122 %struct.X = type { ptr, ptr }
123 define i32 @pointer_offset(i32 signext %i, i32 signext %j, i32 zeroext %off) {
127 %x = alloca %struct.X
128 store i32 %i, ptr %i.addr
129 store i32 %j, ptr %j.addr
130 store ptr %i.addr, ptr %x
131 %q2 = getelementptr inbounds %struct.X, ptr %x, i32 0, i32 1
132 store ptr %j.addr, ptr %q2
133 %add.ptr = getelementptr inbounds ptr, ptr %q2, i32 %off
134 %0 = load ptr, ptr %add.ptr
135 %1 = load i32, ptr %0
139 ; CHECK-LABEL: Function: one_size_unknown:
140 ; CHECK: NoModRef: Ptr: i8* %p.minus1 <-> call void @llvm.memset.p0.i32(ptr %p, i8 0, i32 %size, i1 false)
141 define void @one_size_unknown(ptr %p, i32 %size) {
142 %p.minus1 = getelementptr inbounds i8, ptr %p, i32 -1
143 call void @llvm.memset.p0.i32(ptr %p, i8 0, i32 %size, i1 false)
144 load i8, ptr %p.minus1
149 ; If part of the addressing is done with non-inbounds GEPs, we can't use
150 ; properties implied by the last gep w/the whole offset. In this case,
151 ; %random = %alloc - 4 bytes is well defined, and results in %step == %alloca,
152 ; leaving %p as an entirely inbounds gep pointing inside %alloca
153 ; CHECK-LABEL: Function: all_inbounds:
154 ; CHECK: MayAlias: i32* %alloca, i8* %random
155 ; CHECK: MayAlias: i32* %alloca, i8* %p1
156 define void @all_inbounds() {
157 %alloca = alloca i32, i32 4
158 %random = call ptr @random.i8(ptr %alloca)
159 %step = getelementptr i8, ptr %random, i8 4
160 %p1 = getelementptr inbounds i8, ptr %step, i8 2
161 load i32, ptr %alloca
168 ; For all values of %x, %random and %p1 can't alias because %random would
169 ; have to be out of bounds (and thus a contradiction) for them to be equal.
170 ; CHECK-LABEL: Function: common_factor:
171 ; CHECK: NoAlias: i32* %p0, i32* %p1
172 define void @common_factor(i32 %x) {
173 %alloca = alloca i32, i32 4
174 %random = call ptr @random.i8(ptr %alloca)
175 %p0 = getelementptr inbounds i32, ptr %alloca, i32 %x
176 %step = getelementptr inbounds i8, ptr %random, i8 4
177 %p1 = getelementptr inbounds i32, ptr %step, i32 %x
184 declare void @llvm.memset.p0.i32(ptr, i8, i32, i1)