Closed

Description
git version: 9580468
system: Ubuntu 20.04.6 LTS (Focal Fossa)
reproduced with: mlir-opt --eliminate-empty-tensors --eliminate-empty-tensors a.mlir
a.mlir:
%44 = tensor.empty() : tensor<26xi32>
%9 = tensor.empty() : tensor<26xi32>
%45 = linalg.copy ins(%9 : tensor<26xi32>) outs(%44 : tensor<26xi32>) -> tensor<26xi32>
trace:
mlir-opt: /data/bin/llvm-project/mlir/lib/IR/PatternMatch.cpp:307: virtual void mlir::RewriterBase::eraseOp(mlir::Operation*): Assertion `op->use_empty() && "expected 'op' to have no uses"' 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/bin/llvm-project/build/bin/mlir-opt --eliminate-empty-tensors --eliminate-empty-tensors a.mlir
#0 0x0000560ba180516f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x158f16f)
#1 0x0000560ba1802204 SignalHandler(int) Signals.cpp:0:0
#2 0x00007fc60fcc7420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x00007fc60f7b200b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#4 0x00007fc60f791859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#5 0x00007fc60f791729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#6 0x00007fc60f7a2fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#7 0x0000560ba447c939 mlir::RewriterBase::eraseOp(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x4206939)
#8 0x0000560ba4478563 mlir::RewriterBase::replaceOp(mlir::Operation*, mlir::ValueRange) (/data/bin/llvm-project/build/bin/mlir-opt+0x4202563)
#9 0x0000560ba1cda49b mlir::bufferization::eliminateEmptyTensors(mlir::RewriterBase&, mlir::Operation*, mlir::bufferization::OneShotAnalysisState&)::'lambda'(mlir::bufferization::SubsetInsertionOpInterface)::operator()(mlir::bufferization::SubsetInsertionOpInterface) const (.isra.0) EmptyTensorElimination.cpp:0:0
#10 0x0000560ba1cdb117 _ZN4llvm12function_refIFN4mlir10WalkResultEPNS1_9OperationEEE11callback_fnIZNS1_6detail4walkILNS1_9WalkOrderE1ENS1_15ForwardIteratorEZNS1_13bufferization21eliminateEmptyTensorsERNS1_12RewriterBaseES4_RNSC_20OneShotAnalysisStateEEUlNSC_26SubsetInsertionOpInterfaceEE_SH_S2_EENSt9enable_ifIXaantsrSt11disjunctionIJSt7is_sameIT2_S4_ESL_ISM_PNS1_6RegionEESL_ISM_PNS1_5BlockEEEE5valuesrSL_IT3_S2_E5valueESV_E4typeES4_OT1_EUlS4_E_EES2_lS4_ EmptyTensorElimination.cpp:0:0
#11 0x0000560ba1cdb66a (anonymous namespace)::EmptyTensorElimination::runOnOperation() EmptyTensorElimination.cpp:0:0
#12 0x0000560ba426117e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x3feb17e)
#13 0x0000560ba426165a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/bin/llvm-project/build/bin/mlir-opt+0x3feb65a)
#14 0x0000560ba4261e84 mlir::PassManager::run(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x3febe84)
#15 0x0000560ba425275b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#16 0x0000560ba4253c14 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#17 0x0000560ba4253dc4 mlir::LogicalResult llvm::function_ref<mlir::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&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#18 0x0000560ba43522b4 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) (/data/bin/llvm-project/build/bin/mlir-opt+0x40dc2b4)
#19 0x0000560ba424d1e7 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/bin/llvm-project/build/bin/mlir-opt+0x3fd71e7)
#20 0x0000560ba42540eb mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x3fde0eb)
#21 0x0000560ba173e1cb main (/data/bin/llvm-project/build/bin/mlir-opt+0x14c81cb)
#22 0x00007fc60f793083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#23 0x0000560ba17d5d9e _start (/data/bin/llvm-project/build/bin/mlir-opt+0x155fd9e)
Aborted (core dumped)