This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Linalg] Use rank-reduced versions of subtensor/subtensor_insert to drop unit-dims.
ClosedPublic

Authored by mravishankar on Apr 25 2021, 8:54 AM.

Details

Summary

Canonicalizations for subtensor operations defaulted to use the
rank-reduced version of the operation, but the cast inserted to get
back the original type would be illegal if the rank was actually
reduced. Instead make the canonicalization not reduce the rank of the
operation.
Instead add patterns to convert the subtensor and subtensor_insert
operation to their rank-reduced version to DropUnitDims pass.

Diff Detail

Event Timeline

mravishankar created this revision.Apr 25 2021, 8:54 AM
mravishankar requested review of this revision.Apr 25 2021, 8:54 AM
hanchung accepted this revision.Apr 26 2021, 12:01 AM
hanchung added inline comments.
mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp
550–565 ↗(On Diff #340361)

Do we need Optional here? I think we using the size of the vector to check is good enough, and you never return llvm::None in the function.

This revision is now accepted and ready to land.Apr 26 2021, 12:01 AM
mravishankar added inline comments.Apr 26 2021, 10:41 PM
mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp
550–565 ↗(On Diff #340361)

I'd keep the Optional. Its a more robust way to return that the required reassociation could not be computed.

nicolasvasilache accepted this revision.Apr 27 2021, 9:03 AM

Looks good, thanks for fixing!

mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
1862

s/subtensor/subview

mlir/lib/Dialect/StandardOps/IR/Ops.cpp
1975

comment is a bit misleading, could you please update (and even add an assert that the case will be valid) ?

Dropping the patterns that introduced rank-reduced versions of
subtensor and subtensor_insert. They need to be supported on the
SPIR-V backend.

mravishankar marked an inline comment as done.

Fix comments.

This revision was landed with ongoing or failed builds.Apr 28 2021, 11:33 AM
This revision was automatically updated to reflect the committed changes.