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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] -one-shot-bufferize 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 -one-shot-bufferize a.mlir`


a.mlir: 
``` 
module {
  func.func @test_reshape_3d_same_d2d(%arg0: tensor<2x?xf32>) -> (tensor<?x?xf32>, tensor<?x?xf32>, tensor<?x?xf32>) {
 %collapsed = tensor.collapse_shape %arg0 [[0, 1]] : tensor<2x?xf32> into tensor<?xf32>
    %c0 = arith.constant 0 : index
    %dim = tensor.dim %collapsed, %c0 : tensor<?xf32>
    %c2 = arith.constant 2 : index
    %0 = arith.divui %dim, %c2 : index
    %expanded = tensor.expand_shape %collapsed [[0, 1]] output_shape [2, %0] : tensor<?xf32> into tensor<2x?xf32>
    %cast = tensor.cast %expanded : tensor<2x?xf32> to tensor<?x?xf32>
 %dim_replaced = tensor.dim %cast, %c0 : tensor<?x?xf32>
    %c1 = arith.constant 1 : index
    %1 = arith.divui %dim_replaced, %c1 : index
 %expanded_0 = tensor.expand_shape %collapsed [[0, 1]] output_shape [2, %1] : tensor<?xf32> into tensor<2x?xf32>
    %cast_1 = tensor.cast %expanded_0 : tensor<2x?xf32> to tensor<?x?xf32>
    %c0_2 = arith.constant 0 : index
 %dim_replaced_3 = tensor.dim %cast_1, %c0_2 : tensor<?x?xf32>
    %c1_4 = arith.constant 1 : index
    %expanded_5 = tensor.expand_shape %collapsed [[0, 1]] output_shape [%dim_replaced_3, %c1_4] : tensor<?xf32> into tensor<?x?xf32>
    return %cast, %cast_1, %expanded_5 : tensor<?x?xf32>, tensor<?x?xf32>, tensor<?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 -one-shot-bufferize /data/szy/MLIR/seed/seed14/tmp.hNYivZemUi.mlir
 #0 0x000055c527a4a418 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11ee418)
 #1 0x000055c527a47f2e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11ebf2e)
 #2 0x000055c527a4adad SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f548ef53420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f548e59000b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f548e56f859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007f548e56f729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007f548e56f729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007f548e580fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x000055c5292b6681 (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x2a5a681)
#10 0x000055c529f91b6b 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 0x000055c529f912ea 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 0x000055c527fa2340 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 0x000055c527fa604d (anonymous namespace)::OneShotBufferizePass::runOnOperation() Bufferize.cpp:0:0
#14 0x000055c52a9aad66 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)
#15 0x000055c52a9ab690 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)
#16 0x000055c52a9adc62 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4151c62)
#17 0x000055c52a9a63da performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#18 0x000055c52a9a602d 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
#19 0x000055c52aa51985 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)
#20 0x000055c52a9a0015 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)
#21 0x000055c52a9a02bf mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41442bf)
#22 0x000055c52a9a05ee mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41445ee)
#23 0x000055c527a2af07 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11cef07)
#24 0x00007f548e571083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#25 0x000055c527a2aa7e _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/eJzcWl9zozry_TTKiyouIf4YHvLgJOP6TdXkl1Qy91btvlBCamztBcFKIpPcT78lATY49kxmNq67u1MTG4SkPn36SN2AmTFyowCuUHyN4tsL1tlto6--fXtNgiy4KBrxerWRFj-DNrJRKFzhgtOs5Fm45AkvIkYDUqaEZyFfZiVPQGRLnpKgTBFZIbIyr8ZC7cahhPxWdMp2OEgXJFok-MvXJ5SQvp-GVjei44C_Sbsd-teV1JdNa_Flo-DSbBt7WXRlCVr-CZgt3OXdBIishhY3lqzcBf_fndSN6CrAaHmNyArjslN84T4wiogFY3MNZstayEORG1ZDLqhANEU0ZnpD3IwWlGk0Cm_oCwrXL2VIUfgJ0QxfovATRjTddXCXp11u8K9cykawiMa8qSrWGhAYhbfDkMXYmHvgeICKfRyviZs7QPEtim_xSfhYKtvMIQzmHUnYmybeJtPSbhe8UcYyZTHxc0ol4GXfVch6is-fTrA7ROOEqx8YpceM0mNGp_CEfO7kgGS0dnQQvLRMiTmdfduezAnnbxltOtt2duwcX9PBHHlD90myZzLae86MnQXZn88Qn4rlYSTn0_es5BraivG552OgmLHfidFRtMGxOAXHKA9OxGmHaDR9MHrie04-PF7BR8QrD74XsZz8cszGFZgfXQ7kDVFTOvPwRIjzYBfknL43zHn07kDv_I4_LFpvXNtpJY_eH8Cj3mmwnVaH8p_SNPPnNFm_tss7EGh567JV_3mQtoxl_A9sNeOAwtWRDmOC9DmPrgWzDNG1-fMV0fXdl8-PiK6r6rm-1FABMzCetrr5B3CL6NonTLquZIHo-layqm--g_oRSkTXfor-7L41C962KFzRMIidRWOZlRw_N1LgIfOicFVDraHsjz959p5cJO_bvqnoZOVy63177Y5AY0QTR9J9C5pZ2agnyyyMrV9fW3Dfv7Oq8wcrrdmrAxfePAIzpuHSj_qshORg-uTp0K2MAe2uuErCdJwDCLfPpL2-PCifZ52hBCNKO8WKCtyqlKoEPQgRm74nRXSJSyY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