[Mlir-commits] [mlir] [mlir] Canonicalize tensor.extract_slice (linalg.fill) (PR #112619)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Oct 22 23:07:09 PDT 2024


MaheshRavishankar wrote:

> Let me try to summarize based on the discussions we've had so far.
> 
> Folding of `extract_slice` into `linalg.fill` when the latter op has single vs multiple consumers. Do we consider either/both of them as part of canonicalization? I think there's agreement when there's a single consumer of `FillOp`, this pass produces a simpler representation of the same set of input instructions.
> 
> When there's multiple consumers, an additional `tensor.empty` needs to be introduced since replacing the old `FillOp` with a new sliced `FillOp` might not always work. An example of where it will not work:
> 
> ```
> %1 = linalg.fill
> %2 = tensor.extract %1
> %3 = scf.for [%1]
> ```
> 
> I see two options here:
> 
> 1. Don't enforce single consumer constraint and have an additional `tensor.empty`.
> 2. I can also create a separate pattern like https://github.com/llvm/llvm-project/blob/78e026f845fb4d924673a9d534cc36cf7b55473c/mlir/lib/Dialect/Linalg/Transforms/SwapExtractSliceWithFillPatterns.cpp

I think Andrej's point is good. If we want to add a canonicalization, we add it for a single user of the `linalg.fill`. But mainly I think we want to add a separate pattern that does the "bubbling up" of `extract_slice` irrespective of number of uses and that is a separate pattern + `populate` method. 

https://github.com/llvm/llvm-project/pull/112619


More information about the Mlir-commits mailing list