1 // RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(test-alias-analysis))' -split-input-file -allow-unregistered-dialect 2>&1 | FileCheck %s
3 // CHECK-LABEL: Testing : "simple"
4 // CHECK-DAG: func.region0#0 <-> func.region0#1: MayAlias
6 // CHECK-DAG: alloca_1#0 <-> alloca_2#0: NoAlias
7 // CHECK-DAG: alloca_1#0 <-> alloc_1#0: NoAlias
8 // CHECK-DAG: alloca_1#0 <-> alloc_2#0: NoAlias
9 // CHECK-DAG: alloca_1#0 <-> func.region0#0: NoAlias
10 // CHECK-DAG: alloca_1#0 <-> func.region0#1: NoAlias
12 // CHECK-DAG: alloca_2#0 <-> alloc_1#0: NoAlias
13 // CHECK-DAG: alloca_2#0 <-> alloc_2#0: NoAlias
14 // CHECK-DAG: alloca_2#0 <-> func.region0#0: NoAlias
15 // CHECK-DAG: alloca_2#0 <-> func.region0#1: NoAlias
17 // CHECK-DAG: alloc_1#0 <-> alloc_2#0: NoAlias
18 // CHECK-DAG: alloc_1#0 <-> func.region0#0: NoAlias
19 // CHECK-DAG: alloc_1#0 <-> func.region0#1: NoAlias
21 // CHECK-DAG: alloc_2#0 <-> func.region0#0: NoAlias
22 // CHECK-DAG: alloc_2#0 <-> func.region0#1: NoAlias
23 func.func @simple(%arg: memref<2xf32>, %arg1: memref<2xf32>) attributes {test.ptr = "func"} {
24 %0 = memref.alloca() {test.ptr = "alloca_1"} : memref<8x64xf32>
25 %1 = memref.alloca() {test.ptr = "alloca_2"} : memref<8x64xf32>
26 %2 = memref.alloc() {test.ptr = "alloc_1"} : memref<8x64xf32>
27 %3 = memref.alloc() {test.ptr = "alloc_2"} : memref<8x64xf32>
33 // CHECK-LABEL: Testing : "control_flow"
34 // CHECK-DAG: alloca_1#0 <-> func.region0.block1#0: MustAlias
35 // CHECK-DAG: alloca_1#0 <-> func.region0.block2#0: MustAlias
37 // CHECK-DAG: alloca_2#0 <-> func.region0.block1#0: NoAlias
38 // CHECK-DAG: alloca_2#0 <-> func.region0.block2#0: NoAlias
40 // CHECK-DAG: alloc_1#0 <-> func.region0.block1#0: NoAlias
41 // CHECK-DAG: alloc_1#0 <-> func.region0.block2#0: NoAlias
43 // CHECK-DAG: func.region0#0 <-> func.region0.block1#0: NoAlias
44 // CHECK-DAG: func.region0#0 <-> func.region0.block2#0: NoAlias
46 // CHECK-DAG: func.region0#1 <-> func.region0.block1#0: NoAlias
47 // CHECK-DAG: func.region0#1 <-> func.region0.block2#0: NoAlias
49 // CHECK-DAG: func.region0.block1#0 <-> func.region0.block2#0: MustAlias
50 func.func @control_flow(%arg: memref<2xf32>, %cond: i1) attributes {test.ptr = "func"} {
51 %0 = memref.alloca() {test.ptr = "alloca_1"} : memref<8x64xf32>
52 %1 = memref.alloca() {test.ptr = "alloca_2"} : memref<8x64xf32>
53 %2 = memref.alloc() {test.ptr = "alloc_1"} : memref<8x64xf32>
55 cf.cond_br %cond, ^bb1(%0 : memref<8x64xf32>), ^bb2(%0 : memref<8x64xf32>)
57 ^bb1(%arg1: memref<8x64xf32>):
58 cf.br ^bb2(%arg1 : memref<8x64xf32>)
60 ^bb2(%arg2: memref<8x64xf32>):
66 // CHECK-LABEL: Testing : "control_flow_merge"
67 // CHECK-DAG: alloca_1#0 <-> func.region0.block1#0: MustAlias
68 // CHECK-DAG: alloca_1#0 <-> func.region0.block2#0: MayAlias
70 // CHECK-DAG: alloca_2#0 <-> func.region0.block1#0: NoAlias
71 // CHECK-DAG: alloca_2#0 <-> func.region0.block2#0: NoAlias
73 // CHECK-DAG: alloc_1#0 <-> func.region0.block1#0: NoAlias
74 // CHECK-DAG: alloc_1#0 <-> func.region0.block2#0: MayAlias
76 // CHECK-DAG: func.region0#0 <-> func.region0.block1#0: NoAlias
77 // CHECK-DAG: func.region0#0 <-> func.region0.block2#0: NoAlias
79 // CHECK-DAG: func.region0#1 <-> func.region0.block1#0: NoAlias
80 // CHECK-DAG: func.region0#1 <-> func.region0.block2#0: NoAlias
82 // CHECK-DAG: func.region0.block1#0 <-> func.region0.block2#0: MayAlias
83 func.func @control_flow_merge(%arg: memref<2xf32>, %cond: i1) attributes {test.ptr = "func"} {
84 %0 = memref.alloca() {test.ptr = "alloca_1"} : memref<8x64xf32>
85 %1 = memref.alloca() {test.ptr = "alloca_2"} : memref<8x64xf32>
86 %2 = memref.alloc() {test.ptr = "alloc_1"} : memref<8x64xf32>
88 cf.cond_br %cond, ^bb1(%0 : memref<8x64xf32>), ^bb2(%2 : memref<8x64xf32>)
90 ^bb1(%arg1: memref<8x64xf32>):
91 cf.br ^bb2(%arg1 : memref<8x64xf32>)
93 ^bb2(%arg2: memref<8x64xf32>):
99 // CHECK-LABEL: Testing : "region_control_flow"
100 // CHECK-DAG: alloca_1#0 <-> if_alloca#0: MustAlias
101 // CHECK-DAG: alloca_1#0 <-> if_alloca_merge#0: MayAlias
102 // CHECK-DAG: alloca_1#0 <-> if_alloc#0: NoAlias
104 // CHECK-DAG: alloca_2#0 <-> if_alloca#0: NoAlias
105 // CHECK-DAG: alloca_2#0 <-> if_alloca_merge#0: MayAlias
106 // CHECK-DAG: alloca_2#0 <-> if_alloc#0: NoAlias
108 // CHECK-DAG: alloc_1#0 <-> if_alloca#0: NoAlias
109 // CHECK-DAG: alloc_1#0 <-> if_alloca_merge#0: NoAlias
110 // CHECK-DAG: alloc_1#0 <-> if_alloc#0: MustAlias
112 // CHECK-DAG: if_alloca#0 <-> if_alloca_merge#0: MayAlias
113 // CHECK-DAG: if_alloca#0 <-> if_alloc#0: NoAlias
114 // CHECK-DAG: if_alloca#0 <-> func.region0#0: NoAlias
115 // CHECK-DAG: if_alloca#0 <-> func.region0#1: NoAlias
117 // CHECK-DAG: if_alloca_merge#0 <-> if_alloc#0: NoAlias
118 // CHECK-DAG: if_alloca_merge#0 <-> func.region0#0: NoAlias
119 // CHECK-DAG: if_alloca_merge#0 <-> func.region0#1: NoAlias
121 // CHECK-DAG: if_alloc#0 <-> func.region0#0: NoAlias
122 // CHECK-DAG: if_alloc#0 <-> func.region0#1: NoAlias
123 func.func @region_control_flow(%arg: memref<2xf32>, %cond: i1) attributes {test.ptr = "func"} {
124 %0 = memref.alloca() {test.ptr = "alloca_1"} : memref<8x64xf32>
125 %1 = memref.alloca() {test.ptr = "alloca_2"} : memref<8x64xf32>
126 %2 = memref.alloc() {test.ptr = "alloc_1"} : memref<8x64xf32>
128 %3 = scf.if %cond -> (memref<8x64xf32>) {
129 scf.yield %0 : memref<8x64xf32>
131 scf.yield %0 : memref<8x64xf32>
132 } {test.ptr = "if_alloca"}
134 %4 = scf.if %cond -> (memref<8x64xf32>) {
135 scf.yield %0 : memref<8x64xf32>
137 scf.yield %1 : memref<8x64xf32>
138 } {test.ptr = "if_alloca_merge"}
140 %5 = scf.if %cond -> (memref<8x64xf32>) {
141 scf.yield %2 : memref<8x64xf32>
143 scf.yield %2 : memref<8x64xf32>
144 } {test.ptr = "if_alloc"}
150 // CHECK-LABEL: Testing : "region_loop_control_flow"
151 // CHECK-DAG: alloca_1#0 <-> for_alloca#0: MustAlias
152 // CHECK-DAG: alloca_1#0 <-> for_alloca.region0#0: MayAlias
153 // CHECK-DAG: alloca_1#0 <-> for_alloca.region0#1: MustAlias
155 // CHECK-DAG: alloca_2#0 <-> for_alloca#0: NoAlias
156 // CHECK-DAG: alloca_2#0 <-> for_alloca.region0#0: MayAlias
157 // CHECK-DAG: alloca_2#0 <-> for_alloca.region0#1: NoAlias
159 // CHECK-DAG: alloc_1#0 <-> for_alloca#0: NoAlias
160 // CHECK-DAG: alloc_1#0 <-> for_alloca.region0#0: MayAlias
161 // CHECK-DAG: alloc_1#0 <-> for_alloca.region0#1: NoAlias
163 // CHECK-DAG: for_alloca#0 <-> for_alloca.region0#0: MayAlias
164 // CHECK-DAG: for_alloca#0 <-> for_alloca.region0#1: MustAlias
165 // CHECK-DAG: for_alloca#0 <-> func.region0#0: NoAlias
166 // CHECK-DAG: for_alloca#0 <-> func.region0#1: NoAlias
167 // CHECK-DAG: for_alloca#0 <-> func.region0#2: NoAlias
168 // CHECK-DAG: for_alloca#0 <-> func.region0#3: NoAlias
170 // CHECK-DAG: for_alloca.region0#0 <-> for_alloca.region0#1: MayAlias
171 // CHECK-DAG: for_alloca.region0#0 <-> func.region0#0: MayAlias
172 // CHECK-DAG: for_alloca.region0#0 <-> func.region0#1: MayAlias
173 // CHECK-DAG: for_alloca.region0#0 <-> func.region0#2: MayAlias
174 // CHECK-DAG: for_alloca.region0#0 <-> func.region0#3: MayAlias
176 // CHECK-DAG: for_alloca.region0#1 <-> func.region0#0: NoAlias
177 // CHECK-DAG: for_alloca.region0#1 <-> func.region0#1: NoAlias
178 // CHECK-DAG: for_alloca.region0#1 <-> func.region0#2: NoAlias
179 // CHECK-DAG: for_alloca.region0#1 <-> func.region0#3: NoAlias
180 func.func @region_loop_control_flow(%arg: memref<2xf32>, %loopI0 : index,
181 %loopI1 : index, %loopI2 : index) attributes {test.ptr = "func"} {
182 %0 = memref.alloca() {test.ptr = "alloca_1"} : memref<8x64xf32>
183 %1 = memref.alloca() {test.ptr = "alloca_2"} : memref<8x64xf32>
184 %2 = memref.alloc() {test.ptr = "alloc_1"} : memref<8x64xf32>
186 %result = scf.for %i0 = %loopI0 to %loopI1 step %loopI2 iter_args(%si = %0) -> (memref<8x64xf32>) {
187 scf.yield %si : memref<8x64xf32>
188 } {test.ptr = "for_alloca"}
194 // CHECK-LABEL: Testing : "region_loop_zero_trip_count"
195 // CHECK-DAG: alloca_1#0 <-> alloca_2#0: NoAlias
196 // CHECK-DAG: alloca_1#0 <-> for_alloca#0: MustAlias
197 // CHECK-DAG: alloca_1#0 <-> for_alloca.region0#0: MayAlias
198 // CHECK-DAG: alloca_1#0 <-> for_alloca.region0#1: MayAlias
200 // CHECK-DAG: alloca_2#0 <-> for_alloca#0: NoAlias
201 // CHECK-DAG: alloca_2#0 <-> for_alloca.region0#0: MayAlias
202 // CHECK-DAG: alloca_2#0 <-> for_alloca.region0#1: MayAlias
204 // CHECK-DAG: for_alloca#0 <-> for_alloca.region0#0: MayAlias
205 // CHECK-DAG: for_alloca#0 <-> for_alloca.region0#1: MayAlias
207 // CHECK-DAG: for_alloca.region0#0 <-> for_alloca.region0#1: MayAlias
208 func.func @region_loop_zero_trip_count() attributes {test.ptr = "func"} {
209 %0 = memref.alloca() {test.ptr = "alloca_1"} : memref<i32>
210 %1 = memref.alloca() {test.ptr = "alloca_2"} : memref<i32>
211 %result = affine.for %i = 0 to 0 iter_args(%si = %0) -> (memref<i32>) {
212 affine.yield %si : memref<i32>
213 } {test.ptr = "for_alloca"}
219 // CHECK-LABEL: Testing : "view_like"
220 // CHECK-DAG: alloc_1#0 <-> view#0: NoAlias
222 // CHECK-DAG: alloca_1#0 <-> view#0: MustAlias
224 // CHECK-DAG: view#0 <-> func.region0#0: NoAlias
225 // CHECK-DAG: view#0 <-> func.region0#1: NoAlias
226 func.func @view_like(%arg: memref<2xf32>, %size: index) attributes {test.ptr = "func"} {
227 %1 = memref.alloc() {test.ptr = "alloc_1"} : memref<8x64xf32>
229 %c0 = arith.constant 0 : index
230 %2 = memref.alloca (%size) {test.ptr = "alloca_1"} : memref<?xi8>
231 %3 = memref.view %2[%c0][] {test.ptr = "view"} : memref<?xi8> to memref<8x64xf32>
237 // CHECK-LABEL: Testing : "constants"
238 // CHECK-DAG: alloc_1#0 <-> constant_1#0: NoAlias
239 // CHECK-DAG: alloc_1#0 <-> constant_2#0: NoAlias
240 // CHECK-DAG: alloc_1#0 <-> constant_3#0: NoAlias
242 // CHECK-DAG: constant_1#0 <-> constant_2#0: MayAlias
243 // CHECK-DAG: constant_1#0 <-> constant_3#0: MayAlias
244 // CHECK-DAG: constant_1#0 <-> func.region0#0: MayAlias
246 // CHECK-DAG: constant_2#0 <-> constant_3#0: MayAlias
247 // CHECK-DAG: constant_2#0 <-> func.region0#0: MayAlias
249 // CHECK-DAG: constant_3#0 <-> func.region0#0: MayAlias
250 func.func @constants(%arg: memref<2xf32>) attributes {test.ptr = "func"} {
251 %1 = memref.alloc() {test.ptr = "alloc_1"} : memref<8x64xf32>
253 %c0 = arith.constant {test.ptr = "constant_1"} 0 : index
254 %c0_2 = arith.constant {test.ptr = "constant_2"} 0 : index
255 %c1 = arith.constant {test.ptr = "constant_3"} 1 : index