[Mlir-commits] [llvm] [mlir] [Linalg] Fix crash in vectorizeScalableVectorPrecondition with undersized vector sizes (PR #205493)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Aug 24 02:36:51 PDT 2026


https://github.com/LouisLu060211 updated https://github.com/llvm/llvm-project/pull/205493

>From d0025a31adc57d20b85540ae85a963c9fc49ffa2 Mon Sep 17 00:00:00 2001
From: LouisLu0602 <yaolu0602 at gmail.com>
Date: Wed, 24 Jun 2026 15:09:36 +0800
Subject: [PATCH 1/7] Fix crash in vectorizeOpPrecondition when vector sizes
 array is too short

[MLIR][Vector] Add regression test for bug #204100 (mixed static/dynamic vector sizes)

Remove accidentally created file vectorize-dynamic-mixed-sizes.mlir

Remove mlir_venv/ from .gitignore (directory already deleted)

Fix comment about regression test location in Vectorization.cpp

Correct the path in the comment from .../Linalg/transform/... to .../Linalg/...
(the test actually lives directly under Linalg). Also update the
related vector-to-llvm test for consistency.

remove venv

Remove lldb/python_api from .gitignore

Fix emitSilenceableFailure to use target->getLoc()
---
 .gitignore                                    |  2 +
 .gitignorees                                  | 92 +++++++++++++++++++
 a.mlir                                        | 13 +++
 .../TransformOps/LinalgTransformOps.cpp       |  1 -
 .../Linalg/Transforms/Vectorization.cpp       | 12 +++
 .../Vector/transform-op-vector-to-llvm.mlir   | 26 ++++++
 .../Vector/transform-op-vector-to-llvm.mlires | 43 +++++++++
 7 files changed, 188 insertions(+), 1 deletion(-)
 create mode 100644 .gitignorees
 create mode 100644 a.mlir
 create mode 100644 mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlires

diff --git a/.gitignore b/.gitignore
index a4382c9ea7390..ac57b104aa4e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -90,3 +90,5 @@ pythonenv*
 /clang/utils/analyzer/projects/*/RefScanBuildResults
 # automodapi puts generated documentation files here.
 /lldb/docs/python_api/
+<<<<<<< HEAD
+<<<<<<< HEAD
diff --git a/.gitignorees b/.gitignorees
new file mode 100644
index 0000000000000..a4382c9ea7390
--- /dev/null
+++ b/.gitignorees
@@ -0,0 +1,92 @@
+#==============================================================================#
+# This file specifies intentionally untracked files that git should ignore.
+# See: http://www.kernel.org/pub/software/scm/git/docs/gitignore.html
+#
+# This file is intentionally different from the output of `git svn show-ignore`,
+# as most of those are useless.
+#==============================================================================#
+
+#==============================================================================#
+# File extensions to be ignored anywhere in the tree.
+#==============================================================================#
+# Temp files created by most text editors.
+*~
+# Emacs lock files
+.#*
+# Merge files created by git.
+*.orig
+# Reject files created by patch.
+*.rej
+# Byte compiled python modules.
+*.pyc
+# vim swap files
+.*.sw?
+.sw?
+#macOS specific
+.DS_Store
+
+# Ignore the user specified CMake presets in subproject directories.
+/*/CMakeUserPresets.json
+
+# Nested build directory
+/build*
+
+#==============================================================================#
+# Explicit files to ignore (only matches one).
+#==============================================================================#
+# Various tag programs
+/tags
+/TAGS
+/GPATH
+/GRTAGS
+/GSYMS
+/GTAGS
+/ID
+.gitusers
+autom4te.cache
+cscope.files
+cscope.out
+autoconf/aclocal.m4
+autoconf/autom4te.cache
+/compile_commands.json
+/tablegen_compile_commands.yml
+# Visual Studio built-in CMake configuration
+/CMakeSettings.json
+# CLion project configuration
+/.idea
+/cmake-build*
+# Coding assistants' stuff
+.agents/
+/CLAUDE.md
+/instructions.md
+.claude/
+/GEMINI.md
+.gemini/
+AGENTS.md
+.codex/
+# Cursor specific files
+.cursor
+.cursorignore
+.cursorindexingignore
+
+#==============================================================================#
+# Directories to ignore (do not add trailing '/'s, they skip symlinks).
+#==============================================================================#
+# VS2017 and VSCode config files.
+.vscode
+.vs
+#zed config files
+.zed
+# pythonenv for github Codespaces
+pythonenv*
+# clangd index. (".clangd" is a config file now, thus trailing slash)
+.clangd/
+.cache
+.clangd
+# static analyzer regression testing project files
+/clang/utils/analyzer/projects/*/CachedSource
+/clang/utils/analyzer/projects/*/PatchedSource
+/clang/utils/analyzer/projects/*/ScanBuildResults
+/clang/utils/analyzer/projects/*/RefScanBuildResults
+# automodapi puts generated documentation files here.
+/lldb/docs/python_api/
diff --git a/a.mlir b/a.mlir
new file mode 100644
index 0000000000000..17b8861438a17
--- /dev/null
+++ b/a.mlir
@@ -0,0 +1,13 @@
+module {
+  func.func @add_dynamic(%arg0: memref<?x?bf16>, %arg1: memref<?x?bf16>, %arg2: memref<?x?bf16>) {
+    linalg.add ins(%arg0, %arg1 : memref<?x?bf16>, memref<?x?bf16>) outs(%arg2 : memref<?x?bf16>)
+    return
+  }
+  module attributes {transform.with_named_sequence} {
+    transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {
+      %0 = transform.structured.match ops{["linalg.add"]} in %arg0 : (!transform.any_op) -> !transform.any_op
+      transform.structured.vectorize %0 vector_sizes [8, 16, 4] : !transform.any_op
+      transform.yield 
+    }
+  }
+}
diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index f44693096b26b..4f9eb70d661e2 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -4174,7 +4174,6 @@ DiagnosedSilenceableFailure transform::VectorizeOp::apply(
       return mlir::emitSilenceableFailure(target->getLoc())
              << "Unsupported Op, cannot vectorize";
     }
-    FailureOr<VectorizationResult> vectorResults =
         linalg::vectorize(rewriter, target, vectorSizes, getScalableSizes(),
                           getVectorizeNdExtract().value_or(false),
                           /*flatten1DDepthwiseConv=*/false,
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
index b57e66a1c3580..95b05be723d7e 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
@@ -2381,6 +2381,18 @@ vectorizeScalableVectorPrecondition(Operation *op,
     return success(isa<linalg::UnPackOp>(op));
   }
 
+  // Ensure that the number of vector sizes and scalable flags provided by the
+  // user does not exceed the number of loops in the target Linalg op.
+  // Accessing iterator types with an out-of-bounds index would cause an
+  // assertion failure (SmallVector::operator[]). This check converts such a
+  // crash into a clean failure, allowing the transform interpreter to report
+  // an error gracefully.
+  // Regression test:
+  // mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
+  if (inputScalableVecDims.size() > linalgOp.getNumLoops() ||
+      inputVectorSizes.size() > linalgOp.getNumLoops())
+    return failure();
+
   // Cond 2: There's been no need for more than 2 scalable dims so far
   if (numOfScalableDims > 2)
     return failure();
diff --git a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
index 271cdf0e059f4..a74e52dfd4bdb 100644
--- a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
+++ b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
@@ -19,3 +19,29 @@ module attributes {transform.with_named_sequence} {
     transform.yield
   }
 }
+
+// -----
+
+// RUN: mlir-opt %s -transform-interpreter -verify-diagnostics
+// Regression test for bug #204100.
+// Assertion idx < size() in SmallVector.h used to happen here.
+// CHECK-LABEL: func @add_dynamic
+module {
+  func.func @add_dynamic(%arg0: memref<?x?xbf16>, %arg1: memref<?x?xbf16>, %arg2: memref<?x?xbf16>) {
+    linalg.add ins(%arg0, %arg1 : memref<?x?xbf16>, memref<?x?xbf16>) outs(%arg2 : memref<?x?xbf16>)
+    return
+  }
+  module attributes {transform.with_named_sequence} {
+    transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {
+      %0 = transform.structured.match ops{["linalg.add"]} in %arg0 : (!transform.any_op) -> !transform.any_op
+      // This combination was crashing (static/dynamic mismatch)
+      transform.structured.vectorize %0 vector_sizes [8, [16], 4] : !transform.any_op
+      // expected-error @above {{Attempted to vectorize, but failed}}
+      transform.yield
+    }
+  }
+}
+
+
+
+
diff --git a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlires b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlires
new file mode 100644
index 0000000000000..0ef5c7efaeab9
--- /dev/null
+++ b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlires
@@ -0,0 +1,43 @@
+// RUN: mlir-opt %s -transform-interpreter -verify-diagnostics -allow-unregistered-dialect -split-input-file | FileCheck %s
+
+// CHECK-LABEL: func @lower_to_llvm
+//   CHECK-NOT:   vector.bitcast
+//       CHECK:   llvm.bitcast
+func.func @lower_to_llvm(%input: vector<f32>) -> vector<i32> {
+  %0 = vector.bitcast %input : vector<f32> to vector<i32>
+  return %0 : vector<i32>
+}
+
+module attributes {transform.with_named_sequence} {
+  transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
+    %0 = transform.structured.match ops{["func.func"]} in %arg1 : (!transform.any_op) -> !transform.any_op
+    transform.apply_conversion_patterns to %0 {
+      transform.apply_conversion_patterns.vector.vector_to_llvm
+    } with type_converter {
+      transform.apply_conversion_patterns.memref.memref_to_llvm_type_converter
+    } {legal_dialects = ["func", "llvm"]} : !transform.any_op
+    transform.yield
+  }
+}
+
+// RUN: mlir-opt %s -transform-interpreter -verify-diagnostics
+// Regression test for bug #204100.
+// Assertion idx < size() in SmallVector.h used to happen here.
+// CHECK-LABEL: func @add_dynamic
+module {
+  func.func @add_dynamic(%arg0: memref<?x?xbf16>, %arg1: memref<?x?xbf16>, %arg2: memref<?x?xbf16>) {
+    linalg.add ins(%arg0, %arg1 : memref<?x?xbf16>, memref<?x?xbf16>) outs(%arg2 : memref<?x?xbf16>)
+    return
+  }
+  module attributes {transform.with_named_sequence} {
+    transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {
+      %0 = transform.structured.match ops{["linalg.add"]} in %arg0 : (!transform.any_op) -> !transform.any_op
+      // This combination was crashing (static/dynamic mismatch)
+      transform.structured.vectorize %0 vector_sizes [8, [16], 4] : !transform.any_op
+      // expected-error @above {{Attempted to vectorize, but failed}}
+      transform.yield
+    }
+  }
+}
+
+

