<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/120953>120953</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 0x000055f4925e2508 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11ef508)
 #1 0x000055f4925e001e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11ed01e)
 #2 0x000055f4925e2e9d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f753f805420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f753ee4200b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f753ee21859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x000055f49527557f (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x3e8257f)
 #7 0x000055f495291ed0 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 0x000055f4928e3f84 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 0x000055f4955a1014 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41ae014)
#10 0x000055f49867e791 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 0x000055f49867b40b 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 0x000055f4955a20e3 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#13 0x000055f4955a1137 mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41ae137)
#14 0x000055f4955a230f mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41af30f)
#15 0x000055f4955a836b 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 0x000055f4953636cd (anonymous namespace)::LowerHostCodeToLLVM::runOnOperation() ConvertLaunchFuncToLLVMCalls.cpp:0:0
#17 0x000055f495543ec6 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 0x000055f4955447f0 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 0x000055f495546dc2 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4153dc2)
#20 0x000055f49553f53a performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#21 0x000055f49553f18d 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 0x000055f4955eac65 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 0x000055f495539175 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 0x000055f49553941f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x414641f)
#25 0x000055f49553974e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x414674e)
#26 0x000055f4925c2ff7 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11cfff7)
#27 0x00007f753ee23083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#28 0x000055f4925c2b6e _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/eJzsWltv3LgV_jX0C-EBRer64AdlnOkGsBHDThfok0BRRxp2OZR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