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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] -sparsification-and-bufferization 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   -sparsification-and-bufferization a.mlir`


a.mlir:  
``` 
#map = affine_map<()[s0,s1,s2] -> ((s0 * s1) * s1)>
module {
  func.func @test_reshape_3d_same_d2d_explicit_empty(%arg0: tensor<3x?x?xf32>) -> tensor<?x?x?xf32> {
    %c2 = arith.constant 2 : index
    %c1 = arith.constant 1 : index
    %c3 = arith.constant 3 : index
    %collapsed = tensor.collapse_shape %arg0 [[0, 1, 2]] : tensor<3x?x?xf32> into tensor<?xf32>
    %dim = tensor.dim %arg0, %c1 : tensor<3x?x?xf32>
    %dim_0 = tensor.dim %collapsed, %c2 : tensor<?xf32>
 %dim_1 = tensor.dim %collapsed, %c3 : tensor<?xf32>
    %0 = affine.apply #map()[%dim, %dim_0, %dim_1]
    %1 = arith.divui %0, %c1 : index
 %expanded = tensor.expand_shape %collapsed [[0, 1, 2]] output_shape [%1, 3, %0] : tensor<?xf32> into tensor<?x3x?xf32>
    %cast = tensor.cast %expanded : tensor<?x3x?xf32> to tensor<?x?x?xf32>
    return %cast : tensor<?x?x?xf32>
  }
}

``` 
stack trace:

``` 
mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp:2315: static void mlir::memref::ExpandShapeOp::build(OpBuilder &, OperationState &, Type, Value, ArrayRef<ReassociationIndices>): Assertion `succeeded(outputShape) && "unable to infer output shape"' 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 -sparsification-and-bufferization /data/szy/MLIR/seed/seed14/tmp.hNYivZemUi.mlir
 #0 0x0000556e46049418 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11ee418)
 #1 0x0000556e46046f2e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11ebf2e)
 #2 0x0000556e46049dad SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f218845a420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f2187a9700b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f2187a76859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007f2187a76729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007f2187a76729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007f2187a87fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x0000556e478b5681 (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x2a5a681)
#10 0x0000556e48590b6b mlir::memref::ExpandShapeOp mlir::OpBuilder::create<mlir::memref::ExpandShapeOp, llvm::ArrayRef<long>, mlir::Value&, llvm::SmallVector<llvm::SmallVector<long, 2u>, 4u>>(mlir::Location, llvm::ArrayRef<long>&&, mlir::Value&, llvm::SmallVector<llvm::SmallVector<long, 2u>, 4u>&&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x3735b6b)
#11 0x0000556e485902ea mlir::bufferization::detail::BufferizableOpInterfaceInterfaceTraits::FallbackModel<mlir::tensor::(anonymous namespace)::ExpandShapeOpInterface>::bufferize(mlir::bufferization::detail::BufferizableOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, mlir::RewriterBase&, mlir::bufferization::BufferizationOptions const&) BufferizableOpInterfaceImpl.cpp:0:0
#12 0x0000556e465a1340 mlir::bufferization::bufferizeOp(mlir::Operation*, mlir::bufferization::BufferizationOptions const&, mlir::bufferization::BufferizationStatistics*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1746340)
#13 0x0000556e465dc1e4 mlir::bufferization::bufferizeModuleOp(mlir::ModuleOp, mlir::bufferization::OneShotBufferizationOptions const&, mlir::bufferization::BufferizationStatistics*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x17811e4)
#14 0x0000556e4805e588 mlir::sparse_tensor::SparsificationAndBufferizationPass::runDenseBufferization() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x3203588)
#15 0x0000556e4805e0dc mlir::sparse_tensor::SparsificationAndBufferizationPass::runOnOperation() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x32030dc)
#16 0x0000556e48fa9d66 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x414ed66)
#17 0x0000556e48faa690 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+0x414f690)
#18 0x0000556e48facc62 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4151c62)
#19 0x0000556e48fa53da performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#20 0x0000556e48fa502d 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
#21 0x0000556e49050985 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+0x41f5985)
#22 0x0000556e48f9f015 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+0x4144015)
#23 0x0000556e48f9f2bf mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41442bf)
#24 0x0000556e48f9f5ee mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41445ee)
#25 0x0000556e46029f07 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11cef07)
#26 0x00007f2187a78083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#27 0x0000556e46029a7e _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11cea7e)
``` 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzcWl9v2zgS_zTMCxGDIvX3IQ9KWuMKNJei6S5w9yJQ1MjmrUTpSCqN99MfSMm25Dhtuldjb69oFIoiZ-Y38-NwRIUbIzcK4AZFtyh6d8UHu-30zdevuzjIgquyq3Y3G2nxE2gjO4VYjktBs1pkLBGxKENOA1KnRGRMJFktYqiyRKQkqFNEckRyszMWWjcPxeSXclB2wEG6IuEqxh-_PKKYjOM09LqrBgH4q7TbaXzbSH3d9RZjfG16ro2speBWduqaq-q6HOoatPzd92C-csMPAhHJpx6WY-w6YjL-9zeUtbzHiL3DvK6lgqLlPWJ3iKaIZii6NQTROxO4C0XRO3yN2Hvsn6aGYERz7B5mxxZi7xHJ264aGsAouUUkx7gelFi5C0YhsWBsocFseQ8FqwrDWygqWhXw3DdSSFtA29udVxJxvSHOcgvKdBqxO_aM2Nr_1Iw6ZTQbjTqM2D8_jjnYgTGikaAjXi3tdiU6ZSxXFrvOHEtVwfNsaHBuaHB2KDs3lJ0d2jUN7w1UfsZo92rfWXi_4Ak69ny8dUHALgjYBcHF4Zs-wVLZbumQyVkHGyrZzrX728nb9O4A_Vt-n4sqyBlhB5h7iXQpcSlrEhS8RRD7lqDRKDLj9Ir3fbPDI9cPzB4VTiI9hlk7cG4-CJuzoJJPg_Qalo46xBjRCJ57rqplfMe-Y3RnJHglxN1g-8HuZ3iD_XM2KSYvePBNBrCzwRPc2AUN_f0CQv66HHyq5CxHNNhBq5m2_LuTUOLcP11PcpaxXPyGreYCEMvPDNinS5896briliO6Nr_vEF3ff_zwGdF10zy11xoa4Ab2t73u_gXCIrr26ZKuG1kiun4neTN230P7GWpE117EePfQm5Xoe8RyyoLIaTSWWynwUycrPOVdxPIWWg312H7vffvo4vrQj13lIJsK0fShv3Ut0BjR2MX5oQft8_qj5Rb2vV92P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