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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] -buffer-hoisting 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: d09707070c7460d0887eae8f7022e816510d5eb1

system: `Ubuntu 18.04.6 LTS`

reproduce with: `mlir-opt  -buffer-hoisting  a.mlir`


a.mlir: 
``` 
module {
  func.func @f(%arg0: f32) {
    %c0 = arith.constant 0 : index
    return
  ^BB1(%0: i32):  // no predecessors
    %cst = arith.constant 1.000000e+00 : f32
    %c0_0 = arith.constant 0 : index
 %c10 = arith.constant 10 : index
    %c1 = arith.constant 1 : index
 %alloc = memref.alloc() : memref<10xf32>
    %c0_1 = arith.constant 0 : index
    %c10_2 = arith.constant 10 : index
    %c1_3 = arith.constant 1 : index
    cf.br ^BB2(%c0_1 : index)
  ^BB2(%1: index):  // 2 preds: ^BB1, ^BB3
    %2 = arith.cmpi slt, %1, %c10 : index
    cf.cond_br %2, ^BB3(%1 : index), ^BB4
  ^BB3(%3: index):  // 2 preds: ^BB2, ^BB5
    %4 = arith.cmpi slt, %3, %c10 : index
    cf.cond_br %4, ^BB4, ^BB6
  ^BB4:  // pred: ^BB3
    %5 = memref.load %alloc[%1] : memref<10xf32>
    %6 = arith.addf %5, %cst : f32
    memref.store %6, %alloc[%1] : memref<10xf32>
    %7 = arith.addi %3, %c1 : index
    cf.br ^BB5(%7 : index)
  ^BB5(%8: index): // 2 preds: ^BB4, ^BB5
    %9 = arith.cmpi slt, %8, %c10 : index
 cf.cond_br %9, ^BB6, ^BB7
  ^BB6:  // pred: ^BB5
    %10 = arith.addi %8, %c1 : index
    cf.br ^BB5(%10 : index)
  ^BB7:  // pred: ^BB6
 return
  }
}

``` 
stack trace:

``` 
mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/llvm/include/llvm/Support/GenericDomTree.h:535: NodeT *llvm::DominatorTreeBase<mlir::Block, false>::findNearestCommonDominator(NodeT *, NodeT *) const [NodeT = mlir::Block, IsPostDom = false]: Assertion `NodeA && "A must be in the tree"' 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 -buffer-hoisting /data/szy/MLIR/seed/seed15/tmp.FeIsmb9dCg.mlir
 #0 0x000055d6f9dd2f88 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1185f88)
 #1 0x000055d6f9dd0a9e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1183a9e)
 #2 0x000055d6f9dd391d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007fab40550420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fab3fb8d00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007fab3fb6c859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007fab3fb6c729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007fab3fb6c729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007fab3fb7dfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x000055d6fd35c25b llvm::DominatorTreeBase<mlir::Block, false>::findNearestCommonDominator(mlir::Block*, mlir::Block*) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x470f25b)
#10 0x000055d6fa33d3b9 mlir::Block* mlir::detail::DominanceInfoBase<false>::findNearestCommonDominator<llvm::SmallPtrSet<mlir::Block*, 16u>&>(llvm::SmallPtrSet<mlir::Block*, 16u>&) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x16f03b9)
#11 0x000055d6fa33cff9 mlir::Block* mlir::bufferization::findCommonDominator<mlir::DominanceInfo>(mlir::Value, llvm::SmallPtrSet<mlir::Value, 16u> const&, mlir::DominanceInfo const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x16efff9)
#12 0x000055d6fa33d7fb (anonymous namespace)::BufferHoistingPass::runOnOperation() BufferOptimizations.cpp:0:0
#13 0x000055d6fd20d936 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45c0936)
#14 0x000055d6fd20e260 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+0x45c1260)
#15 0x000055d6fd21360e auto void mlir::parallelForEach<__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_0>(mlir::MLIRContext*, __gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, __gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_0&&)::'lambda'(__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>&&)::operator()<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&>(__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>&&) const Pass.cpp:0:0
#16 0x000055d6fd20f8bb mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45c28bb)
#17 0x000055d6fd20da8f mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45c0a8f)
#18 0x000055d6fd20e260 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+0x45c1260)
#19 0x000055d6fd210832 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45c3832)
#20 0x000055d6fd2090da performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#21 0x000055d6fd208d2d 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 0x000055d6fd2b4fa5 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+0x4667fa5)
#23 0x000055d6fd202d15 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+0x45b5d15)
#24 0x000055d6fd202fbf mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45b5fbf)
#25 0x000055d6fd2032ee mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45b62ee)
#26 0x000055d6f9db3a77 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1166a77)
#27 0x00007fab3fb6e083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#28 0x000055d6f9db35ee _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11665ee)
``` 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWl1z3CrS_jX4hvIUAn1e-GJsx-9xVXLiivPurQoJJLORQAvIsc-v3wJpRh-eSZxsJqk9mxyfmRE09NNPN3QLiRojasn5BYguQXR9Rnv7oPTF58_PcZAFZ4Vizxe1sPCRayOUBGQLGcoS5P4rkzBGDKVpwilPqwRhzNMgjgLEIl4EAG0B2ppnY3nrxoEY_X_RS9vDIN2gcBPDtx_vQYwGOc07rVhfcvhZ2IdRvm2EPledhfC86KuK6_MHJYwVsoaQblzvfjxA27HFDUVb1-H_3EWrWN9wCJJLgLYQVr0sN-4DghBVAKcAR1TXyA2tCAY424tCCHBUIgjINaRa2IdNqaSxVFroGrdQSMafRlHNba-lvwDRm8vLYJjazyv8vO4XBPgG4BsoFew0Z7zkxihtZuqMPaQv2CD_jwN8iQblDuwMZf4anE4yOCgYvLTICx-UfTEpbRpVetGWt5pXG9_gGci88NAMyFWAnhxw8maB_aCaI4hQjr_FgJy8wgQIYVltCj24Dg-uG3HtxHA2OXeUCBa9M_di713jw3EMhqvhF5mwLcxoOwFNY72cm3j4Lg9YVVbODJY7tDjCs5kHTEvIu95wAj8KkteCn1REE_jwOHjyavDhDN7uVzwBDeeoHKY9pBmL0TzsGkXZPh7druaojK6_GoLxzBrKWOUn3pnhV-R8vY3KjFWa-9Gj5LdqTZZaxZK8L0VoNLgwORKeY3e69vARB4eHHJwdd3B6zMFL72Yzn-5-JRPI-Kh3ZygWm9WOo_RbOFpg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