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

[mlir](scf-parallel-loop-specialization) mlir-opt crashes with scf-parallel-loop-specialization

Open Aran-414 opened this issue 5 months ago • 3 comments

git version: c56e892f5c520b4474158837d7968e5c8dc3e4c1

MLIR Program:

#map1 = affine_map<()[s0] -> (s0, 8)>
module {
  func.func @m0() -> (f32) {
    %c0 = arith.constant 0 : index
    %c1 = arith.constant 1 : index
    %c10 = arith.constant 10 : index
    %cst_2 = arith.constant 0.000000e+00 : f32
    %4 = affine.min #map1()[%c10]

    %8 = scf.parallel (%arg0) = (%c0) to (%4) step (%c1) init (%cst_2) -> f32 {
      %17 = arith.addf %cst_2, %cst_2 : f32
      scf.reduce(%17 : f32) {
      ^bb0(%arg1: f32, %arg2: f32):
        %18 = arith.addf %arg1, %arg2 : f32
        scf.reduce.return %18 : f32
      }
    }

    return %8 : f32
  }
}

Reproduce Command: mlir-opt -scf-parallel-loop-specialization a.mlir

StackTrace:

a.mlir:10:10: error: 'scf.parallel' op operation destroyed but still has uses
    %8 = scf.parallel (%arg0) = (%c0) to (%4) step (%c1) init (%cst_2) -> f32 {
         ^
a.mlir:10:10: note: see current operation:
%0 = "scf.parallel"(<<UNKNOWN SSA VALUE>>, <<UNKNOWN SSA VALUE>>, <<UNKNOWN SSA VALUE>>, <<UNKNOWN SSA VALUE>>) <{operandSegmentSizes = array<i32: 1, 1, 1, 1>}> ({
^bb0(%arg0: index):
  %1 = "arith.addf"(<<UNKNOWN SSA VALUE>>, <<UNKNOWN SSA VALUE>>) <{fastmath = #arith.fastmath<none>}> : (f32, f32) -> f32
  "scf.reduce"(%1) ({
  ^bb0(%arg1: f32, %arg2: f32):
    %2 = "arith.addf"(%arg1, %arg2) <{fastmath = #arith.fastmath<none>}> : (f32, f32) -> f32
    "scf.reduce.return"(%2) : (f32) -> ()
  }) : (f32) -> ()
}) : (index, index, index, f32) -> f32
a.mlir:19:5: note: - use: "func.return"(<<UNKNOWN SSA VALUE>>) : (f32) -> ()

    return %8 : f32
    ^
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: /data2/dependency/dev/llvm-project/build/bin/mlir-opt -scf-parallel-loop-specialization a.mlir
 #0 0x0000560b2630620f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25cb20f)
 #1 0x0000560b263029dc llvm::sys::RunSignalHandlers() (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25c79dc)
 #2 0x0000560b26302b77 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f40e05bf420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f40e00aa00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f40e0089859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x0000560b2622a705 (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x24ef705)
 #7 0x0000560b262e31e5 (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25a81e5)
 #8 0x0000560b2f49e086 mlir::Operation::~Operation() (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb763086)
 #9 0x0000560b2f49e1cd mlir::Operation::erase() (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb7631cd)
#10 0x0000560b2d0edc42 specializeParallelLoopForUnrolling(mlir::scf::ParallelOp) LoopSpecialization.cpp:0:0
#11 0x0000560b2d0ee1d3 _ZN4llvm12function_refIFvPN4mlir9OperationEEE11callback_fnIZNS1_6detail4walkILNS1_9WalkOrderE1ENS1_15ForwardIteratorEZN12_GLOBAL__N_126ParallelLoopSpecialization14runOnOperationEvEUlNS1_3scf10ParallelOpEE_SE_vEENSt9enable_ifIXaantsrSt11disjunctionIJSt7is_sameIT2_S3_ESI_ISJ_PNS1_6RegionEESI_ISJ_PNS1_5BlockEEEE5valuesrSI_IT3_vE5valueESS_E4typeES3_OT1_EUlS3_E_EEvlS3_ LoopSpecialization.cpp:0:0
#12 0x0000560b2d0e8cdc void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (.constprop.3) LoopSpecialization.cpp:0:0
#13 0x0000560b2d0ee065 (anonymous namespace)::ParallelLoopSpecialization::runOnOperation() LoopSpecialization.cpp:0:0
#14 0x0000560b2f11c281 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e1281)
#15 0x0000560b2f11c610 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e1610)
#16 0x0000560b2f11e6c4 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e36c4)
#17 0x0000560b2f11f751 mlir::PassManager::run(mlir::Operation*) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e4751)
#18 0x0000560b263cbe8b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#19 0x0000560b263cc933 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
#20 0x0000560b263ccbbb 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
#21 0x0000560b2f4f4cb5 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) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb7b9cb5)
#22 0x0000560b263c2cc4 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
#23 0x0000560b263cd0d7 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x26920d7)
#24 0x0000560b263cd313 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x2692313)
#25 0x0000560b26232b8c main (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x24f7b8c)
#26 0x00007f40e008b083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#27 0x0000560b262e291e _start (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25a791e)
Aborted (core dumped)

Aran-414 avatar Jun 23 '26 01:06 Aran-414

@llvm/issue-subscribers-mlir

Author: Aran-414

git version: c56e892f5c520b4474158837d7968e5c8dc3e4c1

MLIR Program:

#map1 = affine_map&lt;()[s0] -&gt; (s0, 8)&gt;
module {
  func.func @<!-- -->m0() -&gt; (f32) {
    %c0 = arith.constant 0 : index
    %c1 = arith.constant 1 : index
    %c10 = arith.constant 10 : index
    %cst_2 = arith.constant 0.000000e+00 : f32
    %4 = affine.min #map1()[%c10]

    %8 = scf.parallel (%arg0) = (%c0) to (%4) step (%c1) init (%cst_2) -&gt; f32 {
      %17 = arith.addf %cst_2, %cst_2 : f32
      scf.reduce(%17 : f32) {
      ^bb0(%arg1: f32, %arg2: f32):
        %18 = arith.addf %arg1, %arg2 : f32
        scf.reduce.return %18 : f32
      }
    }

    return %8 : f32
  }
}

Reproduce Command: mlir-opt -scf-parallel-loop-specialization a.mlir

StackTrace:

a.mlir:10:10: error: 'scf.parallel' op operation destroyed but still has uses
    %8 = scf.parallel (%arg0) = (%c0) to (%4) step (%c1) init (%cst_2) -&gt; f32 {
         ^
a.mlir:10:10: note: see current operation:
%0 = "scf.parallel"(&lt;&lt;UNKNOWN SSA VALUE&gt;&gt;, &lt;&lt;UNKNOWN SSA VALUE&gt;&gt;, &lt;&lt;UNKNOWN SSA VALUE&gt;&gt;, &lt;&lt;UNKNOWN SSA VALUE&gt;&gt;) &lt;{operandSegmentSizes = array&lt;i32: 1, 1, 1, 1&gt;}&gt; ({
^bb0(%arg0: index):
  %1 = "arith.addf"(&lt;&lt;UNKNOWN SSA VALUE&gt;&gt;, &lt;&lt;UNKNOWN SSA VALUE&gt;&gt;) &lt;{fastmath = #arith.fastmath&lt;none&gt;}&gt; : (f32, f32) -&gt; f32
  "scf.reduce"(%1) ({
  ^bb0(%arg1: f32, %arg2: f32):
    %2 = "arith.addf"(%arg1, %arg2) &lt;{fastmath = #arith.fastmath&lt;none&gt;}&gt; : (f32, f32) -&gt; f32
    "scf.reduce.return"(%2) : (f32) -&gt; ()
  }) : (f32) -&gt; ()
}) : (index, index, index, f32) -&gt; f32
a.mlir:19:5: note: - use: "func.return"(&lt;&lt;UNKNOWN SSA VALUE&gt;&gt;) : (f32) -&gt; ()

    return %8 : f32
    ^
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: /data2/dependency/dev/llvm-project/build/bin/mlir-opt -scf-parallel-loop-specialization a.mlir
 #<!-- -->0 0x0000560b2630620f llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25cb20f)
 #<!-- -->1 0x0000560b263029dc llvm::sys::RunSignalHandlers() (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25c79dc)
 #<!-- -->2 0x0000560b26302b77 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #<!-- -->3 0x00007f40e05bf420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #<!-- -->4 0x00007f40e00aa00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #<!-- -->5 0x00007f40e0089859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #<!-- -->6 0x0000560b2622a705 (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x24ef705)
 #<!-- -->7 0x0000560b262e31e5 (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25a81e5)
 #<!-- -->8 0x0000560b2f49e086 mlir::Operation::~Operation() (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb763086)
 #<!-- -->9 0x0000560b2f49e1cd mlir::Operation::erase() (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb7631cd)
#<!-- -->10 0x0000560b2d0edc42 specializeParallelLoopForUnrolling(mlir::scf::ParallelOp) LoopSpecialization.cpp:0:0
#<!-- -->11 0x0000560b2d0ee1d3 _ZN4llvm12function_refIFvPN4mlir9OperationEEE11callback_fnIZNS1_6detail4walkILNS1_9WalkOrderE1ENS1_15ForwardIteratorEZN12_GLOBAL__N_126ParallelLoopSpecialization14runOnOperationEvEUlNS1_3scf10ParallelOpEE_SE_vEENSt9enable_ifIXaantsrSt11disjunctionIJSt7is_sameIT2_S3_ESI_ISJ_PNS1_6RegionEESI_ISJ_PNS1_5BlockEEEE5valuesrSI_IT3_vE5valueESS_E4typeES3_OT1_EUlS3_E_EEvlS3_ LoopSpecialization.cpp:0:0
#<!-- -->12 0x0000560b2d0e8cdc void mlir::detail::walk&lt;mlir::ForwardIterator&gt;(mlir::Operation*, llvm::function_ref&lt;void (mlir::Operation*)&gt;, mlir::WalkOrder) (.constprop.3) LoopSpecialization.cpp:0:0
#<!-- -->13 0x0000560b2d0ee065 (anonymous namespace)::ParallelLoopSpecialization::runOnOperation() LoopSpecialization.cpp:0:0
#<!-- -->14 0x0000560b2f11c281 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e1281)
#<!-- -->15 0x0000560b2f11c610 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&amp;, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e1610)
#<!-- -->16 0x0000560b2f11e6c4 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e36c4)
#<!-- -->17 0x0000560b2f11f751 mlir::PassManager::run(mlir::Operation*) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e4751)
#<!-- -->18 0x0000560b263cbe8b performActions(llvm::raw_ostream&amp;, std::shared_ptr&lt;llvm::SourceMgr&gt; const&amp;, mlir::MLIRContext*, mlir::MlirOptMainConfig const&amp;) MlirOptMain.cpp:0:0
#<!-- -->19 0x0000560b263cc933 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
#<!-- -->20 0x0000560b263ccbbb 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
#<!-- -->21 0x0000560b2f4f4cb5 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) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb7b9cb5)
#<!-- -->22 0x0000560b263c2cc4 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
#<!-- -->23 0x0000560b263cd0d7 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&amp;) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x26920d7)
#<!-- -->24 0x0000560b263cd313 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&amp;) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x2692313)
#<!-- -->25 0x0000560b26232b8c main (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x24f7b8c)
#<!-- -->26 0x00007f40e008b083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#<!-- -->27 0x0000560b262e291e _start (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25a791e)
Aborted (core dumped)

I just reproduced this on the current main branch and observed the same crash. I'd like to work on it. Could you please assign it to me?

cr-zhao avatar Jul 24 '26 04:07 cr-zhao

I just reproduced this on the current main branch and observed the same crash. I'd like to work on it. Could you please assign it to me?

Just prepare pull request and mention it on this page.

EugeneZelenko avatar Jul 24 '26 04:07 EugeneZelenko