<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/116352>116352</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [MLIR]-gpu-module-to-binary="format=%gpu_compilation_format" triggers Assertion Failure 'this->_M_is_engaged()'
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          xisang0
      </td>
    </tr>
</table>

<pre>
    Test on commit: https://github.com/llvm/llvm-project/commit/6548b6354d1d990e1c98736f5e7c3de876bedc8e
steps to reproduce:
```
mlir-opt test.mlir -gpu-module-to-binary="format=%gpu_compilation_format"
```
test case:
```
module {
  func.func @test_gather(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x26xi32>) -> () {
    return
 }
}
```
crash trace:
```
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/optional:438: _Tp &std::_Optional_base_impl<mlir::gpu::CompilationTarget, std::_Optional_base<mlir::gpu::CompilationTarget, true, true>>::_M_get() [_Tp = mlir::gpu::CompilationTarget, _Dp = std::_Optional_base<mlir::gpu::CompilationTarget, true, true>]: Assertion 'this->_M_is_engaged()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: build/bin/mlir-opt test.mlir -gpu-module-to-binary=format=%gpu_compilation_format
 #0 0x0000000001119717 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build/bin/mlir-opt+0x1119717)
 #1 0x000000000111726e llvm::sys::RunSignalHandlers() (build/bin/mlir-opt+0x111726e)
 #2 0x000000000111a0ea SignalHandler(int) Signals.cpp:0:0
 #3 0x000073d414dcc520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000073d414e209fc pthread_kill (/usr/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x000073d414dcc476 gsignal (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x000073d414db27f3 abort (/usr/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x0000000001921b85 (anonymous namespace)::GpuModuleToBinaryPass::runOnOperation() ModuleToBinary.cpp:0:0
 #8 0x000000000445988c mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (build/bin/mlir-opt+0x445988c)
 #9 0x000000000445a212 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (build/bin/mlir-opt+0x445a212)
#10 0x000000000445cb65 mlir::PassManager::run(mlir::Operation*) (build/bin/mlir-opt+0x445cb65)
#11 0x0000000004454f8c performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#12 0x0000000004454aa4 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, 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&)::$_2>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#13 0x0000000004543018 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::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (build/bin/mlir-opt+0x4543018)
#14 0x000000000444fe4f mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (build/bin/mlir-opt+0x444fe4f)
#15 0x00000000044500ed mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (build/bin/mlir-opt+0x44500ed)
#16 0x00000000044504c7 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (build/bin/mlir-opt+0x44504c7)
#17 0x00000000010fb097 main (build/bin/mlir-opt+0x10fb097)
#18 0x000073d414db3d90 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#19 0x000073d414db3e40 __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#20 0x00000000010fac15 _start (build/bin/mlir-opt+0x10fac15)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWN1y4yoSfhp8Q8WF0P-FL5x4vDtV40oqyb0KAZLZQaAFdNZ5-y2Q4lhOMk5yZndrT8qxJdF0f939dYMg1opWcb4C6TVINwsyuL02q4OwRLVoUWv2tHrk1kGtINVdJxyI13DvXG9BvAZ4C_C2FW4_1EuqO4C3Uv7x_HPVG_0PTh3A22kq3mZpUtRZnCYsYmWJeETLIo-zJuU5jRkv8qzmjBYcoA1Aa-t4b6HT0PDeaDZQ7o2GIZCh6RNuOynMle4ddNy6pb-DV20_XHWaDZJfOX1VC0XME4g3AONGm464cJ22_VBR3fVCEie0qqYxjN-049VDSuz7QIJBCPLr8R7CZlB06b8gSJCfX7XE7bkBuAA4JaZFPqSOK6sNiG-i-ICjQ3xoYgzibwDfwFEqeiWVHcQkU8IrEH-DQWN5ahtCw91g1HQP8s0E-ngxR08NsXvoDHk_0gBvB2t8ikXtk08pwNtDkVVZciWFGg5XrRoA3pYAb5fL119CUTkw7kkB8HX4BFnd-_ATCe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