[Mlir-commits] [mlir] [mlir] [memref] Elevate `AllocOp`s to `GlobalOp`s pass (PR #211141)

ioana ghiban llvmlistbot at llvm.org
Mon Jul 27 05:45:35 PDT 2026


================
@@ -0,0 +1,140 @@
+// RUN: mlir-opt --elevate-allocs-to-globals --split-input-file %s | FileCheck %s
+
+/// Test that a single static memref.alloc is elevated to a memref.global, references
+/// are replaced with memref.get_global, and the associated memref.dealloc is removed.
+
+func.func @single_alloc() -> memref<10xf32> {
+  %0 = memref.alloc() {alignment = 64 : i64} : memref<10xf32>
+  memref.dealloc %0 : memref<10xf32>
+  return %0 : memref<10xf32>
+}
+
+// CHECK-LABEL: func.func @single_alloc() -> memref<10xf32> {
+// CHECK-NEXT:    %[[MEM:.*]] = memref.get_global @global_alloc : memref<10xf32>
----------------
ioghiban wrote:

I'd add a test where `memref.alloc` turned into `memref.get_global` had a clear use before being deallocated, such as a `load`/`store`.

https://github.com/llvm/llvm-project/pull/211141


More information about the Mlir-commits mailing list