blob: 7569e66eccfb1e6520f91388bdbc6a09cbd971d4 [file] [log] [blame]
Michael Kuperstein82069c42016-05-25 22:23:08 +00001; RUN: opt < %s -basicaa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
2
3target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
4target triple = "i386-unknown-linux-gnu"
5
6declare i32* @random.i32(i32* %ptr)
7
8; CHECK-LABEL: Function: arr:
9; CHECK-DAG: MayAlias: i32* %alloca, i32* %p0
10; CHECK-DAG: NoAlias: i32* %alloca, i32* %p1
11define void @arr() {
12 %alloca = alloca i32, i32 4
13 %random = call i32* @random.i32(i32* %alloca)
14 %p0 = getelementptr inbounds i32, i32* %random, i32 0
15 %p1 = getelementptr inbounds i32, i32* %random, i32 1
16 ret void
17}
18
19; CHECK-LABEL: Function: arg:
20; CHECK-DAG: MayAlias: i32* %arg, i32* %p0
21; CHECK-DAG: MayAlias: i32* %arg, i32* %p1
22define void @arg(i32* %arg) {
23 %random = call i32* @random.i32(i32* %arg)
24 %p0 = getelementptr inbounds i32, i32* %random, i32 0
25 %p1 = getelementptr inbounds i32, i32* %random, i32 1
26 ret void
27}
28
Michael Kupersteinae214912016-05-26 19:30:49 +000029@gv = global i32 1
30; CHECK-LABEL: Function: global:
31; CHECK-DAG: MayAlias: i32* %p0, i32* @gv
32; CHECK-DAG: NoAlias: i32* %p1, i32* @gv
33define void @global() {
34 %random = call i32* @random.i32(i32* @gv)
35 %p0 = getelementptr inbounds i32, i32* %random, i32 0
36 %p1 = getelementptr inbounds i32, i32* %random, i32 1
37 ret void
38}
39
Michael Kuperstein82069c42016-05-25 22:23:08 +000040; CHECK-LABEL: Function: struct:
41; CHECK-DAG: MayAlias: i32* %f0, i32* %p0
42; CHECK-DAG: MayAlias: i32* %f1, i32* %p0
43; CHECK-DAG: NoAlias: i32* %f0, i32* %p1
44; CHECK-DAG: MayAlias: i32* %f1, i32* %p1
45%struct = type { i32, i32, i32 }
46define void @struct() {
47 %alloca = alloca %struct
48 %alloca.i32 = bitcast %struct* %alloca to i32*
49 %random = call i32* @random.i32(i32* %alloca.i32)
50 %f0 = getelementptr inbounds %struct, %struct* %alloca, i32 0, i32 0
51 %f1 = getelementptr inbounds %struct, %struct* %alloca, i32 0, i32 1
52 %p0 = getelementptr inbounds i32, i32* %random, i32 0
53 %p1 = getelementptr inbounds i32, i32* %random, i32 1
54 ret void
55}
56
57; CHECK-LABEL: Function: complex1:
58; CHECK-DAG: MayAlias: i32* %a2.0, i32* %r2.0
59; CHECK-DAG: NoAlias: i32* %a2.0, i32* %r2.1
60; CHECK-DAG: MayAlias: i32* %a2.0, i32* %r2.i
61; CHECK-DAG: MayAlias: i32* %a2.0, i32* %r2.1i
62; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.0
63; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.1
Shiva Chenc84e77a2018-04-16 01:58:39 +000064; CHECK-DAG: MayAlias: i32* %a1, i32* %r2.i
65; CHECK-DAG: MayAlias: i32* %a1, i32* %r2.1i
Michael Kuperstein82069c42016-05-25 22:23:08 +000066%complex = type { i32, i32, [4 x i32] }
67define void @complex1(i32 %i) {
68 %alloca = alloca %complex
69 %alloca.i32 = bitcast %complex* %alloca to i32*
70 %r.i32 = call i32* @random.i32(i32* %alloca.i32)
71 %random = bitcast i32* %r.i32 to %complex*
72 %a1 = getelementptr inbounds %complex, %complex* %alloca, i32 0, i32 1
73 %a2.0 = getelementptr inbounds %complex, %complex* %alloca, i32 0, i32 2, i32 0
74 %r2.0 = getelementptr inbounds %complex, %complex* %random, i32 0, i32 2, i32 0
75 %r2.1 = getelementptr inbounds %complex, %complex* %random, i32 0, i32 2, i32 1
76 %r2.i = getelementptr inbounds %complex, %complex* %random, i32 0, i32 2, i32 %i
77 %r2.1i = getelementptr inbounds i32, i32* %r2.1, i32 %i
78 ret void
79}
80
81; CHECK-LABEL: Function: complex2:
Shiva Chenc84e77a2018-04-16 01:58:39 +000082; CHECK-DAG: NoAlias: i32* %alloca, i32* %p120
83; CHECK-DAG: MayAlias: i32* %alloca, i32* %pi20
84; CHECK-DAG: MayAlias: i32* %alloca, i32* %pij1
Michael Kuperstein82069c42016-05-25 22:23:08 +000085; CHECK-DAG: MayAlias: i32* %a3, i32* %pij1
86%inner = type { i32, i32 }
87%outer = type { i32, i32, [10 x %inner] }
88declare %outer* @rand_outer(i32* %p)
89define void @complex2(i32 %i, i32 %j) {
90 %alloca = alloca i32, i32 128
91 %a3 = getelementptr inbounds i32, i32* %alloca, i32 3
92 %random = call %outer* @rand_outer(i32* %alloca)
93 %p120 = getelementptr inbounds %outer, %outer* %random, i32 1, i32 2, i32 2, i32 0
94 %pi20 = getelementptr inbounds %outer, %outer* %random, i32 %i, i32 2, i32 2, i32 0
95 %pij1 = getelementptr inbounds %outer, %outer* %random, i32 %i, i32 2, i32 %j, i32 1
96 ret void
97}
98
Shiva Chenc84e77a2018-04-16 01:58:39 +000099; CHECK-LABEL: Function: pointer_offset:
100; CHECK-DAG: MayAlias: i32** %add.ptr, i32** %p1
101; CHECK-DAG: MayAlias: i32** %add.ptr, i32** %q2
102%struct.X = type { i32*, i32* }
103define i32 @pointer_offset(i32 signext %i, i32 signext %j, i32 zeroext %off) {
104entry:
105 %i.addr = alloca i32
106 %j.addr = alloca i32
107 %x = alloca %struct.X
108 store i32 %i, i32* %i.addr
109 store i32 %j, i32* %j.addr
110 %0 = bitcast %struct.X* %x to i8*
111 %p1 = getelementptr inbounds %struct.X, %struct.X* %x, i32 0, i32 0
112 store i32* %i.addr, i32** %p1
113 %q2 = getelementptr inbounds %struct.X, %struct.X* %x, i32 0, i32 1
114 store i32* %j.addr, i32** %q2
115 %add.ptr = getelementptr inbounds i32*, i32** %q2, i32 %off
116 %1 = load i32*, i32** %add.ptr
117 %2 = load i32, i32* %1
118 ret i32 %2
119}