[Mlir-commits] [mlir] [mlir][linalg] Fix vectorization precondition for tensor.pad (PR #175869)

Ian Wood llvmlistbot at llvm.org
Tue Jan 13 15:55:29 PST 2026


https://github.com/IanWood1 created https://github.com/llvm/llvm-project/pull/175869

This changes `padOp.getLow()` to `padOp.getMixedLowPad()` in `vectorizePadOpPrecondition()`. The `getMixedLowPad()` function correctly returns both static and dynamic padding values, ensuring that the indexing is correct when checking for non-zero low padding on non-unit result dimensions. Using the added test as an example, `getLow()` would only return	`%low`, which means `en.index()` would be 0 instead of the correct dimension index 1.

>From 1ea4e7aaa8f44717431ca3da63c719e76ad22068 Mon Sep 17 00:00:00 2001
From: Ian Wood <ianwood at u.northwestern.edu>
Date: Tue, 13 Jan 2026 15:49:56 -0800
Subject: [PATCH] [mlir][linalg] Fix vectorization precondition check for
 tensor.pad

Signed-off-by: Ian Wood <ianwood at u.northwestern.edu>
---
 .../Linalg/Transforms/Vectorization.cpp       |  4 +--
 .../Linalg/vectorization/unsupported.mlir     | 25 +++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
index 52d651b59bbd0..5ddefb726080e 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
@@ -2511,8 +2511,8 @@ vectorizePadOpPrecondition(tensor::PadOp padOp,
   // which is zero here. Hence we will load the pad value which is what we want
   // in this case. If the low pad is dynamically zero then the lowering is
   // correct as well as no shifts are necessary.
-  if (llvm::any_of(llvm::enumerate(padOp.getLow()), [&](const auto &en) {
-        Value padValue = en.value();
+  if (llvm::any_of(llvm::enumerate(padOp.getMixedLowPad()), [&](const auto &en) {
+        OpFoldResult padValue = en.value();
         unsigned pos = en.index();
         std::optional<int64_t> pad = getConstantIntValue(padValue);
         return (!pad.has_value() || pad.value() != 0) &&
diff --git a/mlir/test/Dialect/Linalg/vectorization/unsupported.mlir b/mlir/test/Dialect/Linalg/vectorization/unsupported.mlir
index f653a4852b074..eb7cbfd4ed6d7 100644
--- a/mlir/test/Dialect/Linalg/vectorization/unsupported.mlir
+++ b/mlir/test/Dialect/Linalg/vectorization/unsupported.mlir
@@ -332,6 +332,31 @@ module attributes {transform.with_named_sequence} {
 
 // -----
 
+// This test verifies that vectorization correctly handles mixed static/dynamic
+// low padding.
+func.func @tensor_pad_non_zero_low_pad_mixed_dynamic_static(
+  %0 : tensor<1x?xf32>, %low : index, %high : index)
+    -> tensor<1x3xf32> {
+  // expected-error @+3 {{Attempted to vectorize, but failed}}
+  %cst = arith.constant 42.43 : f32
+  %1 = tensor.pad %0 low[0, %low] high[0, %high]  {
+    ^bb0(%i: index, %j: index):
+      tensor.yield %cst : f32
+    } : tensor<1x?xf32> to tensor<1x3xf32>
+  return %1: tensor<1x3xf32>
+}
+
+module attributes {transform.with_named_sequence} {
+  transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
+    %0 = transform.structured.match ops{["tensor.pad"]} in %arg1
+      : (!transform.any_op) -> !transform.any_op
+    transform.structured.vectorize %0 vector_sizes [2, 4] : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
 // With dynamically shaped source, the vectorizer infers the vector size for
 // xfer Ops from the destination tensor and, conservatively, assumes
 // out-of-bounds accesses. Out-of-bounds accesses require a pad value, but



More information about the Mlir-commits mailing list