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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR]`-remove-dead-values` triggers Segmentation fault
        </td>
    </tr>

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

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

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

<pre>
    Test on commit: https://github.com/llvm/llvm-project/commit/47928ab16b675c17826ada16f23aa0569e93a474
steps to reproduce:
```
mlir-opt test.mlir --remove-dead-values
```
test case:
```
module {
  func.func @payload() attributes { transform.target_tag = "start_here" } {
    %D = arith.constant dense<1.0> : tensor<2x4xf32>
    %E = arith.constant dense<2.0> : tensor<2x4xf32>
    linalg.generic {
      indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>],
 iterator_types = ["parallel", "parallel"]
    } ins(%D : tensor<2x4xf32>) outs(%E : tensor<2x4xf32>) {
      ^bb0(%arg0: f32, %arg1: f32):
        linalg.yield %arg0 : f32
    } -> tensor<2x4xf32>
    return
  }
}
```
crash trace:
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: ./mlir-opt /home/workdir/test.mlir --remove-dead-values
 #0 0x000062be695969b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./mlir-opt+0x107f9b8)
 #1 0x000062be695944de llvm::sys::RunSignalHandlers() (./mlir-opt+0x107d4de)
 #2 0x000062be695973c8 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007865c63f2520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000062be69e26521 getGenericEffectsImpl(llvm::SmallVectorImpl<mlir::SideEffects::EffectInstance<mlir::MemoryEffects::Effect>>&, mlir::linalg::LinalgOp) LinalgOps.cpp:0:0
 #5 0x000062be6a0dd748 mlir::detail::MemoryEffectOpInterfaceInterfaceTraits::Model<mlir::linalg::GenericOp>::getEffects(mlir::detail::MemoryEffectOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, llvm::SmallVectorImpl<mlir::SideEffects::EffectInstance<mlir::MemoryEffects::Effect>>&) (./mlir-opt+0x1bc6748)
 #6 0x000062be6e969c23 mlir::isMemoryEffectFree(mlir::Operation*) (./mlir-opt+0x6452c23)
 #7 0x000062be6c884434 void llvm::function_ref<void (mlir::Operation*)>::callback_fn<(anonymous namespace)::RemoveDeadValues::runOnOperation()::$_1>(long, mlir::Operation*) RemoveDeadValues.cpp:0:0
 #8 0x000062be696a8a2e void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (./mlir-opt+0x1191a2e)
 #9 0x000062be696a8a2e void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (./mlir-opt+0x1191a2e)
#10 0x000062be6c883d35 (anonymous namespace)::RemoveDeadValues::runOnOperation() RemoveDeadValues.cpp:0:0
#11 0x000062be6c85008f mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0x433908f)
#12 0x000062be6c850872 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0x4339872)
#13 0x000062be6c85301e mlir::PassManager::run(mlir::Operation*) (./mlir-opt+0x433c01e)
#14 0x000062be6c84bb3b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#15 0x000062be6c84b79b 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
#16 0x000062be6c8f5f25 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) (./mlir-opt+0x43def25)
#17 0x000062be6c846682 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (./mlir-opt+0x432f682)
#18 0x000062be6c846933 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x432f933)
#19 0x000062be6c846b42 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x432fb42)
#20 0x000062be69575bd7 main (./mlir-opt+0x105ebd7)
#21 0x00007865c63d9d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#22 0x00007865c63d9e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#23 0x000062be69575745 _start (./mlir-opt+0x105e745)
Segmentation fault (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWdtu2zwSfhrmhoghkTpe-MK1490ADRK0xb-XBiWOZG5pUktSbfL2C0qyLTlWmnb_RfdQtI1Ecma--eZAimHWiloBLFH8AcW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