<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/120954>120954</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] -lower-host-to-llvm crashes
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wwy6191
</td>
</tr>
</table>
<pre>
git version: bc29fc937c6cb4a210f80c93c79fc6ed97c801f8
system: `Ubuntu 18.04.6 LTS`
reproduce with: `mlir-opt -lower-host-to-llvm a.mlir`
a.mlir:
```
#map = affine_map<(d0) -> (d0)>
module {
func.func @loop_nest_depth() {
%alloc = memref.alloca() :memref<256x8xf32, #spirv.storage_class<Generic>>
affine.for %arg0 = 0 to 32 step 4 {
affine.for %arg1 = 0 to 8 step 2 {
%0 = affine.apply #map(%arg1)
%1 = affine.load %alloc[%arg0, %0] : memref<256x8xf32, #spirv.storage_class<Generic>>
}
}
return
}
}
```
stack trace:
```
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/optional:438: _Tp &std::_Optional_base_impl<unsigned int, std::_Optional_base<unsigned int>>::_M_get() [_Tp = unsigned int, _Dp = std::_Optional_base<unsigned int>]: 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: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -lower-host-to-llvm /data/szy/MLIR/seed/seed29/tmp.lM6A8VYgS4.mlir
#0 0x00005573d3861508 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11ef508)
#1 0x00005573d385f01e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11ed01e)
#2 0x00005573d3861e9d SignalHandler(int) Signals.cpp:0:0
#3 0x00007f57ee10d420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007f57ed74a00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#5 0x00007f57ed729859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
#6 0x00005573d64f457f (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x3e8257f)
#7 0x00005573d6510ed0 mlir::AllocLikeOpLLVMLowering::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::Value>, mlir::ConversionPatternRewriter&) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x3e9eed0)
#8 0x00005573d3b62f84 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::ValueRange>, mlir::ConversionPatternRewriter&) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x14f0f84)
#9 0x00005573d6820014 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41ae014)
#10 0x00005573d98fd791 void llvm::function_ref<void ()>::callback_fn<mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>)::$_0>(long) PatternApplicator.cpp:0:0
#11 0x00005573d98fa40b mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x728840b)
#12 0x00005573d68210e3 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#13 0x00005573d6820137 mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41ae137)
#14 0x00005573d682130f mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41af30f)
#15 0x00005573d682736b mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41b536b)
#16 0x00005573d65e26cd (anonymous namespace)::LowerHostCodeToLLVM::runOnOperation() ConvertLaunchFuncToLLVMCalls.cpp:0:0
#17 0x00005573d67c2ec6 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4150ec6)
#18 0x00005573d67c37f0 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41517f0)
#19 0x00005573d67c5dc2 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4153dc2)
#20 0x00005573d67be53a performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#21 0x00005573d67be18d 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&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#22 0x00005573d6869c65 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) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f7c65)
#23 0x00005573d67b8175 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4146175)
#24 0x00005573d67b841f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x414641f)
#25 0x00005573d67b874e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x414674e)
#26 0x00005573d3841ff7 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11cfff7)
#27 0x00007f57ed72b083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#28 0x00005573d3841b6e _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11cfb6e)
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWltv2zgW_jXMCxGDInV9yIPq1DsFEjRIugPsk0BRlMwdmtSSVJrMr1-Qki3f0mZm6pndxQKtbYlHPOf7zoWHYqi1olOc34DkA0hur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