This commit adds a pattern to swap
tensor.extract_slice(linalg.fill(%cst, %init))
into
linalg.fill(%cst, tensor.extract_slice(%init))
when the linalg.fill op have no other users.
This helps to reduce the fill footprint.
Differential D134102
[mlir][linalg] Swap tensor.extract_slice(linalg.fill) antiagainst on Sep 16 2022, 7:57 PM. Authored by
Details This commit adds a pattern to swap tensor.extract_slice(linalg.fill(%cst, %init)) into linalg.fill(%cst, tensor.extract_slice(%init)) when the linalg.fill op have no other users.
Diff Detail
Event TimelineComment Actions I am apprehensive of adding this as a canonicalization. Canonicalization that involves multiple operations has always been a footgun Comment Actions +1, please just create a new file with a proper name (and suffixed with Patterns.cpp) and let's trigger this on-demand. Comment Actions Friday evening my brain doesnt work as well. This is basically a specialized implementation of https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Dialect/Tensor/Transforms/Transforms.h#L29 which works on any operation that implements the TilingInterface. If you can just use that method, we dont need to diverge (but that does introduce a more heavy weight treatment of this, and the implementation here is simpler). Either way, this shouldnt be a canonicalization. Comment Actions @mravishankar @nicolasvasilache : moved to a separate file and entry point now! Thanks for the suggestion! I tried to use that but found the above 1) does not support non-1 strides, & 2) cannot handle rank-reducing extract_slice ops. I'm not sure how easy to extend the above for both; esp. the above is used for tiling, which later bufferization relies on the tiled structure. OTOH, this pattern itself is already very simple; just a few lines. I'd prefer to keep the current impl. |