>From 694f9e08f507a61d7f22d881bca8e5894227d9bc Mon Sep 17 00:00:00 2001
From: LouisLu0602 <yaolu0602 at gmail.com>
Date: Thu, 25 Jun 2026 09:38:02 +0800
Subject: [PATCH 2/7] Fixing comments

---
 .gitignorees                                  | 92 -------------------
 a.mlir                                        | 13 ---
 .../TransformOps/LinalgTransformOps.cpp       |  1 +
 3 files changed, 1 insertion(+), 105 deletions(-)
 delete mode 100644 .gitignorees
 delete mode 100644 a.mlir

diff --git a/.gitignorees b/.gitignorees
deleted file mode 100644
index a4382c9ea7390..0000000000000
--- a/.gitignorees
+++ /dev/null
@@ -1,92 +0,0 @@
-#==============================================================================#
-# This file specifies intentionally untracked files that git should ignore.
-# See: http://www.kernel.org/pub/software/scm/git/docs/gitignore.html
-#
-# This file is intentionally different from the output of `git svn show-ignore`,
-# as most of those are useless.
-#==============================================================================#
-
-#==============================================================================#
-# File extensions to be ignored anywhere in the tree.
-#==============================================================================#
-# Temp files created by most text editors.
-*~
-# Emacs lock files
-.#*
-# Merge files created by git.
-*.orig
-# Reject files created by patch.
-*.rej
-# Byte compiled python modules.
-*.pyc
-# vim swap files
-.*.sw?
-.sw?
-#macOS specific
-.DS_Store
-
-# Ignore the user specified CMake presets in subproject directories.
-/*/CMakeUserPresets.json
-
-# Nested build directory
-/build*
-
-#==============================================================================#
-# Explicit files to ignore (only matches one).
-#==============================================================================#
-# Various tag programs
-/tags
-/TAGS
-/GPATH
-/GRTAGS
-/GSYMS
-/GTAGS
-/ID
-.gitusers
-autom4te.cache
-cscope.files
-cscope.out
-autoconf/aclocal.m4
-autoconf/autom4te.cache
-/compile_commands.json
-/tablegen_compile_commands.yml
-# Visual Studio built-in CMake configuration
-/CMakeSettings.json
-# CLion project configuration
-/.idea
-/cmake-build*
-# Coding assistants' stuff
-.agents/
-/CLAUDE.md
-/instructions.md
-.claude/
-/GEMINI.md
-.gemini/
-AGENTS.md
-.codex/
-# Cursor specific files
-.cursor
-.cursorignore
-.cursorindexingignore
-
-#==============================================================================#
-# Directories to ignore (do not add trailing '/'s, they skip symlinks).
-#==============================================================================#
-# VS2017 and VSCode config files.
-.vscode
-.vs
-#zed config files
-.zed
-# pythonenv for github Codespaces
-pythonenv*
-# clangd index. (".clangd" is a config file now, thus trailing slash)
-.clangd/
-.cache
-.clangd
-# static analyzer regression testing project files
-/clang/utils/analyzer/projects/*/CachedSource
-/clang/utils/analyzer/projects/*/PatchedSource
-/clang/utils/analyzer/projects/*/ScanBuildResults
-/clang/utils/analyzer/projects/*/RefScanBuildResults
-# automodapi puts generated documentation files here.
-/lldb/docs/python_api/
diff --git a/a.mlir b/a.mlir
deleted file mode 100644
index 17b8861438a17..0000000000000
--- a/a.mlir
+++ /dev/null
@@ -1,13 +0,0 @@
-module {
-  func.func @add_dynamic(%arg0: memref<?x?bf16>, %arg1: memref<?x?bf16>, %arg2: memref<?x?bf16>) {
-    linalg.add ins(%arg0, %arg1 : memref<?x?bf16>, memref<?x?bf16>) outs(%arg2 : memref<?x?bf16>)
-    return
-  }
-  module attributes {transform.with_named_sequence} {
-    transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {
-      %0 = transform.structured.match ops{["linalg.add"]} in %arg0 : (!transform.any_op) -> !transform.any_op
-      transform.structured.vectorize %0 vector_sizes [8, 16, 4] : !transform.any_op
-      transform.yield 
-    }
-  }
-}
diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index 4f9eb70d661e2..f44693096b26b 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -4174,6 +4174,7 @@ DiagnosedSilenceableFailure transform::VectorizeOp::apply(
       return mlir::emitSilenceableFailure(target->getLoc())
              << "Unsupported Op, cannot vectorize";
     }
+    FailureOr<VectorizationResult> vectorResults =
         linalg::vectorize(rewriter, target, vectorSizes, getScalableSizes(),
                           getVectorizeNdExtract().value_or(false),
                           /*flatten1DDepthwiseConv=*/false,

