[Mlir-commits] [mlir] [Linalg] Update Vectorization to work with both named as well as generic conv ops (PR #176339)

Han-Chung Wang llvmlistbot at llvm.org
Fri Jan 16 14:08:24 PST 2026


================
@@ -3537,14 +3576,19 @@ struct Conv1DGenerator
     auto maybeKind = getCombinerOpKind(reduceOp);
     reductionKind = maybeKind.value();
 
-    // The ConvolutionOpInterface gives us guarantees of existence for
-    // strides/dilations. However, we do not need to rely on those, we can
-    // simply use them if present, otherwise use the default and let the generic
-    // conv. matcher in the ConvGenerator succeed or fail.
-    auto strides = linalgOp->getAttrOfType<DenseIntElementsAttr>("strides");
-    auto dilations = linalgOp->getAttrOfType<DenseIntElementsAttr>("dilations");
-    strideW = strides ? *strides.getValues<uint64_t>().begin() : 1;
-    dilationW = dilations ? *dilations.getValues<uint64_t>().begin() : 1;
+    // Try to extract strides/dilations from named 1D conv/pool ops using
+    // matchConvolutionOpOfType. This works for both named ops and generic ops
+    // that match their semantics. For unrecognized generic ops, fall back to
+    // checking attributes directly (which may not exist for generic ops).
+    if (!extract1DConvPoolStrideDilation(linalgOp, strideW, dilationW)) {
+      // Fallback: check for stride/dilation attributes directly.
+      // For generic ops without these attributes, default to 1.
+      auto strides = linalgOp->getAttrOfType<DenseIntElementsAttr>("strides");
+      auto dilations =
+          linalgOp->getAttrOfType<DenseIntElementsAttr>("dilations");
+      strideW = strides ? *strides.getValues<uint64_t>().begin() : 1;
+      dilationW = dilations ? *dilations.getValues<uint64_t>().begin() : 1;
+    }
----------------
hanhanW wrote:

I think once we reach here, it should be safe to assume that the `linalgOp` has strides and dilations. Because they are all checked in precondition. We can turn it into an assertion.

However, the above point is from the perspective of this file, while this class is a generator that should not have such assumption. The better code to me is using factory functions to initializer methods. See https://abseil.io/tips/42 for more details. We checked the precondition in construction for safety.

An example code can be found in https://github.com/iree-org/iree/commit/3f52423351650430efdc3f8b80f0d5201d6d9d5b, see the changes in `TileSizeSelection.h|cpp`.

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


More information about the Mlir-commits mailing list