[Mlir-commits] [mlir] [MLIR][MemRef] Fix AllocOp/AllocaOp flattening domination violation (PR #188980)

Hocky Yudhiono llvmlistbot at llvm.org
Thu Apr 2 01:50:01 PDT 2026


hockyy wrote:

Confirmed this issue, running 
```
func.func @alloc() -> memref<4x8xf32> {
  %0 = memref.alloc() : memref<4x8xf32>
  return %0 : memref<4x8xf32>
}
```
<details>
  <summary>Log here, Click to expand</summary>

```
Args: mlir-opt --flatten-memref huh.mlir --debug 
[mlircontext MLIRContext.cpp:480 1] Load new dialect in Context builtin
[mlircontext MLIRContext.cpp:480 1] Load new dialect in Context builtin
[mlircontext MLIRContext.cpp:480 1] Load new dialect in Context func
[mlircontext MLIRContext.cpp:480 1] Load new dialect in Context cf
[mlircontext MLIRContext.cpp:480 1] Load new dialect in Context arith
[mlircontext MLIRContext.cpp:480 1] Load new dialect in Context memref
[mlircontext MLIRContext.cpp:480 1] Load new dialect in Context ub
[mlircontext MLIRContext.cpp:480 1] Load new dialect in Context affine
[pass-manager Pass.cpp:1041 1] Starting PassManager run on operation 'module {...}' with 1 passes, verifyPasses=1 pipeline: builtin.module(flatten-memref)
[pass-manager Pass.cpp:1052 2] Registering dependent dialects for pipeline
[pass-manager Pass.cpp:1057 2] Loading dialect: affine
[pass-manager Pass.cpp:1057 2] Loading dialect: arith
[pass-manager Pass.cpp:1057 2] Loading dialect: builtin
[pass-manager Pass.cpp:1057 2] Loading dialect: memref
[pass-manager Pass.cpp:1057 2] Loading dialect: vector
[mlircontext MLIRContext.cpp:480 1] Load new dialect in Context vector
[pass-manager Pass.cpp:248 3] Merging adjacent adaptors in pass list
[pass-manager Pass.cpp:305 3] Verifying 1 passes for operation 'builtin.module'
[pass-manager Pass.cpp:319 3] Pass list finalization completed successfully
[pass-manager Pass.cpp:1075 2] Initializing passes with new generation: 1
[pass-manager Pass.cpp:492 2] Initializing pass manager 'builtin.module' (generation 1) with 1 passes
[pass-manager Pass.cpp:501 2] Initializing pass 'FlattenMemrefsPass'
[pass-manager Pass.cpp:522 1] Pass manager initialization completed successfully: builtin.module(flatten-memref)
[pass-manager Pass.cpp:1089 2] Constructing analysis manager for pipeline execution
[pass-manager Pass.cpp:1094 2] Executing pipeline with normal execution
[pass-manager Pass.cpp:1122 2] Executing passes using OpToOpPassAdaptor pipeline
[pass-manager Pass.cpp:670 1] Running pipeline on operation 'module {...}' with 1 passes, verifyPasses=1 pipeline: builtin.module(flatten-memref)
[pass-manager Pass.cpp:549 1] Running pass 'FlattenMemrefsPass' on operation 'module {...}' at loc("huh.mlir":0:0)
[region-utils RegionUtils.cpp:189 1] Starting eraseUnreachableBlocks with 1 regions
[region-utils RegionUtils.cpp:202 2] Initial worklist size: 1
[region-utils RegionUtils.cpp:211 2] Processing region with 1 blocks
[region-utils RegionUtils.cpp:214 2]  -> for operation:  module {...}
[region-utils RegionUtils.cpp:211 2] Processing region with 1 blocks
[region-utils RegionUtils.cpp:214 2]  -> for operation:  func.func @alloc() -> memref<4x8xf32> {...}
[region-utils RegionUtils.cpp:252 1] Finished eraseUnreachableBlocks, erased 0 dead blocks
[greedy-rewriter:1] 
[greedy-rewriter:1] //===-------------------------------------------===//
[greedy-rewriter:1] Processing operation : 'func.return'(0x50b00002dfe0) {
[greedy-rewriter:1]   "func.return"(%0) : (memref<4x8xf32>) -> ()
[greedy-rewriter:1] 
[greedy-rewriter:1] } -> failure : all patterns failed to match
[greedy-rewriter:1] //===-------------------------------------------===//
[greedy-rewriter:1] 
[greedy-rewriter:1] //===-------------------------------------------===//
[greedy-rewriter:1] Processing operation : 'func.func'(0x50d0000054c0) {
[greedy-rewriter:1] } -> failure : all patterns failed to match
[greedy-rewriter:1] //===-------------------------------------------===//
[greedy-rewriter:1] 
[greedy-rewriter:1] //===-------------------------------------------===//
[greedy-rewriter:1] Processing operation : 'memref.alloc'(0x50b00002df40) {
[greedy-rewriter:1]   %0 = "memref.alloc"() <{operandSegmentSizes = array<i32: 0, 0>}> : () -> memref<4x8xf32>
[greedy-rewriter:1] 
[greedy-rewriter:1] 
[greedy-rewriter:1]   * Pattern (anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp> : 'memref.alloc -> ()' {
[pattern-application PatternApplicator.cpp:209 1] Trying to match "(anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp>"
[pattern-logging-listener PatternLoggingListener.cpp:10 1] (anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp> | notifyOperationInserted | memref.extract_strided_metadata
[greedy-rewriter:1]     ** Insert  : 'memref.extract_strided_metadata'(0x511000030de0)
[pattern-logging-listener PatternLoggingListener.cpp:10 1] (anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp> | notifyOperationInserted | memref.reinterpret_cast
[greedy-rewriter:1]     ** Insert  : 'memref.reinterpret_cast'(0x50f00000cda0)
[pattern-logging-listener PatternLoggingListener.cpp:10 1] (anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp> | notifyOperationInserted | arith.constant
[greedy-rewriter:1]     ** Insert  : 'arith.constant'(0x508000004db0)
[pattern-logging-listener PatternLoggingListener.cpp:10 1] (anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp> | notifyOperationInserted | memref.alloc
[greedy-rewriter:1]     ** Insert  : 'memref.alloc'(0x50b00002ff90)
[pattern-logging-listener PatternLoggingListener.cpp:10 1] (anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp> | notifyOperationInserted | memref.extract_strided_metadata
[greedy-rewriter:1]     ** Insert  : 'memref.extract_strided_metadata'(0x511000030f20)
[pattern-logging-listener PatternLoggingListener.cpp:10 1] (anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp> | notifyOperationInserted | memref.reinterpret_cast
[greedy-rewriter:1]     ** Insert  : 'memref.reinterpret_cast'(0x50f00000ce90)
[pattern-logging-listener PatternLoggingListener.cpp:31 1] (anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp> | notifyOperationReplaced (with values) | memref.alloc
[greedy-rewriter:1]     ** Replace : 'memref.alloc'(0x50b00002df40)
[pattern-logging-listener PatternLoggingListener.cpp:17 1] (anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp> | notifyOperationModified | memref.extract_strided_metadata
[greedy-rewriter:1]     ** Modified: 'memref.extract_strided_metadata'(0x511000030f20)
[pattern-logging-listener PatternLoggingListener.cpp:17 1] (anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp> | notifyOperationModified | memref.reinterpret_cast
[greedy-rewriter:1]     ** Modified: 'memref.reinterpret_cast'(0x50f00000cda0)
[pattern-logging-listener PatternLoggingListener.cpp:17 1] (anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp> | notifyOperationModified | memref.extract_strided_metadata
[greedy-rewriter:1]     ** Modified: 'memref.extract_strided_metadata'(0x511000030de0)
[pattern-logging-listener PatternLoggingListener.cpp:17 1] (anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp> | notifyOperationModified | func.return
[greedy-rewriter:1]     ** Modified: 'func.return'(0x50b00002dfe0)
[pattern-logging-listener PatternLoggingListener.cpp:38 1] (anonymous namespace)::MemRefRewritePattern<mlir::memref::AllocOp> | notifyOperationErased | memref.alloc
[greedy-rewriter:1]     ** Erase   : 'memref.alloc'(0x50b00002df40)
[pattern-application PatternApplicator.cpp:224 1]  -> matchAndRewrite successful
[greedy-rewriter:1]   } -> success : pattern applied successfully
[pattern-application PatternApplicator.cpp:54 2] // *** IR Dump After Pattern Application ***
operand #0 does not dominate this use
[mlir-asm-printer AsmPrinter.cpp:2114 1] func.func' failed to verify and will be printed in generic form
[pattern-application PatternApplicator.cpp:54 2] "func.func"() <{function_type = () -> memref<4x8xf32>, sym_name = "alloc"}> ({
[pattern-application PatternApplicator.cpp:54 2]   %0:6 = "memref.extract_strided_metadata"(%5) : (memref<4x8xf32>) -> (memref<f32>, index, index, index, index, index)
[pattern-application PatternApplicator.cpp:54 2]   %1 = "memref.reinterpret_cast"(%5) <{operandSegmentSizes = array<i32: 1, 0, 0, 0>, static_offsets = array<i64: 0>, static_sizes = array<i64: 32>, static_strides = array<i64: 1>}> : (memref<4x8xf32>) -> memref<32xf32, strided<[1]>>
[pattern-application PatternApplicator.cpp:54 2]   %2 = "arith.constant"() <{value = 0 : index}> : () -> index
[pattern-application PatternApplicator.cpp:54 2]   %3 = "memref.alloc"() <{operandSegmentSizes = array<i32: 0, 0>}> : () -> memref<32xf32, strided<[1]>>
[pattern-application PatternApplicator.cpp:54 2]   %4:6 = "memref.extract_strided_metadata"(%5) : (memref<4x8xf32>) -> (memref<f32>, index, index, index, index, index)
[pattern-application PatternApplicator.cpp:54 2]   %5 = "memref.reinterpret_cast"(%3) <{operandSegmentSizes = array<i32: 1, 0, 0, 0>, static_offsets = array<i64: 0>, static_sizes = array<i64: 4, 8>, static_strides = array<i64: 8, 1>}> : (memref<32xf32, strided<[1]>>) -> memref<4x8xf32>
[pattern-application PatternApplicator.cpp:54 2]   "func.return"(%5) : (memref<4x8xf32>) -> ()
[pattern-application PatternApplicator.cpp:54 2] }) : () -> ()

[greedy-rewriter:1] } -> success : at least one pattern matched
[greedy-rewriter:1] //===-------------------------------------------===//
huh.mlir:3:8: error: operand #0 does not dominate this use
  %0 = memref.alloc() : memref<4x8xf32>
       ^
huh.mlir:3:8: note: see current operation: %0:6 = "memref.extract_strided_metadata"(%5) : (memref<4x8xf32>) -> (memref<f32>, index, index, index, index, index)
huh.mlir:3:8: note: operand defined here (op in the same block)
LLVM ERROR: IR failed to verify after pattern application
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: mlir-opt --flatten-memref huh.mlir --debug
 #0 0x00005ed75a81da3a ___interceptor_backtrace (/home/hocky/llvm/llvm-project/build_clion_asan/bin/mlir-opt+0x15686a3a)
 #1 0x00005ed75aab0955 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/lib/Support/Unix/Signals.inc:880:13
 #2 0x00005ed75aab13c3 PrintStackTraceSignalHandler(void*) /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/lib/Support/Unix/Signals.inc:962:1
 #3 0x00005ed75aab32c4 llvm::sys::RunSignalHandlers() /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/lib/Support/Signals.cpp:0:5
 #4 0x00005ed75aab32c4 SignalHandler(int, siginfo_t*, void*) /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/lib/Support/Unix/Signals.inc:431:3
 #5 0x00007171db245330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #6 0x00007171db29eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #7 0x00007171db29eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #8 0x00007171db29eb2c pthread_kill ./nptl/pthread_kill.c:89:10
 #9 0x00007171db24527e raise ./signal/../sysdeps/posix/raise.c:27:6
#10 0x00007171db2288ff abort ./stdlib/abort.c:81:7
#11 0x00005ed75a8b5d67 llvm::report_fatal_error(llvm::Twine const&, bool) /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/lib/Support/ErrorHandling.cpp:135:5
#12 0x00005ed75a8b58bb (/home/hocky/llvm/llvm-project/build_clion_asan/bin/mlir-opt+0x1571e8bb)
#13 0x00005ed77005a3a4 (anonymous namespace)::ExpensiveChecks::notifyRewriteSuccess() /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:82:7
#14 0x00005ed77005a3a4 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:624:23
#15 0x00005ed770057409 (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &&::$_2::operator()() const /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:889:11
#16 0x00005ed770057409 void llvm::function_ref<void ()>::callback_fn<(anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &&::$_2>(long) /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#17 0x00005ed77004fc30 (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) && /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/include/llvm/ADT/STLFunctionalExtras.h:0:12
#18 0x00005ed77004fc30 mlir::applyPatternsGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:934:47
#19 0x00005ed75afe520f mlir::applyPatternsGreedily(mlir::Operation*, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h:212:15
#20 0x00005ed76ce20165 (anonymous namespace)::FlattenMemrefsPass::runOnOperation() /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Dialect/MemRef/Transforms/FlattenMemRefs.cpp:267:16
#21 0x00005ed7701a7519 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_3::operator()() const /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Pass/Pass.cpp:613:24
#22 0x00005ed7701a7519 void llvm::function_ref<void ()>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_3>(long) /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#23 0x00005ed770191023 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/include/llvm/ADT/STLFunctionalExtras.h:0:12
#24 0x00005ed770192f4a llvm::LogicalResult::failed() const /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/include/llvm/Support/LogicalResult.h:43:43
#25 0x00005ed770192f4a llvm::failed(llvm::LogicalResult) /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/include/llvm/Support/LogicalResult.h:71:58
#26 0x00005ed770192f4a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Pass/Pass.cpp:688:9
#27 0x00005ed77019fee4 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Pass/Pass.cpp:1123:10
#28 0x00005ed77019ede7 mlir::PassManager::run(mlir::Operation*) /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Pass/Pass.cpp:1097:0
#29 0x00005ed75aae43ac llvm::LogicalResult::failed() const /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/include/llvm/Support/LogicalResult.h:43:43
#30 0x00005ed75aae43ac llvm::failed(llvm::LogicalResult) /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/include/llvm/Support/LogicalResult.h:71:58
#31 0x00005ed75aae43ac performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:596:7
#32 0x00005ed75aae2c0c processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:681:12
#33 0x00005ed75aae2c0c mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, llvm::raw_ostream&) const /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:779:12
#34 0x00005ed75aae2c0c llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#35 0x00005ed77094d0f7 llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) const /home/hocky/llvm/llvm-project/build_clion_asan/../llvm/include/llvm/ADT/STLFunctionalExtras.h:69:12
#36 0x00005ed77094d0f7 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Support/ToolUtilities.cpp:30:12
#37 0x00005ed75aac3161 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:784:26
#38 0x00005ed75aac3b78 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:830:14
#39 0x00005ed75aac4331 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:846:10
#40 0x00005ed75a8b509d main /home/hocky/llvm/llvm-project/build_clion_asan/../mlir/tools/mlir-opt/mlir-opt.cpp:343:33
#41 0x00007171db22a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#42 0x00007171db22a28b call_init ./csu/../csu/libc-start.c:128:20
#43 0x00007171db22a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#44 0x00005ed75a7d9125 _start (/home/hocky/llvm/llvm-project/build_clion_asan/bin/mlir-opt+0x15642125)
```
</details>


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


More information about the Mlir-commits mailing list