Alexandra Sidorova d0dd371249
[MLIR][Canonicalization] Add shape_cast folding patterns (#183061)
### Summary

This PR adds two shape_cast-related canonicalization patterns for
`vector.to_elements` and `vector.from_elements`.

### Details

- Added` ToElements(ShapeCast(X)) -> ToElements(X)` as an in-place fold
in `ToElementsOp::fold`.
- Added `ShapeCast(FromElements(X)) -> FromElements(X)` as an
`OpRewritePattern` — it must be a pattern (not a `fold`) because we have
to create new op `FromElementsOp` with updated result type. This cannot
be done with a `fold`, because `fold` cannot create new ops and the
existing `FromElementsOp` result type differs from the `ShapeCastOp`
result type. Mutating the `FromElementsOp` (not root op) would violate
the `fold` contract and break other users.
- Added lit tests for the both ops (new `vector-to-elements.mlir`,
`vector-from-elements.mlir`)

---------

Signed-off-by: Alexandra Sidorova <asidorov@amd.com>
2026-03-03 18:12:24 +00:00
..