diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp --- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp @@ -312,9 +312,11 @@ if (!op->getParentOp()->hasTrait()) { bool hasPotentialAlloca = op->walk([&](Operation *alloc) { + if (alloc == op) + return WalkResult::advance(); if (isPotentialAutomaticAllocationScope(alloc)) return WalkResult::interrupt(); - return WalkResult::skip(); + return WalkResult::advance(); }).wasInterrupted(); if (hasPotentialAlloca) return failure(); diff --git a/mlir/test/Dialect/MemRef/canonicalize.mlir b/mlir/test/Dialect/MemRef/canonicalize.mlir --- a/mlir/test/Dialect/MemRef/canonicalize.mlir +++ b/mlir/test/Dialect/MemRef/canonicalize.mlir @@ -643,3 +643,17 @@ // CHECK: }) : () -> () // CHECK: return // CHECK: } + +func @scopeInline(%arg : memref) { + %cnt = "test.count"() : () -> index + "test.region"() ({ + memref.alloca_scope { + memref.store %cnt, %arg[] : memref + } + "test.terminator"() : () -> () + }) : () -> () + return +} + +// CHECK: func @scopeInline +// CHECK-NOT: memref.alloca_scope