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

Nithin Meganathan llvmlistbot at llvm.org
Tue Oct 22 19:11:23 PDT 2024


nithinsubbiah 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


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


More information about the Mlir-commits mailing list