llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[MLIR][bug][Affine][fuzzer-founded] affine-loop-coalescing erases an affine.for result still used by affine.yield

Open Kiritobl opened this issue 1 month ago • 4 comments

Version

git commit hash: c275ebd64bf5b05e36a3a8e8b8daa32ba9a52aac (LLVM 24.0.0git, optimized build with assertions)

Bug Description

mlir-opt --affine-loop-coalescing aborts with LLVM ERROR: operation destroyed but still has uses when coalescing two perfectly nested affine.for loops. The inner loop result is used by the outer loop's affine.yield. The input passes verification without the pass.

Crash Chain & Root Cause

Location: mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp, coalesceLoops() (line 1712 at this commit).

--affine-loop-coalescing
  → coalescePerfectlyNestedAffineLoops()
  → coalesceLoops()
  → replace uses of the inner loop's region iter arguments
  → secondOutermostLoop.erase()
  → its result is still used by the outer affine.yield
  → Operation::~Operation(): operation destroyed but still has uses

coalesceLoops() remaps the erased loop's region iter arguments but does not remap its result. The outer affine.yield remains a live user of that result when the loop is erased.

Steps to Reproduce

mlir-opt --affine-loop-coalescing reproducer.mlir -o /dev/null

Reproducer (reproducer.mlir)

module {
  func.func @f(%init: i32, %v: i32) -> i32 {
    %outer = affine.for %i = 0 to 4 iter_args(%outer_arg = %init) -> (i32) {
      %inner = affine.for %j = 0 to 4 iter_args(%inner_arg = %init) -> (i32) {
        %next = arith.addi %inner_arg, %v : i32
        affine.yield %next : i32
      }
      affine.yield %inner : i32
    }
    return %outer : i32
  }
}

Stack Dump

