[PATCH] D154892: [MLIR][MemRef] Avoid returning ReallocOp from findDealloc

Alexander Shaposhnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 11 14:33:47 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG57609fb6dde1: [MLIR][MemRef] Avoid returning ReallocOp from findDealloc (authored by alexander-shaposhnikov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154892/new/

https://reviews.llvm.org/D154892

Files:
  mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp
  mlir/test/Dialect/Bufferization/canonicalize.mlir


Index: mlir/test/Dialect/Bufferization/canonicalize.mlir
===================================================================
--- mlir/test/Dialect/Bufferization/canonicalize.mlir
+++ mlir/test/Dialect/Bufferization/canonicalize.mlir
@@ -209,6 +209,19 @@
 
 // -----
 
+// Verify SimplifyClones skips clones followed by realloc.
+// CHECK-LABEL: @clone_and_realloc
+func.func @clone_and_realloc(%arg0: memref<?xf32>) {
+  %0 = bufferization.clone %arg0 : memref<?xf32> to memref<32xf32>
+  "use"(%0) : (memref<32xf32>) -> ()
+  %1 = memref.realloc %0 : memref<32xf32> to memref<64xf32>
+  memref.dealloc %1 : memref<64xf32>
+  return
+}
+// CHECK-SAME: %[[ARG:.*]]: memref<?xf32>
+// CHECK-NOT: %cast = memref.cast %[[ARG]]
+
+// -----
 
 // CHECK-LABEL: func @tensor_cast_to_memref
 //  CHECK-SAME:   %[[ARG0:.+]]: tensor<4x6x16x32xi8>
Index: mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp
===================================================================
--- mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp
+++ mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp
@@ -49,6 +49,9 @@
   for (Operation *user : allocValue.getUsers()) {
     if (!hasEffect<MemoryEffects::Free>(user, allocValue))
       continue;
+    // If we found a realloc instead of dealloc, return std::nullopt.
+    if (isa<memref::ReallocOp>(user))
+      return std::nullopt;
     // If we found > 1 dealloc, return std::nullopt.
     if (dealloc)
       return std::nullopt;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154892.539297.patch
Type: text/x-patch
Size: 1438 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230711/37907b61/attachment.bin>


More information about the llvm-commits mailing list