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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] -nvgpu-optimize-shared-memory 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  -nvgpu-optimize-shared-memory a.mlir`


a.mlir:  
``` 
func.func @variable_ptr_array_physical_result_unranked() -> memref<i32, #gpu.address_space<workgroup>> {
  %0 = memref.alloc() : memref<i32, #gpu.address_space<workgroup>>
  return %0 : memref<i32, #gpu.address_space<workgroup>>
}

``` 
stack trace:

``` 
mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/build/tools/mlir/include/mlir/IR/BuiltinTypeInterfaces.h.inc:268: int64_t mlir::detail::ShapedTypeTrait<mlir::MemRefType>::getDimSize(unsigned int) const [ConcreteType = mlir::MemRefType]: Assertion `idx < getRank() && "invalid index for shaped type"' 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 -nvgpu-optimize-shared-memory /data/szy/MLIR/seed/seed0/tmp.3t229g3cRm.mlir
 #0 0x0000558b2421f348 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x111f348)
 #1 0x0000558b2421ce5e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x111ce5e)
 #2 0x0000558b2421fcdd SignalHandler(int) Signals.cpp:0:0
 #3 0x00007fe7e9eb1420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fe7e94ee00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007fe7e94cd859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007fe7e94cd729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007fe7e94cd729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007fe7e94defd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x0000558b25c610ed mlir::nvgpu::optimizeSharedMemoryReadsAndWrites(mlir::Operation*, mlir::Value) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x2b610ed)
#10 0x0000558b25c629b7 (anonymous namespace)::OptimizeSharedMemoryPass::runOnOperation() OptimizeSharedMemory.cpp:0:0
#11 0x0000558b2712a3d6 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x402a3d6)
#12 0x0000558b2712ad00 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+0x402ad00)
#13 0x0000558b2712d2d2 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x402d2d2)
#14 0x0000558b27125a4a performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#15 0x0000558b2712569d 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
#16 0x0000558b271d1235 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+0x40d1235)
#17 0x0000558b2711f685 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+0x401f685)
#18 0x0000558b2711f92f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x401f92f)
#19 0x0000558b2711fc5e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x401fc5e)
#20 0x0000558b241ffe37 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10ffe37)
#21 0x00007fe7e94cf083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#22 0x0000558b241ff9ae _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10ff9ae)
``` 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzcWVtv3LoR_jX0C2GBou4Pflivs2iAGDHstH0UKHKkZSORKkk53vPrC1Ja78V2knNO3IM2iG1dyJnvm_k4y-Eya2WnAK5Qdo2ymws2ua02V9--7fK4ii8aLXZXnXT4EYyVWqFkhRtOq5ZXScFz3qSMxqQtCa8SXlQtz0FUBS9J3JaIrBBZ2Z11MPh5KCd_byblJhyXEUmjHH_68oByMo8zMBotJg74m3TbZfzQS3OpR4fxpXrsxslfy0H-Bpd2ywyIywEGbXaYRX7ksy1EVsuTZIWxf5CT-b-_aSfFI_8Lo5Q8MiNZ00M9OlMzY9iuHrc7KznrawN26l09KcPUVxCIlohW-BIlH_AAg4EWJWuZUETXGNGkG6eICWHA2tqOjANK1t-0-doZPY0o-eCnoeIaEQ-JZgSj5GaxE7G-13yx7zH_MfPBtAE3GbX38CdMoeJmieZx8Kxj_Ct2JsxavTJgn7KQQboRzDFEN_a3HaKb208f7xHd9P3jcGmgB2Zhfzsa_S_gDtFNM8leILpxWvcW0U3II91IxftJwOFBMHU9yd5J9WU3wkflwLSMg422kVQcJSualx6GVC5Pa4cXRaBkJcAx2c_XD1s2gvAWvhgmHUrWh3G3MNxD69-FsPhHHbgbOTzI3wDRclJh9QjvwueOa2UdRtn1WituwIGfOif6NZvZjYe3shaMk1p5xUvxhFGyxh24e6a-7jVBc0RzjCiV6pH10jsU8IRbbbAN-LHzBilFtMAtkz2ICJHV3acPq4cP2E7NIB1muJk6bGDUxmGn8da50XpQdIPoppNuOzUR18OSk5epkdZO4HOCmfIQQkaw2wLmhtktbhj_GqThfT8EpYhpGGehkAiHf3dGd4YNmJluGkA5-6eV0ki1yCLUiu-Xijc8WfALPPwhXnzDGCWO0qpL-P0w1xLiYSYEkydCCMmysqEpjdskLXEIV8iu3dn54s5I5UIMvoTFQsvDIMO-1do6A2wImV3v9RPS_csigeg1eYrjABHRaiEQnxHgkMFrBO4n9SA7xfq_MSV6MPZZi--B0aM4YK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