[Mlir-commits] [mlir] [Linalg] Add matchers to infer which Convolution Op a given linalg.generic is (PR #163374)

Han-Chung Wang llvmlistbot at llvm.org
Tue Oct 14 15:20:43 PDT 2025


hanhanW wrote:

Thanks @Abhishek-Varma for the patch. I'll help review it. Let's add some motivation for the change; I'll add my thoughts below.

> Could we avoid the explosion in exported function names? They're almost identical, modulo the one thing different.

The PR is related to [[RFC] Op explosion in Linalg](https://discourse.llvm.org/t/rfc-op-explosion-in-linalg/82863). We are making progress on matmul side in upstream. E.g., the transpose variants are removed from named ops; we have matchers for the deprecated ops. [https://github.com/llvm/llvm-project/pull/147961]. The revision aims to do something similar, especially for matcher parts. However, we don't have generic conv/depthwise_conv/pooling ops today. Thus, the implementation looks different. I did a quick survey in the beginning, and I felt that the "explosion" is likely needed in the transition period. They are stronger matchers comparing to `isa<linalg::*Conv*>`. I'm happy to learn more if you have an idea about avoiding the explosion. My naive thinking is that we'll need this anyway in the transition period, like other matmul matchers.

The motivation of the change: our goal is to enhance existing patterns to work with generic op form; it requires matchers. Hopefully, the matching logic can be reused when we have the generic conv/depthwise_conv/pooling ops.

Mirroring some context from IREE issue, and the plan of upstream pattern enhancement:

- [DecomposeConvolutionToLowerDimOpsPass](https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Codegen/Common/DecomposeConvolutionToLowerDimOps.cpp): this is the pass that downscale 2D convolution to 1D convolution when either H or W dimensions are ones. The work include updating [the upstream decompose convolution patterns](https://github.com/llvm/llvm-project/blob/580fdeb6ff55fcd54be16ed8555eaaa6a9aee1c0/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp#L1631-L1650) to handle generic form.
- [Vectorization](https://github.com/llvm/llvm-project/blob/main/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp#L4): There are named ops in the file like [linalg::DepthwiseConv1DNwcWcOp](https://github.com/llvm/llvm-project/blob/af82c1a67b3a1dfc05b6149e68caa30103c15ce8/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp#L4236-L4242). We need to switch the `isa` to a matcher. I did not check all the code, but the [core vectorizer](https://github.com/llvm/llvm-project/blob/af82c1a67b3a1dfc05b6149e68caa30103c15ce8/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp#L2705-L2707) is using `linalg::LinalgOp` which is good.

So I think there are two major tasks in the work stream:
- Implement the matchers and use it in IREE and Vectorization.
- Adapt the convolution patterns, that are mentioned in the issue, to accept generalized convolution ops.



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


More information about the Mlir-commits mailing list