Open
Description
test commit: 8c7a2ce
step to reproduce:
mlir-opt test.mlir -ownership-based-buffer-deallocation
Interestingly, the crash doesn't occur if I remove the extra branch jump statements in test.mlir!
minimal test case:
module {
memref.global "private" constant @__constant_3x3xf32_0 : memref<3x3xf32> = dense<-5.013000e+01> {alignment = 64 : i64}
memref.global "private" constant @__constant_21x3xf32 : memref<21x3xf32> = dense<2.558000e+01> {alignment = 64 : i64}
memref.global "private" constant @__constant_3x3xf32 : memref<3x3xf32> = dense<8.502000e+01> {alignment = 64 : i64}
func.func @main() -> (memref<1x4x4x8xf32>, memref<3x3xf32>, memref<21x3xf32>, memref<3x3xf32>) {
%cst = arith.constant dense<3599.60767> : tensor<1x4x4x8xf32>
%0 = bufferization.to_memref %cst : tensor<1x4x4x8xf32> to memref<1x4x4x8xf32, strided<[?, ?, ?, ?], offset: ?>>
%3 = memref.get_global @__constant_3x3xf32_0 : memref<3x3xf32>
%alloc = memref.alloc() {alignment = 64 : i64} : memref<21x3xf32>
cf.br ^bb2
^bb2: // pred: ^bb0
%alloc_0 = memref.alloc() {alignment = 64 : i64} : memref<3x3xf32>
cf.br ^bb24
^bb24: // 2 preds: ^bb13, ^bb23
%alloc_1 = memref.alloc() {alignment = 64 : i64} : memref<1x4x4x8xf32>
memref.copy %0, %alloc_1 : memref<1x4x4x8xf32, strided<[?, ?, ?, ?], offset: ?>> to memref<1x4x4x8xf32>
return %alloc_1, %3, %alloc, %alloc_0 : memref<1x4x4x8xf32>, memref<3x3xf32>, memref<21x3xf32>, memref<3x3xf32>
}
}
Crash backtrace:
mlir-opt: /home/workdir/llvm-project/mlir/lib/IR/Operation.cpp:389: bool mlir::Operation::isBeforeInBlock(Operation *): Assertion `other && other->block == block && "Expected other operation to have the same parent block."' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /home/workdir/llvm-project/build/bin/mlir-opt -ownership-based-buffer-deallocation test.mlir
#0 0x0000562e64f5cf78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/workdir/llvm-project/build/bin/mlir-opt+0x1342f78)
#1 0x0000562e64f5aa9e llvm::sys::RunSignalHandlers() (/home/workdir/llvm-project/build/bin/mlir-opt+0x1340a9e)
#2 0x0000562e64f5d981 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f6244708520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f624475c9fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007f6244708476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007f62446ee7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007f62446ee71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007f62446ffe96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000562e68353383 mlir::Operation::isBeforeInBlock(mlir::Operation*) (/home/workdir/llvm-project/build/bin/mlir-opt+0x4739383)
#10 0x0000562e65491cc6 void std::__final_insertion_sort<mlir::Value*, __gnu_cxx::__ops::_Iter_comp_iter<mlir::bufferization::ValueComparator>>(mlir::Value*, mlir::Value*, __gnu_cxx::__ops::_Iter_comp_iter<mlir::bufferization::ValueComparator>) (/home/workdir/llvm-project/build/bin/mlir-opt+0x1877cc6)
#11 0x0000562e6548f5f7 mlir::bufferization::DeallocationState::getMemrefsToRetain(mlir::Block*, mlir::Block*, mlir::ValueRange, llvm::SmallVectorImpl<mlir::Value>&) const (/home/workdir/llvm-project/build/bin/mlir-opt+0x18755f7)
#12 0x0000562e65515b33 llvm::FailureOr<mlir::Operation*> (anonymous namespace)::BufferDeallocation::handleOp<mlir::MemoryEffectOpInterface, mlir::RegionBranchOpInterface, mlir::CallOpInterface, mlir::BranchOpInterface, mlir::RegionBranchTerminatorOpInterface>(mlir::Operation*) OwnershipBasedBufferDeallocation.cpp:0:0
#13 0x0000562e65513f96 mlir::WalkResult llvm::function_ref<mlir::WalkResult (mlir::Block*)>::callback_fn<(anonymous namespace)::BufferDeallocation::deallocate(mlir::FunctionOpInterface)::$_0>(long, mlir::Block*) OwnershipBasedBufferDeallocation.cpp:0:0
#14 0x0000562e65511b4d mlir::WalkResult mlir::detail::walk<mlir::ForwardDominanceIterator<false>>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Block*)>, mlir::WalkOrder) (/home/workdir/llvm-project/build/bin/mlir-opt+0x18f7b4d)
#15 0x0000562e6551089c mlir::bufferization::deallocateBuffersOwnershipBased(mlir::FunctionOpInterface, mlir::bufferization::DeallocationOptions) (/home/workdir/llvm-project/build/bin/mlir-opt+0x18f689c)
#16 0x0000562e65518aa7 mlir::WalkResult llvm::function_ref<mlir::WalkResult (mlir::Operation*)>::callback_fn<std::enable_if<!llvm::is_one_of<mlir::func::FuncOp, mlir::Operation*, mlir::Region*, mlir::Block*>::value && std::is_same<mlir::WalkResult, mlir::WalkResult>::value, mlir::WalkResult>::type mlir::detail::walk<(mlir::WalkOrder)1, mlir::ForwardIterator, (anonymous namespace)::OwnershipBasedBufferDeallocationPass::runOnOperation()::'lambda'(mlir::func::FuncOp), mlir::func::FuncOp, mlir::WalkResult>(mlir::Operation*, (anonymous namespace)::OwnershipBasedBufferDeallocationPass::runOnOperation()::'lambda'(mlir::func::FuncOp)&&)::'lambda'(mlir::Operation*)>(long, mlir::Operation*) OwnershipBasedBufferDeallocation.cpp:0:0
#17 0x0000562e6508f157 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/home/workdir/llvm-project/build/bin/mlir-opt+0x1475157)
#18 0x0000562e6551886b (anonymous namespace)::OwnershipBasedBufferDeallocationPass::runOnOperation() OwnershipBasedBufferDeallocation.cpp:0:0
#19 0x0000562e681b3373 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/workdir/llvm-project/build/bin/mlir-opt+0x4599373)
#20 0x0000562e681b3c12 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/workdir/llvm-project/build/bin/mlir-opt+0x4599c12)
#21 0x0000562e681b63ee mlir::PassManager::run(mlir::Operation*) (/home/workdir/llvm-project/build/bin/mlir-opt+0x459c3ee)
#22 0x0000562e681ae96b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#23 0x0000562e681ae5c4 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
#24 0x0000562e6825a9e5 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) (/home/workdir/llvm-project/build/bin/mlir-opt+0x46409e5)
#25 0x0000562e681a77b2 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/home/workdir/llvm-project/build/bin/mlir-opt+0x458d7b2)
#26 0x0000562e681a7a68 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/home/workdir/llvm-project/build/bin/mlir-opt+0x458da68)
#27 0x0000562e681a7c82 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/home/workdir/llvm-project/build/bin/mlir-opt+0x458dc82)
#28 0x0000562e64f3c4ef main (/home/workdir/llvm-project/build/bin/mlir-opt+0x13224ef)
#29 0x00007f62446efd90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#30 0x00007f62446efe40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#31 0x0000562e64f3c045 _start (/home/workdir/llvm-project/build/bin/mlir-opt+0x1322045)
Aborted (core dumped)