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

    <tr>
        <th>Summary</th>
        <td>
            [mlir][tensor] double --eliminate-empty-tensors crashed with assertion failure "expected 'op' to have no uses"
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          anonymousMCS
      </td>
    </tr>
</table>

<pre>
    git version: 9580468302a1c8f6236a121163c9087ac4e02cfe

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)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWV1T4zjW_jXmRkVKlr8vuAjg1OQtaChMz7s1Ny7ZPk40rUheSaZhf_2W5CTY6UCnm67Z2aWApCSdR-c850NfVGu2EgAXXnTpRddntDdrqS6okOJlI3t9e1WcVbJ5uVgxg55AaSaFF8xRFqU4jNMAE-rXaRuTIKY-8f04qDOcJrQOAZO6BQ9fe3g-_Ncv2sDGSnsxHn4_V70wPSJ4hsNZjG4eC-SRdCFrytFCak09ku0Hj7EUdEo2fQ0N-srMegK64Uydy86g83PgbMMENXAOm868nBsQWir9Tg-dWfGjc267gvm48XAkicIQecE1GgBnDt0jqUcyZLUcmr3gisTPLCBekO8Fs5-UCyMnyJmgfDWrZfeCmNBONnpTmGRI9mY7yqn81rBzL8jfnv4YUUbRGl55mg7Zece5jCwaaqhHFhUTHllw_rQ575T8E2rjkYWjmyw4qzyyWD54ZHFPjQElbqmp17O667xgHuDEQj0xZXrK0ZNkDdr5KZg_wFfFDKhLqmFoAUU13HUeSV9H3XWgqLGhTeY24oI5mmsNyjbZuJKdJaHXUE7cQmKPxMgjBJ47qA00yCOJ7DySICPRmj4BEhL1GrRHiG1tKePQzAYi7m_yeZEj3VcbZhBFVb9CCjqpjJM2ptNWO7LwyGLFzLqvZrXcbFn6liymdW8nWiAqGsREzfsGkFkDqhXVa1TR-otzzHb6wtD6C2r6Tbf3FJ4h93Ov5ErRDaJq1W9AGH2Cr6qe8Wbf-StS0KmEPB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