[Mlir-commits] [mlir] 91e0cb6 - [mlir] LocalAliasAnalysis: Assume allocation scope to function scope if cannot determine better

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed May 26 02:07:32 PDT 2021


Author: Butygin
Date: 2021-05-26T12:06:56+03:00
New Revision: 91e0cb6598f458c79707bc3481f0e70b1dd731d4

URL: https://github.com/llvm/llvm-project/commit/91e0cb6598f458c79707bc3481f0e70b1dd731d4
DIFF: https://github.com/llvm/llvm-project/commit/91e0cb6598f458c79707bc3481f0e70b1dd731d4.diff

LOG: [mlir] LocalAliasAnalysis: Assume allocation scope to function scope if cannot determine better

It helps when checking aliasing between AllocOp result and function arguments.

Differential Revision: https://reviews.llvm.org/D102557

Added: 
    

Modified: 
    mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp
    mlir/test/Analysis/test-alias-analysis.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp b/mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp
index 6116756624adc..17a9ded869173 100644
--- a/mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp
+++ b/mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp
@@ -8,6 +8,7 @@
 
 #include "mlir/Analysis/AliasAnalysis/LocalAliasAnalysis.h"
 
+#include "mlir/IR/FunctionSupport.h"
 #include "mlir/IR/Matchers.h"
 #include "mlir/Interfaces/ControlFlowInterfaces.h"
 #include "mlir/Interfaces/SideEffectInterfaces.h"
@@ -231,7 +232,9 @@ getAllocEffectFor(Value value, Optional<MemoryEffects::EffectInstance> &effect,
 
   // TODO: Here we could look at the users to see if the resource is either
   // freed on all paths within the region, or is just not captured by anything.
-  allocScopeOp = nullptr;
+  // For now assume allocation scope to the function scope (we don't care if
+  // pointer escape outside function).
+  allocScopeOp = op->getParentWithTrait<OpTrait::FunctionLike>();
   return success();
 }
 

diff  --git a/mlir/test/Analysis/test-alias-analysis.mlir b/mlir/test/Analysis/test-alias-analysis.mlir
index a53e9e1f05f2d..977cd30dd3db1 100644
--- a/mlir/test/Analysis/test-alias-analysis.mlir
+++ b/mlir/test/Analysis/test-alias-analysis.mlir
@@ -14,14 +14,12 @@
 // CHECK-DAG: alloca_2#0 <-> func.region0#0: NoAlias
 // CHECK-DAG: alloca_2#0 <-> func.region0#1: NoAlias
 
-// TODO: The MayAlias below is overly conservative and should be provably
-// NoAlias with a proper escape analysis.
 // CHECK-DAG: alloc_1#0 <-> alloc_2#0: NoAlias
-// CHECK-DAG: alloc_1#0 <-> func.region0#0: MayAlias
-// CHECK-DAG: alloc_1#0 <-> func.region0#1: MayAlias
+// CHECK-DAG: alloc_1#0 <-> func.region0#0: NoAlias
+// CHECK-DAG: alloc_1#0 <-> func.region0#1: NoAlias
 
-// CHECK-DAG: alloc_2#0 <-> func.region0#0: MayAlias
-// CHECK-DAG: alloc_2#0 <-> func.region0#1: MayAlias
+// CHECK-DAG: alloc_2#0 <-> func.region0#0: NoAlias
+// CHECK-DAG: alloc_2#0 <-> func.region0#1: NoAlias
 func @simple(%arg: memref<2xf32>, %arg1: memref<2xf32>) attributes {test.ptr = "func"} {
   %0 = memref.alloca() {test.ptr = "alloca_1"} : memref<8x64xf32>
   %1 = memref.alloca() {test.ptr = "alloca_2"} : memref<8x64xf32>
@@ -76,10 +74,10 @@ func @control_flow(%arg: memref<2xf32>, %cond: i1) attributes {test.ptr = "func"
 // CHECK-DAG: alloc_1#0 <-> func.region0.block2#0: MayAlias
 
 // CHECK-DAG: func.region0#0 <-> func.region0.block1#0: NoAlias
-// CHECK-DAG: func.region0#0 <-> func.region0.block2#0: MayAlias
+// CHECK-DAG: func.region0#0 <-> func.region0.block2#0: NoAlias
 
 // CHECK-DAG: func.region0#1 <-> func.region0.block1#0: NoAlias
-// CHECK-DAG: func.region0#1 <-> func.region0.block2#0: MayAlias
+// CHECK-DAG: func.region0#1 <-> func.region0.block2#0: NoAlias
 
 // CHECK-DAG: func.region0.block1#0 <-> func.region0.block2#0: MayAlias
 func @control_flow_merge(%arg: memref<2xf32>, %cond: i1) attributes {test.ptr = "func"} {
@@ -120,8 +118,8 @@ func @control_flow_merge(%arg: memref<2xf32>, %cond: i1) attributes {test.ptr =
 // CHECK-DAG: if_alloca_merge#0 <-> func.region0#0: NoAlias
 // CHECK-DAG: if_alloca_merge#0 <-> func.region0#1: NoAlias
 
-// CHECK-DAG: if_alloc#0 <-> func.region0#0: MayAlias
-// CHECK-DAG: if_alloc#0 <-> func.region0#1: MayAlias
+// CHECK-DAG: if_alloc#0 <-> func.region0#0: NoAlias
+// CHECK-DAG: if_alloc#0 <-> func.region0#1: NoAlias
 func @region_control_flow(%arg: memref<2xf32>, %cond: i1) attributes {test.ptr = "func"} {
   %0 = memref.alloca() {test.ptr = "alloca_1"} : memref<8x64xf32>
   %1 = memref.alloca() {test.ptr = "alloca_2"} : memref<8x64xf32>


        


More information about the Mlir-commits mailing list