[Mlir-commits] [mlir] [mlir][bufferization] Hoist allocations through exactly-once regions (PR #224921)

purnima shrivastava llvmlistbot at llvm.org
Sun Sep 20 08:52:01 PDT 2026


================
@@ -519,3 +519,89 @@ func.func @hoist_alloca(
 //      CHECK: %[[ALLOCA0:.*]] = memref.alloca({{.*}})
 // CHECK-NEXT: %[[ALLOCA1:.*]] = memref.alloca({{.*}})
 // CHECK-NEXT: {{.*}} = scf.for
+
+// -----
+
+// CHECK-LABEL: func @loop_execute_region
+func.func @loop_execute_region(%output: memref<8xindex>) {
+  %c0 = arith.constant 0 : index
+  %c1 = arith.constant 1 : index
+  %c8 = arith.constant 8 : index
+
+  scf.for %i = %c0 to %c8 step %c1 {
+    %value = scf.execute_region -> index {
+      %buffer = memref.alloc() : memref<1xindex>
+      memref.store %i, %buffer[%c0] : memref<1xindex>
+      %loaded = memref.load %buffer[%c0] : memref<1xindex>
+      scf.yield %loaded : index
+    }
+    memref.store %value, %output[%i] : memref<8xindex>
+  }
+
+  return
+}
+
+// CHECK: %[[ALLOC:.*]] = memref.alloc() : memref<1xindex>
+// CHECK-NEXT: scf.for
+// CHECK: scf.execute_region
+// CHECK-NOT: memref.alloc()
+// CHECK: memref.store {{.*}}, %[[ALLOC]]
+
+// -----
+
+// Conditional regions must not be crossed when hoisting allocations.
----------------
purnima-nlp wrote:

I tried this, please check if test name imparts the meaning.!

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


More information about the Mlir-commits mailing list