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

    <tr>
        <th>Summary</th>
        <td>
            DimOp verifier checks for UB-style invariant
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          joker-eph
      </td>
    </tr>
</table>

<pre>
    The DimOp (at least `tensor.dimop`) verifier enforces the absence of out-of-bounds on access when the indexing is a constant.
This kind of checks is an anti-pattern in the verifier and generally belongs to "UB" domain. The reason is that it makes the compiler fragile and transformations non composable. See the simple example below:

```
func.func @dim(%arg : tensor<1x?xf32>) -> index {
 %c2 = arith.constant 2 : index
  %add = arith.addi %c2, %c2 : index
 %dim = tensor.dim %arg, %add : tensor<1x?xf32>
  return %dim : index
}
```

This IR passes the verifier, however `arith.addi` will be folded and lead to an invalid `tensor.dim`. The `DimOp` folder then crashes the compiler because of the assumptions made on the IR. 

In general the guideline for IR verifier is to check only for "local" invariants: that is consistency of types, attributes, and arity in terms of operands/results (we should likely document this better?).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VMFu4zgM_RrlQsRw5NhtDj600wnQ0wKzMx9AS7StqSx5Rblp_n4h2W3axQ4Q2HBEPpGP7xGZzeCIWlE_Cin_Ud76qaMopBT10w6XOPrQ_vYvFPY0j7vO62v7cyR4MtNfMwh5jxEsIUcQTRnJsQ-FNpOfRVMKeYJXCqY3FIBc74MihjgSYMfkFIHvwS9x7_t95xenGbwDVIqY4TKSy7HGaXozbgDDgKC844guFqJ8EuXDz9EwvBinE5QaSb1wjnOALpr9jDFScGBWqI9i0GkYyFFAa6_QkfVuYIgehJS_EhGg_YTGFZB6DYTsXcKNI0YwESZ82TpRfpqNpQB9wMFYytAxoOPehwmj8Y7BeZcDPWNnqYC_iXIym2m2BP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