1 ; RUN: opt < %s -basic-aa -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 i32* @random.i32(i32* %ptr)
7 declare i8* @random.i8(i32* %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 i32* @random.i32(i32* %alloca)
15 %p0 = getelementptr inbounds i32, i32* %random, i32 0
16 %p1 = getelementptr inbounds i32, i32* %random, i32 1
20 ; CHECK-LABEL: Function: arg:
21 ; CHECK-DAG: MayAlias: i32* %arg, i32* %p0
22 ; CHECK-DAG: MayAlias: i32* %arg, i32* %p1
23 define void @arg(i32* %arg) {
24 %random = call i32* @random.i32(i32* %arg)
25 %p0 = getelementptr inbounds i32, i32* %random, i32 0
26 %p1 = getelementptr inbounds i32, i32* %random, i32 1
31 ; CHECK-LABEL: Function: global:
32 ; CHECK-DAG: MayAlias: i32* %p0, i32* @gv
33 ; CHECK-DAG: NoAlias: i32* %p1, i32* @gv
34 define void @global() {
35 %random = call i32* @random.i32(i32* @gv)
36 %p0 = getelementptr inbounds i32, i32* %random, i32 0
37 %p1 = getelementptr inbounds i32, i32* %random, i32 1
41 ; CHECK-LABEL: Function: struct:
42 ; CHECK-DAG: MayAlias: i32* %f0, i32* %p0
43 ; CHECK-DAG: MayAlias: i32* %f1, i32* %p0
44 ; CHECK-DAG: NoAlias: i32* %f0, i32* %p1
45 ; CHECK-DAG: MayAlias: i32* %f1, i32* %p1
46 %struct = type { i32, i32, i32 }
47 define void @struct() {
48 %alloca = alloca %struct
49 %alloca.i32 = bitcast %struct* %alloca to i32*
50 %random = call i32* @random.i32(i32* %alloca.i32)
51 %f0 = getelementptr inbounds %struct, %struct* %alloca, i32 0, i32 0
52 %f1 = getelementptr inbounds %struct, %struct* %alloca, i32 0, i32 1
53 %p0 = getelementptr inbounds i32, i32* %random, i32 0
54 %p1 = getelementptr inbounds i32, i32* %random, i32 1
58 ; CHECK-LABEL: Function: complex1:
59 ; CHECK-DAG: MayAlias: i32* %a2.0, i32* %r2.0
60 ; CHECK-DAG: NoAlias: i32* %a2.0, i32* %r2.1
61 ; CHECK-DAG: MayAlias: i32* %a2.0, i32* %r2.i
62 ; CHECK-DAG: MayAlias: i32* %a2.0, i32* %r2.1i
63 ; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.0
64 ; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.1
65 ; CHECK-DAG: MayAlias: i32* %a1, i32* %r2.i
66 ; CHECK-DAG: MayAlias: i32* %a1, i32* %r2.1i
67 %complex = type { i32, i32, [4 x i32] }
68 define void @complex1(i32 %i) {
69 %alloca = alloca %complex
70 %alloca.i32 = bitcast %complex* %alloca to i32*
71 %r.i32 = call i32* @random.i32(i32* %alloca.i32)
72 %random = bitcast i32* %r.i32 to %complex*
73 %a1 = getelementptr inbounds %complex, %complex* %alloca, i32 0, i32 1
74 %a2.0 = getelementptr inbounds %complex, %complex* %alloca, i32 0, i32 2, i32 0
75 %r2.0 = getelementptr inbounds %complex, %complex* %random, i32 0, i32 2, i32 0
76 %r2.1 = getelementptr inbounds %complex, %complex* %random, i32 0, i32 2, i32 1
77 %r2.i = getelementptr inbounds %complex, %complex* %random, i32 0, i32 2, i32 %i
78 %r2.1i = getelementptr inbounds i32, i32* %r2.1, i32 %i
82 ; CHECK-LABEL: Function: complex2:
83 ; CHECK-DAG: NoAlias: i32* %alloca, i32* %p120
84 ; CHECK-DAG: MayAlias: i32* %alloca, i32* %pi20
85 ; CHECK-DAG: MayAlias: i32* %alloca, i32* %pij1
86 ; CHECK-DAG: MayAlias: i32* %a3, i32* %pij1
87 %inner = type { i32, i32 }
88 %outer = type { i32, i32, [10 x %inner] }
89 declare %outer* @rand_outer(i32* %p)
90 define void @complex2(i32 %i, i32 %j) {
91 %alloca = alloca i32, i32 128
92 %a3 = getelementptr inbounds i32, i32* %alloca, i32 3
93 %random = call %outer* @rand_outer(i32* %alloca)
94 %p120 = getelementptr inbounds %outer, %outer* %random, i32 1, i32 2, i32 2, i32 0
95 %pi20 = getelementptr inbounds %outer, %outer* %random, i32 %i, i32 2, i32 2, i32 0
96 %pij1 = getelementptr inbounds %outer, %outer* %random, i32 %i, i32 2, i32 %j, i32 1
100 ; CHECK-LABEL: Function: pointer_offset:
101 ; CHECK-DAG: MayAlias: i32** %add.ptr, i32** %p1
102 ; CHECK-DAG: MayAlias: i32** %add.ptr, i32** %q2
103 %struct.X = type { i32*, i32* }
104 define i32 @pointer_offset(i32 signext %i, i32 signext %j, i32 zeroext %off) {
108 %x = alloca %struct.X
109 store i32 %i, i32* %i.addr
110 store i32 %j, i32* %j.addr
111 %0 = bitcast %struct.X* %x to i8*
112 %p1 = getelementptr inbounds %struct.X, %struct.X* %x, i32 0, i32 0
113 store i32* %i.addr, i32** %p1
114 %q2 = getelementptr inbounds %struct.X, %struct.X* %x, i32 0, i32 1
115 store i32* %j.addr, i32** %q2
116 %add.ptr = getelementptr inbounds i32*, i32** %q2, i32 %off
117 %1 = load i32*, i32** %add.ptr
118 %2 = load i32, i32* %1
122 ; CHECK-LABEL: Function: one_size_unknown:
123 ; CHECK: NoModRef: Ptr: i8* %p.minus1 <-> call void @llvm.memset.p0i8.i32(i8* %p, i8 0, i32 %size, i1 false)
124 define void @one_size_unknown(i8* %p, i32 %size) {
125 %p.minus1 = getelementptr inbounds i8, i8* %p, i32 -1
126 call void @llvm.memset.p0i8.i32(i8* %p, i8 0, i32 %size, i1 false)
131 ; If part of the addressing is done with non-inbounds GEPs, we can't use
132 ; properties implied by the last gep w/the whole offset. In this case,
133 ; %random = %alloc - 4 bytes is well defined, and results in %step == %alloca,
134 ; leaving %p as an entirely inbounds gep pointing inside %alloca
135 ; CHECK-LABEL: Function: all_inbounds:
136 ; CHECK: MayAlias: i32* %alloca, i8* %p0
137 ; CHECK: MayAlias: i32* %alloca, i8* %p1
138 define void @all_inbounds() {
139 %alloca = alloca i32, i32 4
140 %random = call i8* @random.i8(i32* %alloca)
141 %p0 = getelementptr inbounds i8, i8* %random, i8 0
142 %step = getelementptr i8, i8* %random, i8 4
143 %p1 = getelementptr inbounds i8, i8* %step, i8 2
148 ; For all values of %x, %p0 and %p1 can't alias because %random would
149 ; have to be out of bounds (and thus a contradiction) for them to be equal.
150 ; CHECK-LABEL: Function: common_factor:
151 ; CHECK: NoAlias: i32* %p0, i32* %p1
152 define void @common_factor(i32 %x) {
153 %alloca = alloca i32, i32 4
154 %random = call i8* @random.i8(i32* %alloca)
155 %p0 = getelementptr inbounds i32, i32* %alloca, i32 %x
156 %step = getelementptr inbounds i8, i8* %random, i8 4
157 %step.bitcast = bitcast i8* %step to i32*
158 %p1 = getelementptr inbounds i32, i32* %step.bitcast, i32 %x
163 declare void @llvm.memset.p0i8.i32(i8*, i8, i32, i1)