[Mlir-commits] [mlir] [mlir][vector] Add missing dependent dialect to TestVectorUnrollingPatterns (PR #207113)
Longsheng Mou
llvmlistbot at llvm.org
Wed Jul 1 20:45:51 PDT 2026
https://github.com/CoTinker created https://github.com/llvm/llvm-project/pull/207113
Add `vector::VectorDialect` to `getDependentDialects()` for `TestVectorUnrollingPatterns`. Previously, `arith.addf` test passed only because the vector dialect was indirectly loaded via other vector tests in the same `MLIRContext`. With `split-input-file`, each test runs in an isolated context, causing failures due to the missing vector dialect. Fixes #206921.
>From bd1c3b047568364576eb8cc36b5d61726bd4a772 Mon Sep 17 00:00:00 2001
From: Longsheng Mou <longshengmou at gmail.com>
Date: Thu, 2 Jul 2026 11:40:01 +0800
Subject: [PATCH 1/2] [mlir][vector] Add missing dependent dialect to
TestVectorUnrollingPatterns
Add `vector::VectorDialect` to `getDependentDialects()` for
`TestVectorUnrollingPatterns`. Previously, `arith.addf` test passed only because the vector dialect was indirectly loaded via other vector tests in the same `MLIRContext`. With `split-input-file`, each test runs in an isolated context, causing failures due to the missing vector dialect.
---
mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp b/mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
index 043181c16c759..1a4bef664fbe1 100644
--- a/mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
+++ b/mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
@@ -150,6 +150,11 @@ struct TestVectorUnrollingPatterns
return "Test lowering patterns to unroll contract ops in the vector "
"dialect";
}
+
+ void getDependentDialects(DialectRegistry ®istry) const override {
+ registry.insert<vector::VectorDialect>();
+ }
+
TestVectorUnrollingPatterns() = default;
TestVectorUnrollingPatterns(const TestVectorUnrollingPatterns &pass)
: PassWrapper(pass) {}
>From caa23c28c8c3e9a9122e8b501b9eca1925be17b7 Mon Sep 17 00:00:00 2001
From: Longsheng Mou <longshengmou at gmail.com>
Date: Thu, 2 Jul 2026 11:44:27 +0800
Subject: [PATCH 2/2] split file
---
.../Dialect/Vector/vector-unroll-options.mlir | 43 +++++++++++++++++--
1 file changed, 39 insertions(+), 4 deletions(-)
diff --git a/mlir/test/Dialect/Vector/vector-unroll-options.mlir b/mlir/test/Dialect/Vector/vector-unroll-options.mlir
index bb6fc4e38813d..0ec71620c5324 100644
--- a/mlir/test/Dialect/Vector/vector-unroll-options.mlir
+++ b/mlir/test/Dialect/Vector/vector-unroll-options.mlir
@@ -1,6 +1,6 @@
-// RUN: mlir-opt %s -test-vector-unrolling-patterns=unroll-based-on-type | FileCheck %s
-// RUN: mlir-opt %s -test-vector-unrolling-patterns="unroll-based-on-type unroll-order=2,0,1" | FileCheck %s --check-prefix=ORDER
-// RUN: mlir-opt %s -test-vector-unrolling-patterns="unroll-based-on-type unroll-order=0,3,1,2" | FileCheck %s --check-prefix=BATCHED
+// RUN: mlir-opt %s -test-vector-unrolling-patterns=unroll-based-on-type -split-input-file | FileCheck %s
+// RUN: mlir-opt %s -test-vector-unrolling-patterns="unroll-based-on-type unroll-order=2,0,1" -split-input-file | FileCheck %s --check-prefix=ORDER
+// RUN: mlir-opt %s -test-vector-unrolling-patterns="unroll-based-on-type unroll-order=0,3,1,2" -split-input-file | FileCheck %s --check-prefix=BATCHED
func.func @vector_contract_f32(%lhs : vector<8x4xf32>, %rhs : vector<8x4xf32>,
%init : vector<8x8xf32>) -> vector<8x8xf32> {
@@ -150,7 +150,7 @@ func.func @vector_contract_f32(%lhs : vector<8x4xf32>, %rhs : vector<8x4xf32>,
// ORDER: return
-
+// -----
func.func @vector_contract_f16(%lhs : vector<8x8xf16>, %rhs : vector<8x8xf16>,
%init : vector<8x8xf16>) -> vector<8x8xf16> {
@@ -181,6 +181,8 @@ func.func @vector_contract_f16(%lhs : vector<8x8xf16>, %rhs : vector<8x8xf16>,
// CHECK-SAME: vector<4x4xf16>, vector<4x4xf16> into vector<4x4xf16>
// CHECK: return
+// -----
+
func.func @vector_fma(%a: vector<4x4xf32>, %b: vector<4x4xf32>, %c: vector<4x4xf32>) -> vector<4x4xf32> {
%0 = vector.fma %a, %b, %c: vector<4x4xf32>
return %0 : vector<4x4xf32>
@@ -188,6 +190,8 @@ func.func @vector_fma(%a: vector<4x4xf32>, %b: vector<4x4xf32>, %c: vector<4x4xf
// CHECK-LABEL: func @vector_fma
// CHECK-COUNT-4: vector.fma %{{.+}}, %{{.+}}, %{{.+}} : vector<2x2xf32>
+// -----
+
func.func @vector_fma_3d(%a: vector<3x2x2xf32>) -> vector<3x2x2xf32>{
%0 = vector.fma %a, %a, %a : vector<3x2x2xf32>
return %0 : vector<3x2x2xf32>
@@ -221,6 +225,8 @@ func.func @vector_fma_3d(%a: vector<3x2x2xf32>) -> vector<3x2x2xf32>{
// CHECK: %[[I2:.*]] = vector.insert_strided_slice %[[FMA2]], %[[I1]] {offsets = [2, 0, 0], strides = [1, 1]} : vector<2x2xf32> into vector<3x2x2xf32>
// CHECK: return %[[I2]] : vector<3x2x2xf32>
+// -----
+
func.func @vector_multi_reduction(%v : vector<4x6xf32>, %acc: vector<4xf32>) -> vector<4xf32> {
%0 = vector.multi_reduction #vector.kind<add>, %v, %acc [1] : vector<4x6xf32> to vector<4xf32>
return %0 : vector<4xf32>
@@ -245,6 +251,8 @@ func.func @vector_multi_reduction(%v : vector<4x6xf32>, %acc: vector<4xf32>) ->
// CHECK: %[[V2:.*]] = vector.insert_strided_slice %[[R5]], %[[V1]] {offsets = [2], strides = [1]} : vector<2xf32> into vector<4xf32>
// CHECK: return %[[V2]] : vector<4xf32>
+// -----
+
func.func @vector_multi_reduction_scalar(%v: vector<4x2xf32>, %acc: f32) -> f32 {
%0 = vector.multi_reduction #vector.kind<add>, %v, %acc [0, 1] : vector<4x2xf32> to f32
return %0 : f32
@@ -257,6 +265,8 @@ func.func @vector_multi_reduction_scalar(%v: vector<4x2xf32>, %acc: f32) -> f32
// CHECK: %[[R1:.*]] = vector.multi_reduction <add>, %[[S1]], %[[R0]] [0, 1] : vector<2x2xf32> to f32
// CHECK: return %[[R1]] : f32
+// -----
+
func.func @vector_reduction(%v : vector<8xf32>) -> f32 {
%0 = vector.reduction <add>, %v : vector<8xf32> into f32
return %0 : f32
@@ -276,6 +286,8 @@ func.func @vector_reduction(%v : vector<8xf32>) -> f32 {
// CHECK: %[[add3:.*]] = arith.addf %[[add2]], %[[r3]]
// CHECK: return %[[add3]]
+// -----
+
func.func @vector_transpose(%v : vector<2x4x3x8xf32>) -> vector<2x3x8x4xf32> {
%t = vector.transpose %v, [0, 2, 3, 1] : vector<2x4x3x8xf32> to vector<2x3x8x4xf32>
return %t : vector<2x3x8x4xf32>
@@ -337,6 +349,7 @@ func.func @vector_contract_batched(%lhs: vector<8x8x4xf32>, %rhs: vector<8x8x4xf
// BATCHED-NOT: vector.contract
// BATCHED: return
+// -----
func.func @vector_broadcast(%v: vector<4xf32>) -> vector<4x4xf32> {
%0 = vector.broadcast %v : vector<4xf32> to vector<4x4xf32>
@@ -360,6 +373,8 @@ func.func @vector_broadcast(%v: vector<4xf32>) -> vector<4x4xf32> {
// CHECK: [[r3:%.+]] = vector.insert_strided_slice [[b3]], [[r2]] {offsets = [2, 2], strides = [1, 1]} : vector<2x2xf32> into vector<4x4xf32>
// CHECK: return [[r3]] : vector<4x4xf32>
+// -----
+
func.func @vector_broadcast_with_leading_unit_dim(%v: vector<1x4xf32>) -> vector<4x4xf32> {
%0 = vector.broadcast %v : vector<1x4xf32> to vector<4x4xf32>
return %0 : vector<4x4xf32>
@@ -382,6 +397,8 @@ func.func @vector_broadcast_with_leading_unit_dim(%v: vector<1x4xf32>) -> vector
// CHECK: [[r3:%.+]] = vector.insert_strided_slice [[b3]], [[r2]] {offsets = [2, 2], strides = [1, 1]} : vector<2x2xf32> into vector<4x4xf32>
// CHECK: return [[r3]] : vector<4x4xf32>
+// -----
+
func.func @vector_broadcast_with_tailing_unit_dim(%v: vector<4x1xf32>) -> vector<4x4xf32> {
%0 = vector.broadcast %v : vector<4x1xf32> to vector<4x4xf32>
return %0 : vector<4x4xf32>
@@ -404,6 +421,7 @@ func.func @vector_broadcast_with_tailing_unit_dim(%v: vector<4x1xf32>) -> vector
// CHECK: [[r3:%.+]] = vector.insert_strided_slice [[b3]], [[r2]] {offsets = [2, 2], strides = [1, 1]} : vector<2x2xf32> into vector<4x4xf32>
// CHECK: return [[r3]] : vector<4x4xf32>
+// -----
func.func @vector_load_2D(%mem: memref<4x4xf16>) -> vector<4x4xf16> {
%c0 = arith.constant 0 : index
@@ -426,6 +444,7 @@ func.func @vector_load_2D(%mem: memref<4x4xf16>) -> vector<4x4xf16> {
// CHECK: %[[V7:.*]] = vector.insert_strided_slice %[[V6]], %[[V5]] {offsets = [2, 2], strides = [1, 1]} : vector<2x2xf16> into vector<4x4xf16>
// CHECK: return %[[V7]] : vector<4x4xf16>
+// -----
func.func @vector_store_2D(%mem: memref<4x4xf16>, %v: vector<4x4xf16>) {
%c0 = arith.constant 0 : index
@@ -446,6 +465,7 @@ func.func @vector_store_2D(%mem: memref<4x4xf16>, %v: vector<4x4xf16>) {
// CHECK: %[[V3:.*]] = vector.extract_strided_slice %[[ARG1]] {offsets = [2, 2], sizes = [2, 2], strides = [1, 1]} : vector<4x4xf16> to vector<2x2xf16>
// CHECK: vector.store %[[V3]], %[[ARG0]][%[[C2]], %[[C2]]] : memref<4x4xf16>, vector<2x2xf16>
+// -----
func.func @vector_step() -> vector<32xindex> {
%0 = vector.step : vector<32xindex>
@@ -466,6 +486,7 @@ func.func @vector_step() -> vector<32xindex> {
// CHECK: %[[INS3:.*]] = vector.insert_strided_slice %[[ADD3]], %[[INS2]] {offsets = [24], strides = [1]} : vector<8xindex> into vector<32xindex>
// CHECK: return %[[INS3]] : vector<32xindex>
+// -----
func.func @elementwise_3D_to_2D(%v1: vector<2x2x2xf32>, %v2: vector<2x2x2xf32>) -> vector<2x2x2xf32> {
%0 = arith.addf %v1, %v2 : vector<2x2x2xf32>
@@ -488,6 +509,7 @@ func.func @elementwise_3D_to_2D(%v1: vector<2x2x2xf32>, %v2: vector<2x2x2xf32>)
// CHECK: %[[I1:.*]] = vector.insert_strided_slice %[[ADD1]], %[[I0]] {offsets = [1, 0, 0], strides = [1, 1]} : vector<2x2xf32> into vector<2x2x2xf32>
// CHECK: return %[[I1]] : vector<2x2x2xf32>
+// -----
func.func @elementwise_4D_to_2D(%v1: vector<2x2x2x2xf32>, %v2: vector<2x2x2x2xf32>) -> vector<2x2x2x2xf32> {
%0 = arith.addf %v1, %v2 : vector<2x2x2x2xf32>
@@ -499,6 +521,8 @@ func.func @elementwise_4D_to_2D(%v1: vector<2x2x2x2xf32>, %v2: vector<2x2x2x2xf3
// CHECK-NOT: arith.addf
// CHECK: return
+// -----
+
func.func @vector_create_mask(%size1: index, %size2: index) -> vector<16x16xi1> {
%0 = vector.create_mask %size1, %size2 : vector<16x16xi1>
return %0 : vector<16x16xi1>
@@ -539,6 +563,8 @@ func.func @vector_create_mask(%size1: index, %size2: index) -> vector<16x16xi1>
// CHECK: %[[INS11:.*]] = vector.insert_strided_slice %[[MASK11]], %[[INS10]] {offsets = [8, 8], strides = [1, 1]} : vector<8x8xi1> into vector<16x16xi1>
// CHECK: return %[[INS11]] : vector<16x16xi1>
+// -----
+
func.func @vector_create_mask_constant_dim_sizes() -> vector<16x16xi1> {
%cst16 = arith.constant 16 : index
%0 = vector.create_mask %cst16, %cst16 : vector<16x16xi1>
@@ -554,6 +580,8 @@ func.func @vector_create_mask_constant_dim_sizes() -> vector<16x16xi1> {
// CHECK: %[[S3:.*]] = vector.insert_strided_slice %[[CST_0]], %[[S2]] {offsets = [8, 8], strides = [1, 1]} : vector<8x8xi1> into vector<16x16xi1>
// CHECK: return %[[S3]] : vector<16x16xi1>
+// -----
+
func.func @vector_constant_mask() -> vector<16x16xi1> {
%0 = vector.constant_mask [12, 10] : vector<16x16xi1>
return %0 : vector<16x16xi1>
@@ -572,6 +600,8 @@ func.func @vector_constant_mask() -> vector<16x16xi1> {
// CHECK: %[[INS11:.*]] = vector.insert_strided_slice %[[MASK11]], %[[INS10]] {offsets = [8, 8], strides = [1, 1]} : vector<8x8xi1> into vector<16x16xi1>
// CHECK: return %[[INS11]] : vector<16x16xi1>
+// -----
+
func.func @shape_cast_1D(%v: vector<16xf32>) -> vector<2x2x4xf32> {
%0 = vector.shape_cast %v : vector<16xf32> to vector<2x2x4xf32>
return %0 : vector<2x2x4xf32>
@@ -588,6 +618,7 @@ func.func @shape_cast_1D(%v: vector<16xf32>) -> vector<2x2x4xf32> {
// CHECK: %[[I1:.*]] = vector.insert_strided_slice %[[SC1]], %[[I0]] {offsets = [1, 0, 0], strides = [1, 1]} : vector<2x4xf32> into vector<2x2x4xf32>
// CHECK: return %[[I1]] : vector<2x2x4xf32>
+// -----
func.func @shape_cast_2D(%v: vector<8x2xf32>) -> vector<4x4xf32> {
%0 = vector.shape_cast %v : vector<8x2xf32> to vector<4x4xf32>
@@ -605,6 +636,7 @@ func.func @shape_cast_2D(%v: vector<8x2xf32>) -> vector<4x4xf32> {
// CHECK: %[[I1:.*]] = vector.insert_strided_slice %[[SC1]], %[[I0]] {offsets = [2, 0], strides = [1, 1]} : vector<2x4xf32> into vector<4x4xf32>
// CHECK: return %[[I1]] : vector<4x4xf32>
+// -----
// This is a negative test case to ensure that such shape casts are not unrolled
// because the targetShape (2x4) is not contiguous in result vector
@@ -618,6 +650,7 @@ func.func @negative_shape_cast_target_shape_not_contiguous(%v: vector<64xf32>) -
// CHECK: %[[SC:.*]] = vector.shape_cast %[[V]] : vector<64xf32> to vector<8x8xf32>
// CHECK: return %[[SC]] : vector<8x8xf32>
+// -----
// This is negative test case to ensure that such shape casts are not unrolled
// because it cannot determine the extractShape from source vector (8x3)
@@ -632,6 +665,7 @@ func.func @negative_shape_cast_source_shape_not_determinable(%v: vector<8x3xf32>
// CHECK: %[[SC:.*]] = vector.shape_cast %[[V]] : vector<8x3xf32> to vector<6x4xf32>
// CHECK: return %[[SC]] : vector<6x4xf32>
+// -----
// TargetShape is [1x16]
func.func @shape_cast_leading_unit_dim(%v: vector<32xf32>) -> vector<1x32xf32> {
@@ -650,6 +684,7 @@ func.func @shape_cast_leading_unit_dim(%v: vector<32xf32>) -> vector<1x32xf32> {
// CHECK: %[[I1:.*]] = vector.insert_strided_slice %[[SC1]], %[[I0]] {offsets = [0, 16], strides = [1, 1]} : vector<1x16xf32> into vector<1x32xf32>
// CHECK: return %[[I1]] : vector<1x32xf32>
+// -----
// TargetShape is [1x1]
func.func @shape_cast_with_all_unit_target_shape(%v: vector<2xf32>) -> vector<2x1xf32> {
More information about the Mlir-commits
mailing list