>From be6e6290fc9fba553598b79229f7cc5391579c2d Mon Sep 17 00:00:00 2001
From: LouisLu060211 <38174270+LouisLu060211 at users.noreply.github.com>
Date: Thu, 25 Jun 2026 09:39:01 +0800
Subject: [PATCH 3/7] Fix merge conflict in .gitignore

Remove merge conflict markers from .gitignore
---
 .gitignore | 2 --
 1 file changed, 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index ac57b104aa4e0..a4382c9ea7390 100644
--- a/.gitignore
+++ b/.gitignore
@@ -90,5 +90,3 @@ pythonenv*
 /clang/utils/analyzer/projects/*/RefScanBuildResults
 # automodapi puts generated documentation files here.
 /lldb/docs/python_api/
-<<<<<<< HEAD
-<<<<<<< HEAD

>From bbbac07b69afa9da1f16d1e045fdbdff4b6685bd Mon Sep 17 00:00:00 2001
From: LouisLu060211 <38174270+LouisLu060211 at users.noreply.github.com>
Date: Thu, 25 Jun 2026 09:42:28 +0800
Subject: [PATCH 4/7] Delete addtional testing

---
 .../Vector/transform-op-vector-to-llvm.mlires | 43 -------------------
 1 file changed, 43 deletions(-)
 delete mode 100644 mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlires

diff --git a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlires b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlires
deleted file mode 100644
index 0ef5c7efaeab9..0000000000000
--- a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlires
+++ /dev/null
@@ -1,43 +0,0 @@
-// RUN: mlir-opt %s -transform-interpreter -verify-diagnostics -allow-unregistered-dialect -split-input-file | FileCheck %s
-
-// CHECK-LABEL: func @lower_to_llvm
-//   CHECK-NOT:   vector.bitcast
-//       CHECK:   llvm.bitcast
-func.func @lower_to_llvm(%input: vector<f32>) -> vector<i32> {
-  %0 = vector.bitcast %input : vector<f32> to vector<i32>
-  return %0 : vector<i32>
-}
-
-module attributes {transform.with_named_sequence} {
-  transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
-    %0 = transform.structured.match ops{["func.func"]} in %arg1 : (!transform.any_op) -> !transform.any_op
-    transform.apply_conversion_patterns to %0 {
-      transform.apply_conversion_patterns.vector.vector_to_llvm
-    } with type_converter {
-      transform.apply_conversion_patterns.memref.memref_to_llvm_type_converter
-    } {legal_dialects = ["func", "llvm"]} : !transform.any_op
-    transform.yield
-  }
-}
-
-// RUN: mlir-opt %s -transform-interpreter -verify-diagnostics
-// Regression test for bug #204100.
-// Assertion idx < size() in SmallVector.h used to happen here.
-// CHECK-LABEL: func @add_dynamic
-module {
-  func.func @add_dynamic(%arg0: memref<?x?xbf16>, %arg1: memref<?x?xbf16>, %arg2: memref<?x?xbf16>) {
-    linalg.add ins(%arg0, %arg1 : memref<?x?xbf16>, memref<?x?xbf16>) outs(%arg2 : memref<?x?xbf16>)
-    return
-  }
-  module attributes {transform.with_named_sequence} {
-    transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {
-      %0 = transform.structured.match ops{["linalg.add"]} in %arg0 : (!transform.any_op) -> !transform.any_op
-      // This combination was crashing (static/dynamic mismatch)
-      transform.structured.vectorize %0 vector_sizes [8, [16], 4] : !transform.any_op
-      // expected-error @above {{Attempted to vectorize, but failed}}
-      transform.yield
-    }
-  }
-}
-
-

>From 0c3b23e88d83a690231f6936f3624270e5aa20e0 Mon Sep 17 00:00:00 2001
From: LouisLu060211 <38174270+LouisLu060211 at users.noreply.github.com>
Date: Thu, 30 Jul 2026 02:44:35 -0700
Subject: [PATCH 5/7] Clean up transform-op-vector-to-llvm.mlir

Removed redundant RUN command for mlir-opt in the test file.
---
 mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
index a74e52dfd4bdb..820ac8f7ba5c4 100644
--- a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
+++ b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
@@ -1,4 +1,5 @@
 // RUN: mlir-opt %s -transform-interpreter -verify-diagnostics -allow-unregistered-dialect -split-input-file | FileCheck %s
+// RUN: mlir-opt %s -transform-interpreter -verify-diagnostics
 
 // CHECK-LABEL: func @lower_to_llvm
 //   CHECK-NOT:   vector.bitcast
@@ -22,7 +23,6 @@ module attributes {transform.with_named_sequence} {
 
 // -----
 
-// RUN: mlir-opt %s -transform-interpreter -verify-diagnostics
 // Regression test for bug #204100.
 // Assertion idx < size() in SmallVector.h used to happen here.
 // CHECK-LABEL: func @add_dynamic
@@ -41,7 +41,3 @@ module {
     }
   }
 }
-
-
-
-

>From 481efab0decd3f0a56660d87501f001a6a9c40ee Mon Sep 17 00:00:00 2001
From: LouisLu0602 <yaolu0602 at gmail.com>
Date: Fri, 21 Aug 2026 17:23:57 +0800
Subject: [PATCH 6/7] Address review: move the check to vectorizeOpPrecondition

---
 .../Linalg/Transforms/Vectorization.cpp       | 20 ++++++++-----------
 .../Vector/transform-op-vector-to-llvm.mlir   |  9 +++------
 2 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
index 95b05be723d7e..20a242022eb3c 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
@@ -2381,18 +2381,6 @@ vectorizeScalableVectorPrecondition(Operation *op,
     return success(isa<linalg::UnPackOp>(op));
   }
 
-  // Ensure that the number of vector sizes and scalable flags provided by the
-  // user does not exceed the number of loops in the target Linalg op.
-  // Accessing iterator types with an out-of-bounds index would cause an
-  // assertion failure (SmallVector::operator[]). This check converts such a
-  // crash into a clean failure, allowing the transform interpreter to report
-  // an error gracefully.
-  // Regression test:
-  // mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
-  if (inputScalableVecDims.size() > linalgOp.getNumLoops() ||
-      inputVectorSizes.size() > linalgOp.getNumLoops())
-    return failure();
-
   // Cond 2: There's been no need for more than 2 scalable dims so far
   if (numOfScalableDims > 2)
     return failure();
@@ -2496,6 +2484,14 @@ LogicalResult mlir::linalg::vectorizeOpPrecondition(
   if (!hasVectorizationImpl(op))
     return failure();
 
+  // More vector sizes than loops means the extra entries have no iteration
+  // space dimension to describe. The scalable precondition below indexes the
+  // iterator types by vector size position, so an oversized list would trip an
+  // out-of-bounds assertion there.
+  if (auto linalgOp = dyn_cast<linalg::LinalgOp>(op))
+    if (inputVectorSizes.size() > linalgOp.getNumLoops())
+      return failure();
+
   if (failed(vectorizeScalableVectorPrecondition(op, inputVectorSizes,
                                                  inputScalableVecDims)))
     return failure();
diff --git a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
index 820ac8f7ba5c4..deaec441b71c5 100644
--- a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
+++ b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
@@ -1,5 +1,4 @@
 // RUN: mlir-opt %s -transform-interpreter -verify-diagnostics -allow-unregistered-dialect -split-input-file | FileCheck %s
-// RUN: mlir-opt %s -transform-interpreter -verify-diagnostics
 
 // CHECK-LABEL: func @lower_to_llvm
 //   CHECK-NOT:   vector.bitcast
@@ -23,20 +22,18 @@ module attributes {transform.with_named_sequence} {
 
 // -----
 
-// Regression test for bug #204100.
-// Assertion idx < size() in SmallVector.h used to happen here.
-// CHECK-LABEL: func @add_dynamic
+// Regression test for bug #204100. More vector sizes than the op has loops
+// used to trip an out-of-bounds assertion in SmallVector.
 module {
   func.func @add_dynamic(%arg0: memref<?x?xbf16>, %arg1: memref<?x?xbf16>, %arg2: memref<?x?xbf16>) {
+    // expected-error @below {{Attempted to vectorize, but failed}}
     linalg.add ins(%arg0, %arg1 : memref<?x?xbf16>, memref<?x?xbf16>) outs(%arg2 : memref<?x?xbf16>)
     return
   }
   module attributes {transform.with_named_sequence} {
     transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {
       %0 = transform.structured.match ops{["linalg.add"]} in %arg0 : (!transform.any_op) -> !transform.any_op
-      // This combination was crashing (static/dynamic mismatch)
       transform.structured.vectorize %0 vector_sizes [8, [16], 4] : !transform.any_op
-      // expected-error @above {{Attempted to vectorize, but failed}}
       transform.yield
     }
   }

>From 1d8cb99db567b118d65dd149e21273c4c8950ca6 Mon Sep 17 00:00:00 2001
From: LouisLu0602 <yaolu0602 at gmail.com>
Date: Mon, 24 Aug 2026 17:36:33 +0800
Subject: [PATCH 7/7] Address review: move the test to unsupported.mlir and
 rename it

---
 .../Linalg/vectorization/unsupported.mlir     | 19 +++++++++++++++++++
 .../Vector/transform-op-vector-to-llvm.mlir   | 19 -------------------
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/mlir/test/Dialect/Linalg/vectorization/unsupported.mlir b/mlir/test/Dialect/Linalg/vectorization/unsupported.mlir
index 59d51e432b743..5d5a06dd4847a 100644
--- a/mlir/test/Dialect/Linalg/vectorization/unsupported.mlir
+++ b/mlir/test/Dialect/Linalg/vectorization/unsupported.mlir
@@ -411,3 +411,22 @@ module attributes {transform.with_named_sequence} {
     transform.yield
   }
 }
+
+// -----
+
+// The number of vector sizes has to match the number of loops of the target
+// op. More sizes than loops used to trip an out-of-bounds assertion.
+
+func.func @invalid_number_of_vec_sizes(%arg0: memref<?x?xbf16>, %arg1: memref<?x?xbf16>, %arg2: memref<?x?xbf16>) {
+  // expected-error @+1 {{Attempted to vectorize, but failed}}
+  linalg.add ins(%arg0, %arg1 : memref<?x?xbf16>, memref<?x?xbf16>) outs(%arg2 : memref<?x?xbf16>)
+  return
+}
+
+module attributes {transform.with_named_sequence} {
+  transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
+    %0 = transform.structured.match ops{["linalg.add"]} in %arg1 : (!transform.any_op) -> !transform.any_op
+    transform.structured.vectorize %0 vector_sizes [8, [16], 4] : !transform.any_op
+    transform.yield
+  }
+}
diff --git a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
index deaec441b71c5..271cdf0e059f4 100644
--- a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
+++ b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
@@ -19,22 +19,3 @@ module attributes {transform.with_named_sequence} {
     transform.yield
   }
 }
-
-// -----
-
-// Regression test for bug #204100. More vector sizes than the op has loops
-// used to trip an out-of-bounds assertion in SmallVector.
-module {
-  func.func @add_dynamic(%arg0: memref<?x?xbf16>, %arg1: memref<?x?xbf16>, %arg2: memref<?x?xbf16>) {
-    // expected-error @below {{Attempted to vectorize, but failed}}
-    linalg.add ins(%arg0, %arg1 : memref<?x?xbf16>, memref<?x?xbf16>) outs(%arg2 : memref<?x?xbf16>)
-    return
-  }
-  module attributes {transform.with_named_sequence} {
-    transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {
-      %0 = transform.structured.match ops{["linalg.add"]} in %arg0 : (!transform.any_op) -> !transform.any_op
-      transform.structured.vectorize %0 vector_sizes [8, [16], 4] : !transform.any_op
-      transform.yield
-    }
-  }
-}



More information about the Mlir-commits mailing list