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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] -affine-loop-invariant-code-motion fails with parallel min/max bounds
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          sung-kim
      </td>
    </tr>
</table>

<pre>
    - LLVM/MLIR version: 14.0.3, commit 1f9140064dfbfb0bbda8e51306ea51080b2f7aac
- To reproduce: `mlir-opt -affine-loop-invariant-code-motion minimal.mlir`

Input:
```
func @minimal(%arg0: memref<4x4xf32>) {
  affine.for %a = 0 to 4 {
    affine.parallel (%b) = (0) to (4) step (1) {
      affine.for %c = 0 to 4 {
        affine.parallel (%d) = (max(0, %b)) to (4) step (1) {
        //affine.parallel (%d) = (0) to (min(0, %b)) step (1) {
          %0 = affine.load %arg0[%a, %c] : memref<4x4xf32>
        }
      }
    }
  }
  return
}
```

Output: 
```
minimal.mlir:7:16: error: operand #2 does not dominate this use
          %0 = affine.load %arg0[%a, %c] : memref<4x4xf32>
               ^
minimal.mlir:7:16: note: see current operation: %0 = "affine.load"(%arg0, %arg1, %arg3) {map = affine_map<(d0, d1) -> (d0, d1)>} : (memref<4x4xf32>, index, index) -> f32
minimal.mlir:4:7: note: operand defined as a block argument (block #0 neither in a parent nor in a child region)
      affine.for %c = 0 to 4 {
```

If I'm not mistaken, in this example we would expect the load to get hoisted out of parallel loop `%d`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VU1v3DgM_TX2hfBAlr9mDj6kSQMESLFAUfRayBY9o40tGZKczP77pWxP4hSTdntZwJmQksj3nkRRjZH_1Ak8Pn7_EvH7L48PX-EZrVNGR9kNpPmO7bKI30JrhkF5SLtDmjNW5rJruoY1jRR7LNKMlSiKlO1Z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