This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Linalg] Fold init_tensor -> linalg.tensor_reshape.
ClosedPublic

Authored by mravishankar on Dec 23 2020, 12:46 PM.

Details

Summary

Reshaping an init_tensor can be folded to a init_tensor op of the
final type.

Depends On D93748

Diff Detail

Event Timeline

mravishankar created this revision.Dec 23 2020, 12:46 PM
mravishankar requested review of this revision.Dec 23 2020, 12:46 PM
hanchung added inline comments.Dec 28 2020, 10:46 AM
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
753

This looks weird, how about renaming it to shape?

765

ditto

780–781

Do we really want to crash here? I feel we should just return nullptr and stop rewriting the pattern. Although it's really wrong to have more than one dynamic dims, I don't think it is the pass' responsibility to check it. Otherwise, we could leave many similar check in many passes. I think maybe we can check it in reshape op.

hanchung requested changes to this revision.Dec 28 2020, 10:53 AM
This revision now requires changes to proceed.Dec 28 2020, 10:53 AM
hanchung added inline comments.Dec 28 2020, 11:01 AM
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
780–781

I saw a similar check in https://reviews.llvm.org/D93724

With the patch, I think we don't need to check it here. We can have a follow cleanup for this.

mravishankar marked 2 inline comments as done.Jan 8 2021, 2:22 PM
mravishankar added inline comments.
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
780–781

Thats right. I added it to the verifier too. I just returned nullptr. There might be a path to relaxing this restriction with shape dialect. So I added an assert to say the pattern doesnt handle it. But making it return with nullptr is better. THanks!

Address comments

Fix build errors

hanchung accepted this revision.Jan 10 2021, 11:40 PM
This revision is now accepted and ready to land.Jan 10 2021, 11:40 PM