[Mlir-commits] [mlir] Revert "[MLIR][Mem2Reg] Add support for memref.alloca_scope" (PR #215354)
Kewen Meng
llvmlistbot at llvm.org
Mon Aug 10 11:00:37 PDT 2026
https://github.com/Kewen12 created https://github.com/llvm/llvm-project/pull/215354
Reverts llvm/llvm-project#214221
unblock bots:
https://lab.llvm.org/buildbot/#/builders/203
https://lab.llvm.org/buildbot/#/builders/226
https://lab.llvm.org/buildbot/#/builders/234/builds/1876
>From 09b1ed1744781695d043902402be3919101e13c6 Mon Sep 17 00:00:00 2001
From: Kewen Meng <Kewen.Meng at amd.com>
Date: Mon, 10 Aug 2026 10:59:13 -0700
Subject: [PATCH] Revert "[MLIR][Mem2Reg] Add support for memref.alloca_scope
(#214221)"
This reverts commit 7214eb03c28238b89b6ba7e6d56b67359d6cf79e.
---
.../mlir/Dialect/MemRef/IR/MemRefOps.td | 15 ++++---
.../Dialect/MemRef/IR/MemRefMemorySlot.cpp | 40 +------------------
mlir/test/Dialect/MemRef/mem2reg.mlir | 21 ----------
3 files changed, 8 insertions(+), 68 deletions(-)
diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
index fb4506b92f5d9..8f530b2dbd62e 100644
--- a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
+++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
@@ -419,14 +419,13 @@ def MemRef_AllocaOp : AllocLikeOp<"alloca", AutomaticAllocationScopeResource,[
// AllocaScopeOp
//===----------------------------------------------------------------------===//
-def MemRef_AllocaScopeOp
- : MemRef_Op<"alloca_scope",
- [AutomaticAllocationScope,
- DeclareOpInterfaceMethods<
- RegionBranchOpInterface, ["getSuccessorInputs"]>,
- DeclareOpInterfaceMethods<PromotableRegionOpInterface>,
- SingleBlockImplicitTerminator<"AllocaScopeReturnOp">,
- RecursiveMemoryEffects, NoRegionArguments]> {
+def MemRef_AllocaScopeOp : MemRef_Op<"alloca_scope",
+ [AutomaticAllocationScope,
+ DeclareOpInterfaceMethods<RegionBranchOpInterface, [
+ "getSuccessorInputs"]>,
+ SingleBlockImplicitTerminator<"AllocaScopeReturnOp">,
+ RecursiveMemoryEffects,
+ NoRegionArguments]> {
let summary = "explicitly delimited scope for stack allocation";
let description = [{
The `memref.alloca_scope` operation represents an explicitly-delimited
diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefMemorySlot.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefMemorySlot.cpp
index e4a66f3728ffd..6748e2cf71804 100644
--- a/mlir/lib/Dialect/MemRef/IR/MemRefMemorySlot.cpp
+++ b/mlir/lib/Dialect/MemRef/IR/MemRefMemorySlot.cpp
@@ -19,8 +19,8 @@
#include "mlir/IR/Matchers.h"
#include "mlir/IR/Value.h"
#include "mlir/Interfaces/MemorySlotInterfaces.h"
-#include "mlir/Interfaces/Utils/MemorySlotUtils.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/ErrorHandling.h"
using namespace mlir;
@@ -277,44 +277,6 @@ DeletionKind memref::StoreOp::rewire(const DestructurableMemorySlot &slot,
return DeletionKind::Keep;
}
-//===----------------------------------------------------------------------===//
-// Interfaces for AllocaScopeOp
-//===----------------------------------------------------------------------===//
-
-bool memref::AllocaScopeOp::isRegionPromotable(const MemorySlot &slot,
- Region *region,
- bool hasValueStores) {
- return true;
-}
-
-void memref::AllocaScopeOp::setupPromotion(
- const MemorySlot &slot, Value reachingDef, bool hasValueStores,
- llvm::SmallMapVector<Region *, Value, 2> ®ionsToProcess) {
- regionsToProcess.insert({&getRegion(), reachingDef});
-}
-
-Value memref::AllocaScopeOp::finalizePromotion(
- const MemorySlot &slot, Value reachingDef, bool hasValueStores,
- const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
- OpBuilder &builder) {
- if (!hasValueStores)
- return reachingDef;
-
- IRRewriter rewriter(builder);
-
- // Update the return terminator to return the newly defined reaching
- // definition.
- memoryslot::updateTerminator(&getRegion().back(), reachingDef,
- reachingAtBlockEnd);
-
- SmallVector<Type> resultTypes(getResultTypes());
- resultTypes.push_back(slot.elemType);
-
- Operation *newOp =
- memoryslot::replaceWithNewResults(rewriter, getOperation(), resultTypes);
- return newOp->getResults().back();
-}
-
//===----------------------------------------------------------------------===//
// Interfaces for destructurable types
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/MemRef/mem2reg.mlir b/mlir/test/Dialect/MemRef/mem2reg.mlir
index 719b8b9acdb8f..8f937c4efe75e 100644
--- a/mlir/test/Dialect/MemRef/mem2reg.mlir
+++ b/mlir/test/Dialect/MemRef/mem2reg.mlir
@@ -309,24 +309,3 @@ func.func @two_consecutive_merge_points(%cond1: i1, %cond2: i1) -> i32 {
// CHECK: return %[[RESULT]] : i32
return %result : i32
}
-
-// -----
-
-// Ensure that AllocaScopeOp does not block mem2reg.
-
-// CHECK-LABEL: func.func @alloca_scope
-func.func @alloca_scope() -> i32 {
- %c0 = arith.constant 0 : i32
- %alloca = memref.alloca() {alignment = 4 : i64} : memref<i32>
- memref.store %c0, %alloca[] : memref<i32>
- // CHECK: %[[RET:.*]] = memref.alloca_scope
- memref.alloca_scope {
- %c1 = arith.constant 1 : i32
- memref.store %c1, %alloca[] : memref<i32>
- // CHECK: %[[ONE:.*]] = arith.constant 1
- // CHECK: memref.alloca_scope.return %[[ONE]]
- }
- %value = memref.load %alloca[] : memref<i32>
- // CHECK: return %[[RET]]
- return %value : i32
-}
More information about the Mlir-commits
mailing list