<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/193213>193213</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR][MemRef] ExpandStridedMetadata has subview pattern which conflicts with reinterpret cast folding.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir:memref
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
red1bluelost
</td>
</tr>
</table>
<pre>
In ExpandStridedMetadata, the [SubviewFolder pattern](https://github.com/llvm/llvm-project/blob/1697b964ffcf476ff02c4e659bd009c3f949236c/mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp#L187) does the following:
```
subview(x) -> reinterpret_cast(extract_strided_metadata(x) ...)
```
Inside the [ReinterpretCastOp::fold function](https://github.com/llvm/llvm-project/blob/1697b964ffcf476ff02c4e659bd009c3f949236c/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp#L2143), these two patterns occur.
```
reinterpret_cast(reinterpret_cast(x)) -> reinterpret_cast(x)
reinterpret_cast(subview(x)) -> reinterpret_cast(x) if subview offsets are 0
```
If we apply SubviewFolder to the last pattern, it will allow the cast(cast) collapse to happen which disregards if the subview offset was 0 or not.
```
reinterpret_cast(subview(x))
->
reinterpret_cast(reinterpret_cast(extract_strided_metadata(x) ...))
-> // cast(cast) collapse loses the offset data from the original subview
reinterpret_cast(extract_strided_metadata(x))
```
Is this a bug in ExpandStridedMetadata or is this something that MLIR users should avoid?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVV1vozoQ_TXOy2gRmK_wwEPaLlKlrVbq3vfK2AP4ymDkMU3231-ZkOzt3lTtfVspEgpijuecOWcsiHQ_IdYsv2P5w04sfrCudqiS1ixoLPlda9XP-nGCr6dZTOqHd1qhekIvlPCC8XvwAwLL734s7avGY2ONQgez8B7dxPIHxveD9zOx9MB4w3jTaz8sbSTtyHhjzOvl8WV29m-UnvGmNbZlvEmKqmyrIus62WVl0XUxlxkWedWqOK5k2lVZxdNCMt6MRruAo0PdgxbmDPSE4zN2jDd_OTFRZ91IjDc3qURynhlPvyX7kvEKlEVaqXXWGHvUUx8IxAdWxNsvPtCZMuP7Uyj5wtKv4FBPHt3s0L9IQZ7xPZ68E9K_0PnAl_Eq3rkuiiLGq9-wWXx4nEgrvOj7_Av4XpD_Pod-0kNnjYJumaTX9s-R-_H5-u_7TBdpeZKlgenZNITgj_biFAIr5eKi32S4IeeNV6cV9f0JnDZ9b-K9neJHMKA72CrAdh2hJxAOIb4xvw6OCGKezU94mw5v16kaQf6aFH4P2sNRGwMiOG79Yjv4_KhAWmPEHISzMIh5xgmOg5YDKE0Oe-EUhf5C5dse4SgIYrAOJuujc3sfyPwfWVh8CMJ8eiiftP0VGM5-fZezsbRFcuMUwKBzdjy_dLrXkzAX5rf7_KCp2zkMp2oCAe3Sg35nFQZx9fYl2RH9oKce_CA8PH17fIaF0BHQYBejQLxarVja7FSdqiqtxA7rpCyLsizSLN8NNUeZJhlmJU-w5W2cZZUSeSyLNs15WcqdrnnMizjjScLzKs6jfZ60WdGKvNi3VV5ylsU4Cm2iEPbIun6niRaskyrlSbozokVD6-LnfI1zehhxdCG-PNwFrl63RLv0xLLYaPL0C8prb9ZbI1ALWye_27KfP7wjzyDoasrN85t5pZ06o6UnOGo__Dt4qxfCBlZ66qPd4kz9v5fbyjps_Y34a83_CQAA__9bAETJ">