[BasicAA] Try to disambiguate GEPs through arrays of structs into
[oota-llvm.git] / test / Analysis / BasicAA / struct-geps.ll
1 ; RUN: opt < %s -basicaa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
2
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4
5 %struct = type { i32, i32, i32 }
6
7 ; CHECK-LABEL: test_simple
8
9 ; CHECK-DAG: PartialAlias: %struct* %st, i32* %x
10 ; CHECK-DAG: PartialAlias: %struct* %st, i32* %y
11 ; CHECK-DAG: PartialAlias: %struct* %st, i32* %z
12
13 ; CHECK-DAG: NoAlias: i32* %x, i32* %y
14 ; CHECK-DAG: NoAlias: i32* %x, i32* %z
15 ; CHECK-DAG: NoAlias: i32* %y, i32* %z
16
17 ; CHECK-DAG: PartialAlias: %struct* %st, %struct* %y_12
18 ; CHECK-DAG: PartialAlias: %struct* %y_12, i32* %x
19 ; CHECK-DAG: PartialAlias: i32* %x, i80* %y_10
20
21 ; CHECK-DAG: PartialAlias: %struct* %st, i64* %y_8
22 ; CHECK-DAG: PartialAlias: i32* %z, i64* %y_8
23 ; CHECK-DAG: NoAlias: i32* %x, i64* %y_8
24
25 ; CHECK-DAG: MustAlias: %struct* %y_12, i32* %y
26 ; CHECK-DAG: MustAlias: i32* %y, i64* %y_8
27 ; CHECK-DAG: MustAlias: i32* %y, i80* %y_10
28
29 define void @test_simple(%struct* %st, i64 %i, i64 %j, i64 %k) {
30   %x = getelementptr %struct* %st, i64 %i, i32 0
31   %y = getelementptr %struct* %st, i64 %j, i32 1
32   %z = getelementptr %struct* %st, i64 %k, i32 2
33   %y_12 = bitcast i32* %y to %struct*
34   %y_10 = bitcast i32* %y to i80*
35   %y_8 = bitcast i32* %y to i64*
36   ret void
37 }
38
39 ; CHECK-LABEL: test_in_array
40
41 ; CHECK-DAG: PartialAlias: [1 x %struct]* %st, i32* %x
42 ; CHECK-DAG: PartialAlias: [1 x %struct]* %st, i32* %y
43 ; CHECK-DAG: PartialAlias: [1 x %struct]* %st, i32* %z
44
45 ; CHECK-DAG: NoAlias: i32* %x, i32* %y
46 ; CHECK-DAG: NoAlias: i32* %x, i32* %z
47 ; CHECK-DAG: NoAlias: i32* %y, i32* %z
48
49 ; CHECK-DAG: PartialAlias: %struct* %y_12, [1 x %struct]* %st
50 ; CHECK-DAG: PartialAlias: %struct* %y_12, i32* %x
51 ; CHECK-DAG: PartialAlias: i32* %x, i80* %y_10
52
53 ; CHECK-DAG: PartialAlias: [1 x %struct]* %st, i64* %y_8
54 ; CHECK-DAG: PartialAlias: i32* %z, i64* %y_8
55 ; CHECK-DAG: NoAlias: i32* %x, i64* %y_8
56
57 ; CHECK-DAG: MustAlias: %struct* %y_12, i32* %y
58 ; CHECK-DAG: MustAlias: i32* %y, i64* %y_8
59 ; CHECK-DAG: MustAlias: i32* %y, i80* %y_10
60
61 define void @test_in_array([1 x %struct]* %st, i64 %i, i64 %j, i64 %k, i64 %i1, i64 %j1, i64 %k1) {
62   %x = getelementptr [1 x %struct]* %st, i64 %i, i64 %i1, i32 0
63   %y = getelementptr [1 x %struct]* %st, i64 %j, i64 %j1, i32 1
64   %z = getelementptr [1 x %struct]* %st, i64 %k, i64 %k1, i32 2
65   %y_12 = bitcast i32* %y to %struct*
66   %y_10 = bitcast i32* %y to i80*
67   %y_8 = bitcast i32* %y to i64*
68   ret void
69 }
70
71 ; CHECK-LABEL: test_in_3d_array
72
73 ; CHECK-DAG: PartialAlias: [1 x [1 x [1 x %struct]]]* %st, i32* %x
74 ; CHECK-DAG: PartialAlias: [1 x [1 x [1 x %struct]]]* %st, i32* %y
75 ; CHECK-DAG: PartialAlias: [1 x [1 x [1 x %struct]]]* %st, i32* %z
76
77 ; CHECK-DAG: NoAlias: i32* %x, i32* %y
78 ; CHECK-DAG: NoAlias: i32* %x, i32* %z
79 ; CHECK-DAG: NoAlias: i32* %y, i32* %z
80
81 ; CHECK-DAG: PartialAlias: %struct* %y_12, [1 x [1 x [1 x %struct]]]* %st
82 ; CHECK-DAG: PartialAlias: %struct* %y_12, i32* %x
83 ; CHECK-DAG: PartialAlias: i32* %x, i80* %y_10
84
85 ; CHECK-DAG: PartialAlias: [1 x [1 x [1 x %struct]]]* %st, i64* %y_8
86 ; CHECK-DAG: PartialAlias: i32* %z, i64* %y_8
87 ; CHECK-DAG: NoAlias: i32* %x, i64* %y_8
88
89 ; CHECK-DAG: MustAlias: %struct* %y_12, i32* %y
90 ; CHECK-DAG: MustAlias: i32* %y, i64* %y_8
91 ; CHECK-DAG: MustAlias: i32* %y, i80* %y_10
92
93 define void @test_in_3d_array([1 x [1 x [1 x %struct]]]* %st, i64 %i, i64 %j, i64 %k, i64 %i1, i64 %j1, i64 %k1, i64 %i2, i64 %j2, i64 %k2, i64 %i3, i64 %j3, i64 %k3) {
94   %x = getelementptr [1 x [1 x [1 x %struct]]]* %st, i64 %i, i64 %i1, i64 %i2, i64 %i3, i32 0
95   %y = getelementptr [1 x [1 x [1 x %struct]]]* %st, i64 %j, i64 %j1, i64 %j2, i64 %j3, i32 1
96   %z = getelementptr [1 x [1 x [1 x %struct]]]* %st, i64 %k, i64 %k1, i64 %k2, i64 %k3, i32 2
97   %y_12 = bitcast i32* %y to %struct*
98   %y_10 = bitcast i32* %y to i80*
99   %y_8 = bitcast i32* %y to i64*
100   ret void
101 }
102
103 ; CHECK-LABEL: test_same_underlying_object_same_indices
104
105 ; CHECK-DAG: NoAlias: i32* %x, i32* %x2
106 ; CHECK-DAG: NoAlias: i32* %y, i32* %y2
107 ; CHECK-DAG: NoAlias: i32* %z, i32* %z2
108
109 ; CHECK-DAG: PartialAlias: i32* %x, i32* %y2
110 ; CHECK-DAG: PartialAlias: i32* %x, i32* %z2
111
112 ; CHECK-DAG: PartialAlias: i32* %x2, i32* %y
113 ; CHECK-DAG: PartialAlias: i32* %y, i32* %z2
114
115 ; CHECK-DAG: PartialAlias: i32* %x2, i32* %z
116 ; CHECK-DAG: PartialAlias: i32* %y2, i32* %z
117
118 define void @test_same_underlying_object_same_indices(%struct* %st, i64 %i, i64 %j, i64 %k) {
119   %st2 = getelementptr %struct* %st, i32 10
120   %x2 = getelementptr %struct* %st2, i64 %i, i32 0
121   %y2 = getelementptr %struct* %st2, i64 %j, i32 1
122   %z2 = getelementptr %struct* %st2, i64 %k, i32 2
123   %x = getelementptr %struct* %st, i64 %i, i32 0
124   %y = getelementptr %struct* %st, i64 %j, i32 1
125   %z = getelementptr %struct* %st, i64 %k, i32 2
126   ret void
127 }
128
129 ; CHECK-LABEL: test_same_underlying_object_different_indices
130
131 ; CHECK-DAG: PartialAlias: i32* %x, i32* %x2
132 ; CHECK-DAG: PartialAlias: i32* %y, i32* %y2
133 ; CHECK-DAG: PartialAlias: i32* %z, i32* %z2
134
135 ; CHECK-DAG: PartialAlias: i32* %x, i32* %y2
136 ; CHECK-DAG: PartialAlias: i32* %x, i32* %z2
137
138 ; CHECK-DAG: PartialAlias: i32* %x2, i32* %y
139 ; CHECK-DAG: PartialAlias: i32* %y, i32* %z2
140
141 ; CHECK-DAG: PartialAlias: i32* %x2, i32* %z
142 ; CHECK-DAG: PartialAlias: i32* %y2, i32* %z
143
144 define void @test_same_underlying_object_different_indices(%struct* %st, i64 %i1, i64 %j1, i64 %k1, i64 %i2, i64 %k2, i64 %j2) {
145   %st2 = getelementptr %struct* %st, i32 10
146   %x2 = getelementptr %struct* %st2, i64 %i2, i32 0
147   %y2 = getelementptr %struct* %st2, i64 %j2, i32 1
148   %z2 = getelementptr %struct* %st2, i64 %k2, i32 2
149   %x = getelementptr %struct* %st, i64 %i1, i32 0
150   %y = getelementptr %struct* %st, i64 %j1, i32 1
151   %z = getelementptr %struct* %st, i64 %k1, i32 2
152   ret void
153 }
154
155
156 %struct2 = type { [1 x { i32, i32 }], [2 x { i32 }] }
157
158 ; CHECK-LABEL: test_struct_in_array
159 ; CHECK-DAG: MustAlias: i32* %x, i32* %y
160 define void @test_struct_in_array(%struct2* %st, i64 %i, i64 %j, i64 %k) {
161   %x = getelementptr %struct2* %st, i32 0, i32 1, i32 1, i32 0
162   %y = getelementptr %struct2* %st, i32 0, i32 0, i32 1, i32 1
163   ret void
164 }