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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] -remove-dead-values crashes on scf.if for empty region
        </td>
    </tr>

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

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

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

<pre>
    reproduce with: mlir-opt -remove-dead-values a.mlir

a.mlir:
```
func.func @nested_if(%cond0: i1, %cond1: i1, %cond2: i1, %p: memref<1xf32>) {
  %cst = arith.constant 1.000000e+00 : f32
  scf.if %cond0 {
  } else {
    scf.if %cond1 {
    } else {
      scf.if %cond2 {
        affine.store %cst, %p[0] : memref<1xf32>
      }
    }
  }
  return
}
```

It will crash in cleanRegionBranchOp when access region.front() or region.back().

And could be worked around by adding
```
    if (region.empty())
 continue;
```
to all these access.

There's assert in one of the access:
```
assert(!region.empty() && "expected a non-empty region in an op "
                              "implementing `RegionBranchOpInterface`");
```

But scf.if seems OK to return an empty region for getElseRegion.


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxsVE2PozgQ_TXmUgoyRUPCgQPpTKTRHkZa7X1lTAHeNjayTff0v1_ZIdOfCAWnXB_vvSqV8F5Nhqhl1ZlVl0xsYbauXV_DbE35NAnKeju8to5WZ4dNEryoMLOyg0Urd7BrgIOjxT7TYSAxHJ6F3siDyOM14x3j3X4u45nVfH95N25G5vEH2AM35AMN_6qR4YlhJa0ZeKyiCoaPsFuKLxb8YFkTLlocjax8LH6PJbLyB8MG2PHMeAcpzAdg5QWEU2HOpTU-CBOgyHl6iOGZc4iZYngM8nLM1Xgvyd-SHS9A2tMfw2fX4t3NN86f3fHDHYAYR2Uo98E62pH_IVqdOasu8D3hewp2vLxVv0NOX0dhcyY2JBnet4Xx7meAF6U1SCf8DMqA1CTM3zQpa85OGDn_WuFlJgNCSvIeXLrKR2dNSA1swLq7tRfy6WbMb-k7M4C0mx6gJ3ix7okGEM5uZoD-FcQwKDN9AhU5JKFOe1Ja1vB6yxpf3oG0JiizESvPn4KDBaE1hJk87Yh3JP_M5Ijh0YPwnlyIXK0hsGP03n2_Tu7NOVUvvuIBhjXDGhgi_V5JhkgPjDWH5LTLEksJA3aNfu-a_v3DENWyalookpyA1fxjO36aQG4UkiJCxKjJFx0Y785buA-dJ1o8_PoLgt3HIeL5AHG0DiYKP7SnW7Vdtmxoy6EpG5FRWxzLI68fTk2Tza0sBhKypJFT0cumGjkXnDcnRJR0KmWmWuRY8aKoEXlRNnlFvG6qWpa8H4axLtgDp0UonWv9vOTWTZnyfqO2wBIf6kyLnrRPywoxrZXI9ZEhplmN_6pL5toYfei3ybMHrpUP_i1fUEGndZfCq8u3-ytlIw_W3OWKWrwXJ9ucbucQ1jQfeGV4nVSYtz6XdmF4jfX2z2F19j-SgeE1kfEMrzuf5xb_DwAA__-Ofp_T">