[MLIR][MemRef] ExpandStridedMetadata has subview pattern which conflicts with reinterpret cast folding.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
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?
Contributor guide
Research direction
Read the SubviewFolder pattern in mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp and ReinterpretCastOp::fold in mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp. Reproduce the nested reinterpret_cast(subview(x)) case, especially with nonzero subview offsets, and determine whether folding loses offset data. Done means establishing the expected behavior and identifying the responsible transformation or required user constraint.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100