Skip to content

[vector][mlir] Canonicalize to shape_cast where possible #140583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

newling
Copy link
Contributor

@newling newling commented May 19, 2025

Discussions suggest that we should use shape_cast as a canonical form of broadcast/transpose/extract where possible (see #138777)

For example these can all be expressed as shape casts:

%0 = vector.broadcast %arg0 : vector<4xi8> to vector<1x1x4xi8>
%1 = vector.transpose %arg1, [1, 0] : vector<2x1xi8> to vector<1x2xi8>
%2 = vector.extract %arg2[0] : vector<4xi8> from vector<1x4xi8>

This PR adds canonicalizes to convert the above 3 examples to shape_casts. It also removes patterns for

shape_cast(transpose) -> shape_cast and
transpose(shape_cast) -> shape_cast

as these foldings are now reachable via the new canonicalization. Specifically

shape_cast(transpose) -> shape_cast(shape_cast) -> shape_cast and
transpose(shape_cast) -> shape_cast(shape_cast) -> shape_cast

IMO the code is overall simplified by this PR. Other notes to reviewers:

  • function static bool isOrderPreserving unchanged, just moved closer to usage.
  • test movement: tests of shape_cast(broadcast) / shape_cast(transpose) / transpose(shape_cast) removed or moved to new test file.
  • PR will be a bit simpler after [mlir][ArmSME] Remove ConvertIllegalShapeCastOpsToTransposes #139706 (scalable vectors) so let's get that in first

@newling newling changed the title [vector][mlir] Canonicalize to shape_cast where possible [wip][vector][mlir] Canonicalize to shape_cast where possible May 19, 2025
@newling newling changed the title [wip][vector][mlir] Canonicalize to shape_cast where possible [vector][mlir] Canonicalize to shape_cast where possible May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant