1 // RUN: mlir-opt %s -pass-pipeline='builtin.func(test-alias-analysis-modref)' -split-input-file -allow-unregistered-dialect 2>&1 | FileCheck %s
3 // CHECK-LABEL: Testing : "no_side_effects"
4 // CHECK: alloc -> func.region0#0: NoModRef
5 // CHECK: dealloc -> func.region0#0: NoModRef
6 // CHECK: return -> func.region0#0: NoModRef
7 func @no_side_effects(%arg: memref<2xf32>) attributes {test.ptr = "func"} {
8 %1 = memref.alloc() {test.ptr = "alloc"} : memref<8x64xf32>
9 memref.dealloc %1 {test.ptr = "dealloc"} : memref<8x64xf32>
10 return {test.ptr = "return"}
15 // CHECK-LABEL: Testing : "simple"
16 // CHECK-DAG: store -> alloc#0: Mod
17 // CHECK-DAG: load -> alloc#0: Ref
19 // CHECK-DAG: store -> func.region0#0: NoModRef
20 // CHECK-DAG: load -> func.region0#0: NoModRef
21 func @simple(%arg: memref<i32>, %value: i32) attributes {test.ptr = "func"} {
22 %1 = memref.alloca() {test.ptr = "alloc"} : memref<i32>
23 memref.store %value, %1[] {test.ptr = "store"} : memref<i32>
24 %2 = memref.load %1[] {test.ptr = "load"} : memref<i32>
25 return {test.ptr = "return"}
30 // CHECK-LABEL: Testing : "mayalias"
31 // CHECK-DAG: store -> func.region0#0: Mod
32 // CHECK-DAG: load -> func.region0#0: Ref
34 // CHECK-DAG: store -> func.region0#1: Mod
35 // CHECK-DAG: load -> func.region0#1: Ref
36 func @mayalias(%arg0: memref<i32>, %arg1: memref<i32>, %value: i32) attributes {test.ptr = "func"} {
37 memref.store %value, %arg1[] {test.ptr = "store"} : memref<i32>
38 %1 = memref.load %arg1[] {test.ptr = "load"} : memref<i32>
39 return {test.ptr = "return"}
44 // CHECK-LABEL: Testing : "recursive"
45 // CHECK-DAG: if -> func.region0#0: ModRef
46 // CHECK-DAG: if -> func.region0#1: ModRef
48 // TODO: This is provably NoModRef, but requires handling recursive side
50 // CHECK-DAG: if -> alloc#0: ModRef
51 func @recursive(%arg0: memref<i32>, %arg1: memref<i32>, %cond: i1, %value: i32) attributes {test.ptr = "func"} {
52 %0 = memref.alloca() {test.ptr = "alloc"} : memref<i32>
54 memref.store %value, %arg0[] : memref<i32>
55 %1 = memref.load %arg0[] : memref<i32>
57 return {test.ptr = "return"}
62 // CHECK-LABEL: Testing : "unknown"
63 // CHECK-DAG: unknown -> func.region0#0: ModRef
64 func @unknown(%arg0: memref<i32>) attributes {test.ptr = "func"} {
65 "foo.op"() {test.ptr = "unknown"} : () -> ()