This is an archive of the discontinued LLVM Phabricator instance.

[mlir][MemRef] Add folder for no-op `memref.subview`.
AbandonedPublic

Authored by mravishankar on Dec 7 2021, 11:10 PM.

Details

Summary

When offsets, sizes and strides are empty, the memref.subview can be
folded into the source. This cannot be done as a folder since a
memref.cast might be required to address the types. Add a
canonicalization pattern for this.

Diff Detail

Event Timeline

mravishankar created this revision.Dec 7 2021, 11:10 PM
mravishankar requested review of this revision.Dec 7 2021, 11:10 PM

Add some comments.

hanchung accepted this revision.Dec 8 2021, 10:27 AM
This revision is now accepted and ready to land.Dec 8 2021, 10:27 AM
bondhugula requested changes to this revision.Dec 8 2021, 7:10 PM
bondhugula added a subscriber: bondhugula.
bondhugula added inline comments.
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
635

This change is not covered by the commit summary and title.

This revision now requires changes to proceed.Dec 8 2021, 7:10 PM

The revision is making an undocumented change to the DimOp's folder.

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

The whole block above is also missing a comment completely as well.

1937

This isn't the right or efficient way to replace an op's result with another Value in a rewrite pattern. RAUW shouldn't be used here; instead:

rewriter.replaceOp(subViewOp, source);

bondhugula added inline comments.Dec 8 2021, 7:19 PM
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
1925

Consider renaming this to EraseTrivialSubView or TrivialSubViewFolder to be consistent with other such simplifiers.

mravishankar marked 3 inline comments as done.

Rebase and address comments.

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

Good catch! Thanks!

bondhugula added inline comments.Dec 9 2021, 10:04 AM
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
1968–1969

Sorted order here.

1981

Typo: empty

1981

I didn't understand this part - it could have dynamic strides, offsets, and sizes, right?

mravishankar added inline comments.Dec 9 2021, 2:07 PM
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
1981

The size of static_offsets acounts for dynamic offsets as well. A -1 is added to static_offsets when the offset is dynamic. (same is true for sizes and strides). The semantics of the subview operation is that missing offsets implies offset is 0, missing sizes implies sizes is same as source size and missing strides implies strides are 1. So all offsets, sizes, and strides missing means that the subview is a no-op.

mravishankar marked 2 inline comments as done.

Address comments and rebase.

bondhugula accepted this revision.Dec 10 2021, 10:32 PM
This revision is now accepted and ready to land.Dec 10 2021, 10:32 PM

Rebase and fix test error.

mravishankar abandoned this revision.Dec 13 2021, 10:39 AM

FYI, closing this patch as not committing. Ideally memref.subview should not allow number of sizes, offsets and strides that are less than the rank of the source. This should be fixed. I am going to try to tackle that instead.