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

    <tr>
        <th>Summary</th>
        <td>
            [mlir][llvmir] ExtractValueOp canonicalizer assumes property that is not verified
        </td>
    </tr>

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

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

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

<pre>
    The `llvm.insertvalue` and `llvm.extractvalue` operations require an array attribute for the positions. The exact type of the attributes contained in that array is not checked, but the `extractvalue` folder assumes they are always the same and just checks for equality of the positions using the `==` operator. Thus `1 : i64 != 1 : i32` and the `insertvalue` whose value is supposed to be folded to is skipped. It might be a good idea to either check the attribute types in the verifier or consider this case in the folder.

```mlir
%0 = llvm.mlir.undef : !llvm.array<4 x i32>
%1 = llvm.insertvalue %arg0, %0[0 : i32] : !llvm.array<4 x i32>
%2 = llvm.insertvalue %arg1, %1[1 : i32] : !llvm.array<4 x i32>
%3 = llvm.insertvalue %arg2, %2[2 : i32] : !llvm.array<4 x i32>
%4 = llvm.insertvalue %arg3, %3[3 : i32] : !llvm.array<4 x i32>
%5 = llvm.extractvalue %4[1] : !llvm.array<4 x i32>
llvm.return %5 : i32
```

Calling `mlir-opt --canonicalize` on the above code leads to:

```mlir
%0 = llvm.mlir.undef : !llvm.array<4 x i32>
%1 = llvm.extractvalue %0[1] : !llvm.array<4 x i32>
llvm.return %1 : i32
```

Observed at commit b5a9361c90ca
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VMFuozAQ_Rq4jBIZG0g4cGibrrSnXlZ7NzABt4BZ26TNfv2ODU26PVRVV1oJJdgzfvPeYzyVbs7ljw4hylnfn4atGi0ad5L9jLQFcmwuIXxxRtbXmJ7QSKf0aMHgr1kZpHSQxsgzSOeMqmaHcNQGHBWYtFUheQu-Hr4QFLjzhKCPIeFyxEKtRyfViA2okWLSrajKwqgd1B3WT9hE_A4oPxwmPu_pHXXfoAFp7TwQJmURLc-xf5bnsAYrBwwSH2e7wtpAmOTIXrnzK7cLeZitGtvXkpE4-OfihTZe3Gx9LIFI3IDKU4h4Qlmwbgj-6usK8s7x505bhLD0eu08UXFywmmocBEVFj72pKYJmy18dzCotnM-Q0KrNRnXoPRpqKiMWbT9bXMw3y4OU0E06qgok9ST_VZ571xHVWpJfNasxdNtxA4Ru1l_yYbwDL0y6xbPGHjJoW38_nYeGzwGA8iNsB2-aCTuUngJpoj7y-HkeviNOXQyk6Zl_rP7ClF2yy6WZofPgvOPwJMVPCHw5Avg4iNwvoIT4C3_Anj6EbhYwQWBiy-AZ1fwtxfJQ6bejM9ChaBBN5sRVtiFyt_N8raD7mTf-0u19tBGTw42m1qOelQ1XcPfy7RZOlBW-oTUoQ1Cj7Khe6ypwv9ryPfmsH8wJ_mEOQ8VfekTXXkagrUeBkWXPJOFyJO6YLWMsUzyrNgVeZru46YUTSEKGTvleiyJWvAgO9Cbrx3e4X6R8NNLeJjgrdHXcTkZP9JoAobxuw7edUg08Wz6snNust57_o2elubMXG2JIi18rfVvQ0CPWDtaKoJGSy9ZXuzSuCt5XtTpLs-Tap_uE36Ue16xnZCs2leY8zzuZYW99ToizoMUcbNg-9aOVckZ52zP8iQVKcu3RcrYMdmxQhY7sRf7KGU4SNVvg_HatLEpA6lqbi0Fe2WdvQZJu2pHDMZ5fDm7TptykGg6aVwcBJSB_R8jfzZp">