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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] RemoveDeadValues pass errors on unreachable operation
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            rejects-valid,
            mlir
      </td>
    </tr>

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

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

<pre>
    Consider (https://godbolt.org/z/7c7oqqEY7):
```mlir
module @test {
  func.func @foo() {
    %false = arith.constant false
    %zero = arith.constant 0 : i64
    cf.cond_br %false, ^bb1, ^bb4
  ^bb1:
    %3 = arith.cmpi eq, %zero, %zero : i64
    cf.br ^bb1
  ^bb4:
    return
  }
}
```
For some reason `--remove-dead-values` chokes on this and errors rather than just removing the block
```console
<source>:7:10: error: null operand found
 %3 = arith.cmpi eq, %zero, %zero : i64
         ^
<source>:7:10: note: see current operation: %1 = "arith.cmpi"(<<NULL VALUE>>, <<NULL VALUE>>) <{predicate = 0 : i64}> : (<<NULL TYPE>>, <<NULL TYPE>>) -> i1
```

Not sure if #153732 is in any way related but in both cases the cause of the problem seems to be an unreachable block.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVE2P2zYQ_TXjy8AGRVqWddBB6w-gwDYo0iZATgUljS0mFOnlxxabX1-Qcmw3TXuJYZAU3_C9meFwpPfqbIgaKJ-g3C9kDKN1ze_KOakGWnR2eGt21ng1kEPg2zGEiwfRAj8CP57t0FkdVtadgR-_Aj9WfWVfXg6fKuB1MmMtbNj8n7RywNrJDlETwpoF8gGhegLWIp6i6VdpSMjJWuBb4PUNRgRenqT2hCD2KJ0K46q3xgdpAmbgbveVnP2RGUMQLarN-mranxI2_Nm5GzvwHUJ56Lritpqtr5s5pKuMeNSYLgrpJR-aHXhY_ls2Kc6EN-71ndtRiM7MULVPOZzHb5kE1h6tQ28nQkfSW4OwYculo8m-0nIgOSxfpY7kYcOwH-0X8mgNhlF5lGZAcs46j06GkRyGURr8HH3ATKDMGcNI2Gnbf3mUTXm0OuUZxM7b6HoCcQDRViDagqUgM3FamKg12gu5JHey0QwpnJ9IWv5Befg_dWMDpdkTYR-dIxNmH4KyJgHAyyLrA-d3F4DzVG1iB2L37sPzM35snz8cMvkhO_QfSJ2R6uniaFC9DHNp3ous2oM44Kz7SP_Hp99-zP4I1LhMp1Xx3cUDa9_ZgD46QnVC4KIoRSU4Ko_KoDRv-Jd8Q0daBhqwiyFtdzaM2EtPPl9tL6MntKf8cXG20zSlrE0eg8WOUBqMxpHsR9npaymsFkMjhlrUckFNUZWlYGtRF4uxYXVP1ZpKxuuKCTb0664oB7Y9yarYbjq5UA1nvGTbYsOYEEWxqmW_7jpWC7bhRVUwWDOapNIrrV-n1E4WyvtITVGKmm0WWnakfW5SnDv6TH3wqcLVkO9uB5zn7sJ5amKuSSzLLp49rJlWPvg7b1BB53b36_Mv76Hc4_v8aPYkh4_5yeBFev_thdh_5uFWTIvodPNdL1RhjN2qtxPwY5K7TsuLs8lh4Mcckwd-vIb12vC_AwAA__8Ox54D">