This is an archive of the discontinued LLVM Phabricator instance.

[mlir][vector] Add patterns to cast away leading 1-dim
ClosedPublic

Authored by antiagainst on Feb 2 2021, 7:30 AM.

Details

Summary

This patch adds patterns to use vector.shape_cast to cast
away leading 1-dimensions from a few vector operations.
It allows exposing more canonical forms of vector.transfer_read,
vector.transfer_write, vector_extract_strided_slice, and
vector.insert_strided_slice. With this, we can have more
opportunity to cancelling extract/insert ops or forwarding
write/read ops.

Depends On D95825

Diff Detail

Event Timeline

antiagainst created this revision.Feb 2 2021, 7:30 AM
antiagainst requested review of this revision.Feb 2 2021, 7:30 AM
aartbik added inline comments.Feb 2 2021, 10:55 AM
mlir/include/mlir/Dialect/Vector/VectorOps.h
38

nit: all methods in this file operate on vector ops
how about

/// Collect a set of leading-one dimension removal patterns.

(fits on one line too)

mlir/test/Dialect/Vector/vector-transforms.mlir
649

can you please add a test for only 1 dimensions too (since that is a special case in your code).
e.g. vector<1x1x1x1xf32>

Address comments

antiagainst marked 2 inline comments as done.Feb 4 2021, 7:57 AM
ThomasRaoux added inline comments.Feb 4 2021, 8:05 AM
mlir/lib/Dialect/Vector/VectorTransforms.cpp
2719

Can you cast to ShapedType instead? That would allow it to work for transfer_op on tensor. Also you should be able to use cast<> if you do that, since the source has to be ShapedType.

2760

same comment

Address comments

antiagainst marked 2 inline comments as done.Feb 4 2021, 11:26 AM
ThomasRaoux accepted this revision.Feb 4 2021, 11:59 AM
This revision is now accepted and ready to land.Feb 4 2021, 11:59 AM
This revision was automatically updated to reflect the committed changes.