This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add canonicalizations for op -> tensor.cast folding.
ClosedPublic

Authored by mravishankar on Mar 3 2022, 5:14 PM.

Details

Summary

A tensor.cast consumer can be folded with its producer. This is
beneficial only if the result of the tensor cast is more static than
the source. This patch adds a utility function to check that this is
the case, and adds a couple of canonicalizations patterns that fold an
operation with tensor.cast conusmers.

Diff Detail

Event Timeline

mravishankar created this revision.Mar 3 2022, 5:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 5:14 PM
mravishankar requested review of this revision.Mar 3 2022, 5:14 PM

Fix insertion point.

gysit added inline comments.Mar 3 2022, 11:49 PM
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
1228

nit: typo

1758

nit: has a result that is more static?

1788

When reading this part of the code I first had the impression that this creates more casts than it removes and failing may be the better option? But I think the idea is that other patterns such as FoldTensorCastOp will clean up the additional casts? Would a comment and maybe a test make sense here?

gysit added a comment.Mar 3 2022, 11:56 PM

I am confused. Could it be that the last update somehow mixed this revision with https://reviews.llvm.org/D120968? At least may review comments are now mismatched...

Rebase and fix failing test.

mravishankar marked 3 inline comments as done.

Address comments.

mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
1788

Added a comment.

gysit accepted this revision.Mar 8 2022, 12:23 AM
This revision is now accepted and ready to land.Mar 8 2022, 12:23 AM