275 lines · plain
1// RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(test-alias-analysis))' -split-input-file -allow-unregistered-dialect 2>&1 | FileCheck %s2 3// CHECK-LABEL: Testing : "simple"4// CHECK-DAG: func.region0#0 <-> func.region0#1: MayAlias5 6// CHECK-DAG: alloca_1#0 <-> alloca_2#0: NoAlias7// CHECK-DAG: alloca_1#0 <-> alloc_1#0: NoAlias8// CHECK-DAG: alloca_1#0 <-> alloc_2#0: NoAlias9// CHECK-DAG: alloca_1#0 <-> func.region0#0: NoAlias10// CHECK-DAG: alloca_1#0 <-> func.region0#1: NoAlias11 12// CHECK-DAG: alloca_2#0 <-> alloc_1#0: NoAlias13// CHECK-DAG: alloca_2#0 <-> alloc_2#0: NoAlias14// CHECK-DAG: alloca_2#0 <-> func.region0#0: NoAlias15// CHECK-DAG: alloca_2#0 <-> func.region0#1: NoAlias16 17// CHECK-DAG: alloc_1#0 <-> alloc_2#0: NoAlias18// CHECK-DAG: alloc_1#0 <-> func.region0#0: NoAlias19// CHECK-DAG: alloc_1#0 <-> func.region0#1: NoAlias20 21// CHECK-DAG: alloc_2#0 <-> func.region0#0: NoAlias22// CHECK-DAG: alloc_2#0 <-> func.region0#1: NoAlias23func.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>28 return29}30 31// -----32 33// CHECK-LABEL: Testing : "control_flow"34// CHECK-DAG: alloca_1#0 <-> func.region0.block1#0: MustAlias35// CHECK-DAG: alloca_1#0 <-> func.region0.block2#0: MustAlias36 37// CHECK-DAG: alloca_2#0 <-> func.region0.block1#0: NoAlias38// CHECK-DAG: alloca_2#0 <-> func.region0.block2#0: NoAlias39 40// CHECK-DAG: alloc_1#0 <-> func.region0.block1#0: NoAlias41// CHECK-DAG: alloc_1#0 <-> func.region0.block2#0: NoAlias42 43// CHECK-DAG: func.region0#0 <-> func.region0.block1#0: NoAlias44// CHECK-DAG: func.region0#0 <-> func.region0.block2#0: NoAlias45 46// CHECK-DAG: func.region0#1 <-> func.region0.block1#0: NoAlias47// CHECK-DAG: func.region0#1 <-> func.region0.block2#0: NoAlias48 49// CHECK-DAG: func.region0.block1#0 <-> func.region0.block2#0: MustAlias50func.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>54 55 cf.cond_br %cond, ^bb1(%0 : memref<8x64xf32>), ^bb2(%0 : memref<8x64xf32>)56 57^bb1(%arg1: memref<8x64xf32>):58 cf.br ^bb2(%arg1 : memref<8x64xf32>)59 60^bb2(%arg2: memref<8x64xf32>):61 return62}63 64// -----65 66// CHECK-LABEL: Testing : "control_flow_merge"67// CHECK-DAG: alloca_1#0 <-> func.region0.block1#0: MustAlias68// CHECK-DAG: alloca_1#0 <-> func.region0.block2#0: MayAlias69 70// CHECK-DAG: alloca_2#0 <-> func.region0.block1#0: NoAlias71// CHECK-DAG: alloca_2#0 <-> func.region0.block2#0: NoAlias72 73// CHECK-DAG: alloc_1#0 <-> func.region0.block1#0: NoAlias74// CHECK-DAG: alloc_1#0 <-> func.region0.block2#0: MayAlias75 76// CHECK-DAG: func.region0#0 <-> func.region0.block1#0: NoAlias77// CHECK-DAG: func.region0#0 <-> func.region0.block2#0: NoAlias78 79// CHECK-DAG: func.region0#1 <-> func.region0.block1#0: NoAlias80// CHECK-DAG: func.region0#1 <-> func.region0.block2#0: NoAlias81 82// CHECK-DAG: func.region0.block1#0 <-> func.region0.block2#0: MayAlias83func.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>87 88 cf.cond_br %cond, ^bb1(%0 : memref<8x64xf32>), ^bb2(%2 : memref<8x64xf32>)89 90^bb1(%arg1: memref<8x64xf32>):91 cf.br ^bb2(%arg1 : memref<8x64xf32>)92 93^bb2(%arg2: memref<8x64xf32>):94 return95}96 97// -----98 99// CHECK-LABEL: Testing : "region_control_flow"100// CHECK-DAG: alloca_1#0 <-> if_alloca#0: MustAlias101// CHECK-DAG: alloca_1#0 <-> if_alloca_merge#0: MayAlias102// CHECK-DAG: alloca_1#0 <-> if_alloc#0: NoAlias103 104// CHECK-DAG: alloca_2#0 <-> if_alloca#0: NoAlias105// CHECK-DAG: alloca_2#0 <-> if_alloca_merge#0: MayAlias106// CHECK-DAG: alloca_2#0 <-> if_alloc#0: NoAlias107 108// CHECK-DAG: alloc_1#0 <-> if_alloca#0: NoAlias109// CHECK-DAG: alloc_1#0 <-> if_alloca_merge#0: NoAlias110// CHECK-DAG: alloc_1#0 <-> if_alloc#0: MustAlias111 112// CHECK-DAG: if_alloca#0 <-> if_alloca_merge#0: MayAlias113// CHECK-DAG: if_alloca#0 <-> if_alloc#0: NoAlias114// CHECK-DAG: if_alloca#0 <-> func.region0#0: NoAlias115// CHECK-DAG: if_alloca#0 <-> func.region0#1: NoAlias116 117// CHECK-DAG: if_alloca_merge#0 <-> if_alloc#0: NoAlias118// CHECK-DAG: if_alloca_merge#0 <-> func.region0#0: NoAlias119// CHECK-DAG: if_alloca_merge#0 <-> func.region0#1: NoAlias120 121// CHECK-DAG: if_alloc#0 <-> func.region0#0: NoAlias122// CHECK-DAG: if_alloc#0 <-> func.region0#1: NoAlias123func.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>127 128 %3 = scf.if %cond -> (memref<8x64xf32>) {129 scf.yield %0 : memref<8x64xf32>130 } else {131 scf.yield %0 : memref<8x64xf32>132 } {test.ptr = "if_alloca"}133 134 %4 = scf.if %cond -> (memref<8x64xf32>) {135 scf.yield %0 : memref<8x64xf32>136 } else {137 scf.yield %1 : memref<8x64xf32>138 } {test.ptr = "if_alloca_merge"}139 140 %5 = scf.if %cond -> (memref<8x64xf32>) {141 scf.yield %2 : memref<8x64xf32>142 } else {143 scf.yield %2 : memref<8x64xf32>144 } {test.ptr = "if_alloc"}145 return146}147 148// -----149 150// CHECK-LABEL: Testing : "region_loop_control_flow"151// CHECK-DAG: alloca_1#0 <-> for_alloca#0: MustAlias152// CHECK-DAG: alloca_1#0 <-> for_alloca.region0#0: MayAlias153// CHECK-DAG: alloca_1#0 <-> for_alloca.region0#1: MustAlias154 155// CHECK-DAG: alloca_2#0 <-> for_alloca#0: NoAlias156// CHECK-DAG: alloca_2#0 <-> for_alloca.region0#0: MayAlias157// CHECK-DAG: alloca_2#0 <-> for_alloca.region0#1: NoAlias158 159// CHECK-DAG: alloc_1#0 <-> for_alloca#0: NoAlias160// CHECK-DAG: alloc_1#0 <-> for_alloca.region0#0: MayAlias161// CHECK-DAG: alloc_1#0 <-> for_alloca.region0#1: NoAlias162 163// CHECK-DAG: for_alloca#0 <-> for_alloca.region0#0: MayAlias164// CHECK-DAG: for_alloca#0 <-> for_alloca.region0#1: MustAlias165// CHECK-DAG: for_alloca#0 <-> func.region0#0: NoAlias166// CHECK-DAG: for_alloca#0 <-> func.region0#1: NoAlias167// CHECK-DAG: for_alloca#0 <-> func.region0#2: NoAlias168// CHECK-DAG: for_alloca#0 <-> func.region0#3: NoAlias169 170// CHECK-DAG: for_alloca.region0#0 <-> for_alloca.region0#1: MayAlias171// CHECK-DAG: for_alloca.region0#0 <-> func.region0#0: MayAlias172// CHECK-DAG: for_alloca.region0#0 <-> func.region0#1: MayAlias173// CHECK-DAG: for_alloca.region0#0 <-> func.region0#2: MayAlias174// CHECK-DAG: for_alloca.region0#0 <-> func.region0#3: MayAlias175 176// CHECK-DAG: for_alloca.region0#1 <-> func.region0#0: NoAlias177// CHECK-DAG: for_alloca.region0#1 <-> func.region0#1: NoAlias178// CHECK-DAG: for_alloca.region0#1 <-> func.region0#2: NoAlias179// CHECK-DAG: for_alloca.region0#1 <-> func.region0#3: NoAlias180func.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>185 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"}189 return190}191 192// -----193 194// CHECK-LABEL: Testing : "region_loop_zero_trip_count"195// CHECK-DAG: alloca_1#0 <-> alloca_2#0: NoAlias196// CHECK-DAG: alloca_1#0 <-> for_alloca#0: MustAlias197// CHECK-DAG: alloca_1#0 <-> for_alloca.region0#0: MayAlias198// CHECK-DAG: alloca_1#0 <-> for_alloca.region0#1: MayAlias199 200// CHECK-DAG: alloca_2#0 <-> for_alloca#0: NoAlias201// CHECK-DAG: alloca_2#0 <-> for_alloca.region0#0: MayAlias202// CHECK-DAG: alloca_2#0 <-> for_alloca.region0#1: MayAlias203 204// CHECK-DAG: for_alloca#0 <-> for_alloca.region0#0: MayAlias205// CHECK-DAG: for_alloca#0 <-> for_alloca.region0#1: MayAlias206 207// CHECK-DAG: for_alloca.region0#0 <-> for_alloca.region0#1: MayAlias208func.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"}214 return215}216 217// -----218 219// CHECK-LABEL: Testing : "view_like"220// CHECK-DAG: alloc_1#0 <-> view#0: NoAlias221 222// CHECK-DAG: alloca_1#0 <-> view#0: MustAlias223 224// CHECK-DAG: view#0 <-> func.region0#0: NoAlias225// CHECK-DAG: view#0 <-> func.region0#1: NoAlias226func.func @view_like(%arg: memref<2xf32>, %size: index) attributes {test.ptr = "func"} {227 %1 = memref.alloc() {test.ptr = "alloc_1"} : memref<8x64xf32>228 229 %c0 = arith.constant 0 : index230 %2 = memref.alloca (%size) {test.ptr = "alloca_1"} : memref<?xi8>231 %3 = memref.view %2[%c0][] {test.ptr = "view"} : memref<?xi8> to memref<8x64xf32>232 return233}234 235// -----236 237// CHECK-LABEL: Testing : "constants"238// CHECK-DAG: alloc_1#0 <-> constant_1#0: NoAlias239// CHECK-DAG: alloc_1#0 <-> constant_2#0: NoAlias240// CHECK-DAG: alloc_1#0 <-> constant_3#0: NoAlias241 242// CHECK-DAG: constant_1#0 <-> constant_2#0: MayAlias243// CHECK-DAG: constant_1#0 <-> constant_3#0: MayAlias244// CHECK-DAG: constant_1#0 <-> func.region0#0: MayAlias245 246// CHECK-DAG: constant_2#0 <-> constant_3#0: MayAlias247// CHECK-DAG: constant_2#0 <-> func.region0#0: MayAlias248 249// CHECK-DAG: constant_3#0 <-> func.region0#0: MayAlias250func.func @constants(%arg: memref<2xf32>) attributes {test.ptr = "func"} {251 %1 = memref.alloc() {test.ptr = "alloc_1"} : memref<8x64xf32>252 253 %c0 = arith.constant {test.ptr = "constant_1"} 0 : index254 %c0_2 = arith.constant {test.ptr = "constant_2"} 0 : index255 %c1 = arith.constant {test.ptr = "constant_3"} 1 : index256 257 return258}259 260// -----261 262// CHECK-LABEL: Testing : "distinct_objects"263// CHECK-DAG: func.region0#0 <-> func.region0#1: MayAlias264 265// CHECK-DAG: distinct#0 <-> distinct#1: NoAlias266// CHECK-DAG: distinct#0 <-> func.region0#0: MustAlias267// CHECK-DAG: distinct#1 <-> func.region0#0: MayAlias268// CHECK-DAG: distinct#0 <-> func.region0#1: MayAlias269// CHECK-DAG: distinct#1 <-> func.region0#1: MustAlias270 271func.func @distinct_objects(%arg: memref<?xf32>, %arg1: memref<?xf32>) attributes {test.ptr = "func"} {272 %0, %1 = memref.distinct_objects %arg, %arg1 {test.ptr = "distinct"} : memref<?xf32>, memref<?xf32>273 return274}275