reproducer.mlir:4:16: error: 'affine.for' op operation destroyed but still has uses
      %inner = affine.for %j = 0 to 4 iter_args(%inner_arg = %init) -> (i32) {
               ^
reproducer.mlir:4:16: note: see current operation: 
%0 = "affine.for"(<<UNKNOWN SSA VALUE>>) <{lowerBoundMap = affine_map<() -> (0)>, operandSegmentSizes = array<i32: 0, 0, 1>, step = 1 : index, upperBoundMap = affine_map<() -> (4)>}> ({
^bb0(%arg0: index, %arg1: i32):
}) : (i32) -> i32
reproducer.mlir:8:7: note: - use: "affine.yield"(<<UNKNOWN SSA VALUE>>) : (i32) -> ()

      affine.yield %inner : i32
      ^
LLVM ERROR: operation destroyed but still has uses
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 --affine-loop-coalescing reproducer.mlir -o /dev/null
 #0 0x0000556c3a53e699 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (mlir-opt+0x1fa0699)
 #1 0x0000556c3a53ae9c llvm::sys::RunSignalHandlers() (mlir-opt+0x1f9ce9c)
 #2 0x0000556c3a53b006 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f87040a8520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f87040fc9bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f87040fc9bc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f87040fc9bc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f87040a8476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f870408e7f3 abort ./stdlib/abort.c:81:7
 #9 0x0000556c3a4aa785 llvm::ConvertUTF8toUTF16(unsigned char const**, unsigned char const*, unsigned short**, unsigned short*, llvm::ConversionFlags) (.cold) ConvertUTF.cpp:0:0
#10 0x0000556c3a51eb45 (mlir-opt+0x1f80b45)
#11 0x0000556c42db582a mlir::Operation::~Operation() (mlir-opt+0xa81782a)
#12 0x0000556c42db5b4b mlir::Operation::erase() (mlir-opt+0xa817b4b)
#13 0x0000556c40f1c9fe mlir::affine::coalesceLoops(llvm::MutableArrayRef<mlir::affine::AffineForOp>) (mlir-opt+0x897e9fe)
#14 0x0000556c40f205d8 mlir::affine::coalescePerfectlyNestedAffineLoops(mlir::affine::AffineForOp) (mlir-opt+0x89825d8)
#15 0x0000556c40eb9d59 void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (.constprop.0) LoopCoalescing.cpp:0:0
#16 0x0000556c40eb9cc8 void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (.constprop.0) LoopCoalescing.cpp:0:0
#17 0x0000556c40eb9e76 (anonymous namespace)::LoopCoalescingPass::runOnOperation() LoopCoalescing.cpp:0:0
#18 0x0000556c42a3d449 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (mlir-opt+0xa49f449)
#19 0x0000556c42a3d7b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (mlir-opt+0xa49f7b4)
#20 0x0000556c42a3e026 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::'lambda12'(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&)::operator()(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&) const Pass.cpp:0:0
#21 0x0000556c42a3c39c mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (mlir-opt+0xa49e39c)
#22 0x0000556c42a3d321 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (mlir-opt+0xa49f321)
#23 0x0000556c42a3d7b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (mlir-opt+0xa49f7b4)
#24 0x0000556c42a3f6f2 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (mlir-opt+0xa4a16f2)
#25 0x0000556c42a406c9 mlir::PassManager::run(mlir::Operation*) (mlir-opt+0xa4a26c9)
#26 0x0000556c3a6049b3 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#27 0x0000556c3a6052de 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*) MlirOptMain.cpp:0:0
#28 0x0000556c3a605521 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&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#29 0x0000556c42e0fa2d 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) (mlir-opt+0xa871a2d)
#30 0x0000556c3a6002da mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#31 0x0000556c3a605af8 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (mlir-opt+0x2067af8)
#32 0x0000556c3a605d54 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (mlir-opt+0x2067d54)
#33 0x0000556c3a4b25cc main (mlir-opt+0x1f145cc)
#34 0x00007f870408fd90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#35 0x00007f870408fe40 call_init ./csu/../csu/libc-start.c:128:20
#36 0x00007f870408fe40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#37 0x0000556c3a51df35 _start (mlir-opt+0x1f7ff35)

Kiritobl avatar Oct 14 '26 12:10 Kiritobl

@llvm/issue-subscribers-mlir

Author: Kirito (Kiritobl)

#### Version

git commit hash: c275ebd64bf5b05e36a3a8e8b8daa32ba9a52aac (LLVM 24.0.0git, optimized build with assertions)

Bug Description

mlir-opt --affine-loop-coalescing aborts with LLVM ERROR: operation destroyed but still has uses when coalescing two perfectly nested affine.for loops. The inner loop result is used by the outer loop's affine.yield. The input passes verification without the pass.

Crash Chain & Root Cause

Location: mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp, coalesceLoops() (line 1712 at this commit).

--affine-loop-coalescing
  → coalescePerfectlyNestedAffineLoops()
  → coalesceLoops()
  → replace uses of the inner loop's region iter arguments
  → secondOutermostLoop.erase()
  → its result is still used by the outer affine.yield
  → Operation::~Operation(): operation destroyed but still has uses

coalesceLoops() remaps the erased loop's region iter arguments but does not remap its result. The outer affine.yield remains a live user of that result when the loop is erased.

Steps to Reproduce

mlir-opt --affine-loop-coalescing reproducer.mlir -o /dev/null

Reproducer (reproducer.mlir)

module {
  func.func @<!-- -->f(%init: i32, %v: i32) -&gt; i32 {
    %outer = affine.for %i = 0 to 4 iter_args(%outer_arg = %init) -&gt; (i32) {
      %inner = affine.for %j = 0 to 4 iter_args(%inner_arg = %init) -&gt; (i32) {
        %next = arith.addi %inner_arg, %v : i32
        affine.yield %next : i32
      }
      affine.yield %inner : i32
    }
    return %outer : i32
  }
}

Stack Dump

reproducer.mlir:4:16: error: 'affine.for' op operation destroyed but still has uses
      %inner = affine.for %j = 0 to 4 iter_args(%inner_arg = %init) -&gt; (i32) {
               ^
reproducer.mlir:4:16: note: see current operation: 
%0 = "affine.for"(&lt;&lt;UNKNOWN SSA VALUE&gt;&gt;) &lt;{lowerBoundMap = affine_map&lt;() -&gt; (0)&gt;, operandSegmentSizes = array&lt;i32: 0, 0, 1&gt;, step = 1 : index, upperBoundMap = affine_map&lt;() -&gt; (4)&gt;}&gt; ({
^bb0(%arg0: index, %arg1: i32):
}) : (i32) -&gt; i32
reproducer.mlir:8:7: note: - use: "affine.yield"(&lt;&lt;UNKNOWN SSA VALUE&gt;&gt;) : (i32) -&gt; ()

      affine.yield %inner : i32
      ^
LLVM ERROR: operation destroyed but still has uses
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 --affine-loop-coalescing reproducer.mlir -o /dev/null
 #<!-- -->0 0x0000556c3a53e699 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (mlir-opt+0x1fa0699)
 #<!-- -->1 0x0000556c3a53ae9c llvm::sys::RunSignalHandlers() (mlir-opt+0x1f9ce9c)
 #<!-- -->2 0x0000556c3a53b006 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #<!-- -->3 0x00007f87040a8520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #<!-- -->4 0x00007f87040fc9bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #<!-- -->5 0x00007f87040fc9bc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #<!-- -->6 0x00007f87040fc9bc pthread_kill ./nptl/pthread_kill.c:89:10
 #<!-- -->7 0x00007f87040a8476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #<!-- -->8 0x00007f870408e7f3 abort ./stdlib/abort.c:81:7
 #<!-- -->9 0x0000556c3a4aa785 llvm::ConvertUTF8toUTF16(unsigned char const**, unsigned char const*, unsigned short**, unsigned short*, llvm::ConversionFlags) (.cold) ConvertUTF.cpp:0:0
#<!-- -->10 0x0000556c3a51eb45 (mlir-opt+0x1f80b45)
#<!-- -->11 0x0000556c42db582a mlir::Operation::~Operation() (mlir-opt+0xa81782a)
#<!-- -->12 0x0000556c42db5b4b mlir::Operation::erase() (mlir-opt+0xa817b4b)
#<!-- -->13 0x0000556c40f1c9fe mlir::affine::coalesceLoops(llvm::MutableArrayRef&lt;mlir::affine::AffineForOp&gt;) (mlir-opt+0x897e9fe)
#<!-- -->14 0x0000556c40f205d8 mlir::affine::coalescePerfectlyNestedAffineLoops(mlir::affine::AffineForOp) (mlir-opt+0x89825d8)
#<!-- -->15 0x0000556c40eb9d59 void mlir::detail::walk&lt;mlir::ForwardIterator&gt;(mlir::Operation*, llvm::function_ref&lt;void (mlir::Operation*)&gt;, mlir::WalkOrder) (.constprop.0) LoopCoalescing.cpp:0:0
#<!-- -->16 0x0000556c40eb9cc8 void mlir::detail::walk&lt;mlir::ForwardIterator&gt;(mlir::Operation*, llvm::function_ref&lt;void (mlir::Operation*)&gt;, mlir::WalkOrder) (.constprop.0) LoopCoalescing.cpp:0:0
#<!-- -->17 0x0000556c40eb9e76 (anonymous namespace)::LoopCoalescingPass::runOnOperation() LoopCoalescing.cpp:0:0
#<!-- -->18 0x0000556c42a3d449 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (mlir-opt+0xa49f449)
#<!-- -->19 0x0000556c42a3d7b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&amp;, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (mlir-opt+0xa49f7b4)
#<!-- -->20 0x0000556c42a3e026 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::'lambda12'(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&amp;)::operator()(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&amp;) const Pass.cpp:0:0
#<!-- -->21 0x0000556c42a3c39c mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (mlir-opt+0xa49e39c)
#<!-- -->22 0x0000556c42a3d321 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (mlir-opt+0xa49f321)
#<!-- -->23 0x0000556c42a3d7b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&amp;, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (mlir-opt+0xa49f7b4)
#<!-- -->24 0x0000556c42a3f6f2 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (mlir-opt+0xa4a16f2)
#<!-- -->25 0x0000556c42a406c9 mlir::PassManager::run(mlir::Operation*) (mlir-opt+0xa4a26c9)
#<!-- -->26 0x0000556c3a6049b3 performActions(llvm::raw_ostream&amp;, std::shared_ptr&lt;llvm::SourceMgr&gt; const&amp;, mlir::MLIRContext*, mlir::MlirOptMainConfig const&amp;) MlirOptMain.cpp:0:0
#<!-- -->27 0x0000556c3a6052de processBuffer(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&amp;, mlir::DialectRegistry&amp;, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#<!-- -->28 0x0000556c3a605521 llvm::LogicalResult llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;)&gt;::callback_fn&lt;mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;)::'lambda'(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef, llvm::raw_ostream&amp;)&gt;(long, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;) MlirOptMain.cpp:0:0
#<!-- -->29 0x0000556c42e0fa2d mlir::splitAndProcessBuffer(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;)&gt;, llvm::raw_ostream&amp;, llvm::StringRef, llvm::StringRef) (mlir-opt+0xa871a2d)
#<!-- -->30 0x0000556c3a6002da mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;) (.part.0) MlirOptMain.cpp:0:0
#<!-- -->31 0x0000556c3a605af8 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&amp;) (mlir-opt+0x2067af8)
#<!-- -->32 0x0000556c3a605d54 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&amp;) (mlir-opt+0x2067d54)
#<!-- -->33 0x0000556c3a4b25cc main (mlir-opt+0x1f145cc)
#<!-- -->34 0x00007f870408fd90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#<!-- -->35 0x00007f870408fe40 call_init ./csu/../csu/libc-start.c:128:20
#<!-- -->36 0x00007f870408fe40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#<!-- -->37 0x0000556c3a51df35 _start (mlir-opt+0x1f7ff35)

@llvm/issue-subscribers-mlir-affine

Author: Kirito (Kiritobl)

#### Version

git commit hash: c275ebd64bf5b05e36a3a8e8b8daa32ba9a52aac (LLVM 24.0.0git, optimized build with assertions)

Bug Description

mlir-opt --affine-loop-coalescing aborts with LLVM ERROR: operation destroyed but still has uses when coalescing two perfectly nested affine.for loops. The inner loop result is used by the outer loop's affine.yield. The input passes verification without the pass.

Crash Chain & Root Cause

Location: mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp, coalesceLoops() (line 1712 at this commit).

--affine-loop-coalescing
  → coalescePerfectlyNestedAffineLoops()
  → coalesceLoops()
  → replace uses of the inner loop's region iter arguments
  → secondOutermostLoop.erase()
  → its result is still used by the outer affine.yield
  → Operation::~Operation(): operation destroyed but still has uses

coalesceLoops() remaps the erased loop's region iter arguments but does not remap its result. The outer affine.yield remains a live user of that result when the loop is erased.

Steps to Reproduce

mlir-opt --affine-loop-coalescing reproducer.mlir -o /dev/null

Reproducer (reproducer.mlir)

module {
  func.func @<!-- -->f(%init: i32, %v: i32) -&gt; i32 {
    %outer = affine.for %i = 0 to 4 iter_args(%outer_arg = %init) -&gt; (i32) {
      %inner = affine.for %j = 0 to 4 iter_args(%inner_arg = %init) -&gt; (i32) {
        %next = arith.addi %inner_arg, %v : i32
        affine.yield %next : i32
      }
      affine.yield %inner : i32
    }
    return %outer : i32
  }
}

Stack Dump

reproducer.mlir:4:16: error: 'affine.for' op operation destroyed but still has uses
      %inner = affine.for %j = 0 to 4 iter_args(%inner_arg = %init) -&gt; (i32) {
               ^
reproducer.mlir:4:16: note: see current operation: 
%0 = "affine.for"(&lt;&lt;UNKNOWN SSA VALUE&gt;&gt;) &lt;{lowerBoundMap = affine_map&lt;() -&gt; (0)&gt;, operandSegmentSizes = array&lt;i32: 0, 0, 1&gt;, step = 1 : index, upperBoundMap = affine_map&lt;() -&gt; (4)&gt;}&gt; ({
^bb0(%arg0: index, %arg1: i32):
}) : (i32) -&gt; i32
reproducer.mlir:8:7: note: - use: "affine.yield"(&lt;&lt;UNKNOWN SSA VALUE&gt;&gt;) : (i32) -&gt; ()

      affine.yield %inner : i32
      ^
LLVM ERROR: operation destroyed but still has uses
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 --affine-loop-coalescing reproducer.mlir -o /dev/null
 #<!-- -->0 0x0000556c3a53e699 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (mlir-opt+0x1fa0699)
 #<!-- -->1 0x0000556c3a53ae9c llvm::sys::RunSignalHandlers() (mlir-opt+0x1f9ce9c)
 #<!-- -->2 0x0000556c3a53b006 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #<!-- -->3 0x00007f87040a8520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #<!-- -->4 0x00007f87040fc9bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #<!-- -->5 0x00007f87040fc9bc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #<!-- -->6 0x00007f87040fc9bc pthread_kill ./nptl/pthread_kill.c:89:10
 #<!-- -->7 0x00007f87040a8476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #<!-- -->8 0x00007f870408e7f3 abort ./stdlib/abort.c:81:7
 #<!-- -->9 0x0000556c3a4aa785 llvm::ConvertUTF8toUTF16(unsigned char const**, unsigned char const*, unsigned short**, unsigned short*, llvm::ConversionFlags) (.cold) ConvertUTF.cpp:0:0
#<!-- -->10 0x0000556c3a51eb45 (mlir-opt+0x1f80b45)
#<!-- -->11 0x0000556c42db582a mlir::Operation::~Operation() (mlir-opt+0xa81782a)
#<!-- -->12 0x0000556c42db5b4b mlir::Operation::erase() (mlir-opt+0xa817b4b)
#<!-- -->13 0x0000556c40f1c9fe mlir::affine::coalesceLoops(llvm::MutableArrayRef&lt;mlir::affine::AffineForOp&gt;) (mlir-opt+0x897e9fe)
#<!-- -->14 0x0000556c40f205d8 mlir::affine::coalescePerfectlyNestedAffineLoops(mlir::affine::AffineForOp) (mlir-opt+0x89825d8)
#<!-- -->15 0x0000556c40eb9d59 void mlir::detail::walk&lt;mlir::ForwardIterator&gt;(mlir::Operation*, llvm::function_ref&lt;void (mlir::Operation*)&gt;, mlir::WalkOrder) (.constprop.0) LoopCoalescing.cpp:0:0
#<!-- -->16 0x0000556c40eb9cc8 void mlir::detail::walk&lt;mlir::ForwardIterator&gt;(mlir::Operation*, llvm::function_ref&lt;void (mlir::Operation*)&gt;, mlir::WalkOrder) (.constprop.0) LoopCoalescing.cpp:0:0
#<!-- -->17 0x0000556c40eb9e76 (anonymous namespace)::LoopCoalescingPass::runOnOperation() LoopCoalescing.cpp:0:0
#<!-- -->18 0x0000556c42a3d449 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (mlir-opt+0xa49f449)
#<!-- -->19 0x0000556c42a3d7b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&amp;, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (mlir-opt+0xa49f7b4)
#<!-- -->20 0x0000556c42a3e026 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::'lambda12'(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&amp;)::operator()(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&amp;) const Pass.cpp:0:0
#<!-- -->21 0x0000556c42a3c39c mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (mlir-opt+0xa49e39c)
#<!-- -->22 0x0000556c42a3d321 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (mlir-opt+0xa49f321)
#<!-- -->23 0x0000556c42a3d7b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&amp;, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (mlir-opt+0xa49f7b4)
#<!-- -->24 0x0000556c42a3f6f2 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (mlir-opt+0xa4a16f2)
#<!-- -->25 0x0000556c42a406c9 mlir::PassManager::run(mlir::Operation*) (mlir-opt+0xa4a26c9)
#<!-- -->26 0x0000556c3a6049b3 performActions(llvm::raw_ostream&amp;, std::shared_ptr&lt;llvm::SourceMgr&gt; const&amp;, mlir::MLIRContext*, mlir::MlirOptMainConfig const&amp;) MlirOptMain.cpp:0:0
#<!-- -->27 0x0000556c3a6052de processBuffer(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&amp;, mlir::DialectRegistry&amp;, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#<!-- -->28 0x0000556c3a605521 llvm::LogicalResult llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;)&gt;::callback_fn&lt;mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;)::'lambda'(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef, llvm::raw_ostream&amp;)&gt;(long, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;) MlirOptMain.cpp:0:0
#<!-- -->29 0x0000556c42e0fa2d mlir::splitAndProcessBuffer(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;)&gt;, llvm::raw_ostream&amp;, llvm::StringRef, llvm::StringRef) (mlir-opt+0xa871a2d)
#<!-- -->30 0x0000556c3a6002da mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;) (.part.0) MlirOptMain.cpp:0:0
#<!-- -->31 0x0000556c3a605af8 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&amp;) (mlir-opt+0x2067af8)
#<!-- -->32 0x0000556c3a605d54 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&amp;) (mlir-opt+0x2067d54)
#<!-- -->33 0x0000556c3a4b25cc main (mlir-opt+0x1f145cc)
#<!-- -->34 0x00007f870408fd90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#<!-- -->35 0x00007f870408fe40 call_init ./csu/../csu/libc-start.c:128:20
#<!-- -->36 0x00007f870408fe40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#<!-- -->37 0x0000556c3a51df35 _start (mlir-opt+0x1f7ff35)

hi, can I look into this?

Naaz30 avatar Oct 15 '26 03:10 Naaz30

please do @Naaz30, thanks :)

StarOne01 avatar Oct 15 '26 07:10 StarOne01