[Mlir-commits] [mlir] [mlir][linalg][test] Update `simplify-pack-unpack.mlir`. (PR #209011)

Jerry Shih llvmlistbot at llvm.org
Sun Jul 12 05:58:48 PDT 2026


https://github.com/JerryShih created https://github.com/llvm/llvm-project/pull/209011

1. Add prefix `negative_` for the negative tests.
2. Add more test patterns.

>From ff4aa35fca37fba6f7b94c4202e61c58e3c484fa Mon Sep 17 00:00:00 2001
From: Jerry Shih <bignose1007 at gmail.com>
Date: Sun, 12 Jul 2026 03:51:20 -0700
Subject: [PATCH 1/2] [mlir][linalg][test] Rename the negative tests in
 `simplify-pack-unpack.mlir`.

Add prefix `negative_` for the negative tests.
---
 .../Dialect/Linalg/simplify-pack-unpack.mlir  | 36 +++++++++----------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir b/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
index 6979770154bab..4c1370abac947 100644
--- a/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
+++ b/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
@@ -12,11 +12,11 @@ func.func @single_dim_packing(%arg0: tensor<256xf32>) -> tensor<8x32xf32> {
 
 // -----
 
-// CHECK-LABEL: func.func @single_dim_packing_with_padding(
+// CHECK-LABEL: func.func @negative_single_dim_packing_with_padding(
 // CHECK-SAME:    %[[ARG0:.+]]: tensor<255xf32>)
 // CHECK-NOT:     tensor.expand_shape
 // CHECK:         linalg.pack
-func.func @single_dim_packing_with_padding(%arg0: tensor<255xf32>) -> tensor<8x32xf32> {
+func.func @negative_single_dim_packing_with_padding(%arg0: tensor<255xf32>) -> tensor<8x32xf32> {
   %empty = tensor.empty() : tensor<8x32xf32>
   %cst = arith.constant 0.000000e+00 : f32
   %0 = linalg.pack %arg0 padding_value(%cst : f32) inner_dims_pos = [0] inner_tiles = [32] into %empty : tensor<255xf32> -> tensor<8x32xf32>
@@ -61,10 +61,10 @@ func.func @single_last_inner_dim_packing_with_identity_outer_dims_perm(%arg0: te
 
 // -----
 
-// CHECK-LABEL: func.func @packing_with_outer_dims_perm(
+// CHECK-LABEL: func.func @negative_packing_with_outer_dims_perm(
 // CHECK-NOT:     tensor.expand_shape
 // CHECK:         linalg.pack
-func.func @packing_with_outer_dims_perm(%arg0: tensor<5x256xf32>) -> tensor<8x5x32xf32> {
+func.func @negative_packing_with_outer_dims_perm(%arg0: tensor<5x256xf32>) -> tensor<8x5x32xf32> {
   %empty = tensor.empty() : tensor<8x5x32xf32>
   %0 = linalg.pack %arg0 outer_dims_perm = [1, 0] inner_dims_pos = [1] inner_tiles = [32] into %empty : tensor<5x256xf32> -> tensor<8x5x32xf32>
   return %0 : tensor<8x5x32xf32>
@@ -72,10 +72,10 @@ func.func @packing_with_outer_dims_perm(%arg0: tensor<5x256xf32>) -> tensor<8x5x
 
 // -----
 
-// CHECK-LABEL: func.func @single_first_inner_dim_packing(
+// CHECK-LABEL: func.func @negative_single_first_inner_dim_packing(
 // CHECK-NOT:     tensor.expand_shape
 // CHECK:         linalg.pack
-func.func @single_first_inner_dim_packing(%arg0: tensor<256x5xf32>) -> tensor<8x5x32xf32> {
+func.func @negative_single_first_inner_dim_packing(%arg0: tensor<256x5xf32>) -> tensor<8x5x32xf32> {
   %empty = tensor.empty() : tensor<8x5x32xf32>
   %0 = linalg.pack %arg0 inner_dims_pos = [0] inner_tiles = [32] into %empty : tensor<256x5xf32> -> tensor<8x5x32xf32>
   return %0 : tensor<8x5x32xf32>
@@ -122,10 +122,10 @@ func.func @pack_32x1_to_16x1x2x1(%arg0 : tensor<32x1xf32>) -> tensor<1x16x2x1xf3
 
 // -----
 
-// CHECK-LABEL: func.func @pack_32x1_to_16x1x1x2
+// CHECK-LABEL: func.func @negative_pack_32x1_to_16x1x1x2
 // CHECK-NOT:     tensor.expand_shape
 // CHECK:         linalg.pack
-func.func @pack_32x1_to_16x1x1x2(%arg0 : tensor<32x1xf32>) -> tensor<16x1x1x2xf32> {
+func.func @negative_pack_32x1_to_16x1x1x2(%arg0 : tensor<32x1xf32>) -> tensor<16x1x1x2xf32> {
   %empty = tensor.empty() : tensor<16x1x1x2xf32>
   %pack = linalg.pack %arg0 inner_dims_pos = [1, 0] inner_tiles = [1, 2] into %empty
     : tensor<32x1xf32> -> tensor<16x1x1x2xf32>
@@ -146,10 +146,10 @@ func.func @unpack_1d_to_collapse(%arg0: tensor<8x32xf32>) -> tensor<256xf32> {
 
 // -----
 
-// CHECK-LABEL: func.func @unpack_to_partial_slice
+// CHECK-LABEL: func.func @negative_unpack_to_partial_slice
 // CHECK-NOT:     tensor.collapse
 // CHECK:         linalg.unpack
-func.func @unpack_to_partial_slice(%arg0: tensor<8x32xf32>) -> tensor<255xf32> {
+func.func @negative_unpack_to_partial_slice(%arg0: tensor<8x32xf32>) -> tensor<255xf32> {
   %empty = tensor.empty() : tensor<255xf32>
   %0 = linalg.unpack %arg0 inner_dims_pos = [0] inner_tiles = [32] into %empty : tensor<8x32xf32> -> tensor<255xf32>
   return %0 : tensor<255xf32>
@@ -157,10 +157,10 @@ func.func @unpack_to_partial_slice(%arg0: tensor<8x32xf32>) -> tensor<255xf32> {
 
 // -----
 
-// CHECK-LABEL: func.func @unpack_dynamic
+// CHECK-LABEL: func.func @negative_unpack_dynamic
 // CHECK:     tensor.collapse
 // CHECK-NOT:         linalg.unpack
-func.func @unpack_dynamic(%arg0: tensor<?x32xf32>) -> tensor<?xf32> {
+func.func @negative_unpack_dynamic(%arg0: tensor<?x32xf32>) -> tensor<?xf32> {
   %c32 = arith.constant 32 : index
   %c0 = arith.constant 0 : index
   %d0 = tensor.dim %arg0, %c0 : tensor<?x32xf32>
@@ -196,10 +196,10 @@ func.func @single_last_inner_dim_unpacking_with_identity_outer_dims_perm(%arg0:
 
 // -----
 
-// CHECK-LABEL: func.func @unpacking_with_outer_dims_perm(
+// CHECK-LABEL: func.func @negative_unpacking_with_outer_dims_perm(
 // CHECK-NOT:     tensor.collpase_shape
 // CHECK:         linalg.unpack
-func.func @unpacking_with_outer_dims_perm(%arg0: tensor<8x5x32xf32>) -> tensor<5x256xf32> {
+func.func @negative_unpacking_with_outer_dims_perm(%arg0: tensor<8x5x32xf32>) -> tensor<5x256xf32> {
   %empty = tensor.empty() : tensor<5x256xf32>
   %0 = linalg.unpack %arg0 outer_dims_perm = [1, 0] inner_dims_pos = [1] inner_tiles = [32] into %empty : tensor<8x5x32xf32> -> tensor<5x256xf32>
   return %0 : tensor<5x256xf32>
@@ -207,10 +207,10 @@ func.func @unpacking_with_outer_dims_perm(%arg0: tensor<8x5x32xf32>) -> tensor<5
 
 // -----
 
-// CHECK-LABEL: func.func @single_first_inner_dim_unpacking(
+// CHECK-LABEL: func.func @negative_single_first_inner_dim_unpacking(
 // CHECK-NOT:     tensor.collapse_shape
 // CHECK:         linalg.unpack
-func.func @single_first_inner_dim_unpacking(%arg0: tensor<8x5x32xf32>) -> tensor<256x5xf32> {
+func.func @negative_single_first_inner_dim_unpacking(%arg0: tensor<8x5x32xf32>) -> tensor<256x5xf32> {
   %empty = tensor.empty() : tensor<256x5xf32>
   %0 = linalg.unpack %arg0 inner_dims_pos = [0] inner_tiles = [32] into %empty : tensor<8x5x32xf32> -> tensor<256x5xf32>
   return %0 : tensor<256x5xf32>
@@ -257,10 +257,10 @@ func.func @unpack_16x1x2x1_to_32x1(%arg0 : tensor<1x16x2x1xf32>) -> tensor<32x1x
 
 // -----
 
-// CHECK-LABEL: func.func @unpack_16x1x1x2_to_32x1
+// CHECK-LABEL: func.func @negative_unpack_16x1x1x2_to_32x1
 // CHECK-NOT:     tensor.collapse_shape
 // CHECK:         linalg.unpack
-func.func @unpack_16x1x1x2_to_32x1(%arg0 : tensor<16x1x1x2xf32>) -> tensor<32x1xf32> {
+func.func @negative_unpack_16x1x1x2_to_32x1(%arg0 : tensor<16x1x1x2xf32>) -> tensor<32x1xf32> {
   %empty = tensor.empty() : tensor<32x1xf32>
   %unpack = linalg.unpack %arg0 inner_dims_pos = [1, 0] inner_tiles = [1, 2] into %empty
     : tensor<16x1x1x2xf32> -> tensor<32x1xf32>

>From 4c79cf515c8213c6bd3a763dabafc5dd999fa3b2 Mon Sep 17 00:00:00 2001
From: Jerry Shih <bignose1007 at gmail.com>
Date: Sun, 12 Jul 2026 03:43:41 -0700
Subject: [PATCH 2/2] [mlir][linalg][test] Add more test patterns in
 `simplify-pack-unpack.mlir`.

---
 .../Dialect/Linalg/simplify-pack-unpack.mlir  | 103 ++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir b/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
index 4c1370abac947..c8a0416c4c3c3 100644
--- a/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
+++ b/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
@@ -394,3 +394,106 @@ func.func @unpad_like_unpack_with_transpose(%arg0: tensor<32x1x16x64xf32>) -> te
   %0 = linalg.unpack %arg0 inner_dims_pos = [1] inner_tiles = [64] into %empty : tensor<32x1x16x64xf32> -> tensor<32x64x16xf32>
   return %0 : tensor<32x64x16xf32>
 }
+
+// -----
+
+// The non-packed outer dims are not unit-size and permuted.
+// CHECK-LABEL: func.func @negative_pack_with_non_unit_outer_tile_dims_perm(
+// CHECK-SAME:    %[[ARG0:.+]]: tensor<3x3x32x64xf32>)
+// CHECK-NOT:     tensor.expand_shape
+// CHECK:         linalg.pack
+func.func @negative_pack_with_non_unit_outer_tile_dims_perm(%arg0: tensor<3x3x32x64xf32>) -> tensor<3x3x1x1x32x64xf32> {
+  %empty = tensor.empty() : tensor<3x3x1x1x32x64xf32>
+  %0 = linalg.pack %arg0 outer_dims_perm = [1, 0, 2, 3] inner_dims_pos = [2, 3] inner_tiles = [32, 64] into %empty : tensor<3x3x32x64xf32> -> tensor<3x3x1x1x32x64xf32>
+  return %0 : tensor<3x3x1x1x32x64xf32>
+
+}
+
+// -----
+
+// CHECK-LABEL: func.func @negative_pack_with_non_unit_packed_dims(
+// CHECK-SAME:    %[[ARG0:.+]]: tensor<4x4xf32>)
+// CHECK-NOT:     tensor.expand_shape
+// CHECK:         linalg.pack
+func.func @negative_pack_with_non_unit_packed_dims(%arg0: tensor<4x4xf32>) -> tensor<2x2x2x2xf32> {
+  %empty = tensor.empty() : tensor<2x2x2x2xf32>
+  %0 = linalg.pack %arg0 inner_dims_pos = [0, 1] inner_tiles = [2, 2] into %empty : tensor<4x4xf32> -> tensor<2x2x2x2xf32>
+  return %0 : tensor<2x2x2x2xf32>
+}
+
+// -----
+
+// The non-unit inner dims are permuted.
+// CHECK-LABEL: func.func @negative_pack_with_non_unit_inner_tile_dims_perm(
+// CHECK-SAME:    %[[ARG0:.+]]: tensor<32x32xf32>)
+// CHECK-NOT:     tensor.expand_shape
+// CHECK:         linalg.pack
+func.func @negative_pack_with_non_unit_inner_tile_dims_perm(%arg0: tensor<32x32xf32>) -> tensor<1x1x32x32xf32> {
+  %empty = tensor.empty() : tensor<1x1x32x32xf32>
+  %0 = linalg.pack %arg0 outer_dims_perm = [1, 0] inner_dims_pos = [1, 0] inner_tiles = [32, 32] into %empty : tensor<32x32xf32> -> tensor<1x1x32x32xf32>
+  return %0 : tensor<1x1x32x32xf32>
+}
+
+// -----
+
+// CHECK-LABEL: func.func @negative_unpack_with_non_unit_outer_tile_dims_perm(
+// CHECK-SAME:    %[[ARG0:.+]]: tensor<3x3x1x1x32x64xf32>)
+// CHECK-NOT:     tensor.collapse_shape
+// CHECK:         linalg.unpack
+func.func @negative_unpack_with_non_unit_outer_tile_dims_perm(%arg0: tensor<3x3x1x1x32x64xf32>) -> tensor<3x3x32x64xf32> {
+  %empty = tensor.empty() : tensor<3x3x32x64xf32>
+  %0 = linalg.unpack %arg0 outer_dims_perm = [1, 0, 2, 3] inner_dims_pos = [2, 3] inner_tiles = [32, 64] into %empty : tensor<3x3x1x1x32x64xf32> -> tensor<3x3x32x64xf32>
+  return %0 : tensor<3x3x32x64xf32>
+}
+
+// -----
+
+// CHECK-LABEL: func.func @negative_unpack_with_non_unit_packed_dims(
+// CHECK-SAME:    %[[ARG0:.+]]: tensor<2x2x2x2xf32>)
+// CHECK-NOT:     tensor.collapse_shape
+// CHECK:         linalg.unpack
+func.func @negative_unpack_with_non_unit_packed_dims(%arg0: tensor<2x2x2x2xf32>) -> tensor<4x4xf32> {
+  %empty = tensor.empty() : tensor<4x4xf32>
+  %0 = linalg.unpack %arg0 inner_dims_pos = [0, 1] inner_tiles = [2, 2] into %empty : tensor<2x2x2x2xf32> -> tensor<4x4xf32>
+  return %0 : tensor<4x4xf32>
+}
+
+// -----
+
+// CHECK-LABEL: func.func @negative_unpack_with_non_unit_inner_tile_dims_perm(
+// CHECK-SAME:    %[[ARG0:.+]]: tensor<1x1x32x32xf32>)
+// CHECK-NOT:     tensor.collapse_shape
+// CHECK:         linalg.unpack
+func.func @negative_unpack_with_non_unit_inner_tile_dims_perm(%arg0: tensor<1x1x32x32xf32>) -> tensor<32x32xf32> {
+  %empty = tensor.empty() : tensor<32x32xf32>
+  %0 = linalg.unpack %arg0 outer_dims_perm = [1, 0] inner_dims_pos = [1, 0] inner_tiles = [32, 32] into %empty : tensor<1x1x32x32xf32> -> tensor<32x32xf32>
+  return %0 : tensor<32x32xf32>
+}
+
+// -----
+
+// Dynamic shape is not supported.
+// CHECK-LABEL: func.func @negative_unpack_dynamic_input_shape(
+// CHECK-SAME:    %[[ARG0:.+]]: tensor<1x63x1x16xf32>)
+// CHECK-NOT:     tensor.collapse_shape
+// CHECK:         linalg.unpack
+func.func @negative_unpack_dynamic_input_shape(%arg0: tensor<1x63x1x16xf32>) -> tensor<1x1000xf32> {
+  %dynamic_arg0 = tensor.cast %arg0 : tensor<1x63x1x16xf32> to tensor<1x?x1x16xf32>
+  %empty = tensor.empty() : tensor<1x1000xf32>
+  %unpack = linalg.unpack %dynamic_arg0 outer_dims_perm = [0, 1] inner_dims_pos = [0, 1] inner_tiles = [1, 16] into %empty : tensor<1x?x1x16xf32> -> tensor<1x1000xf32>
+  return %unpack : tensor<1x1000xf32>
+}
+
+// -----
+
+// CHECK-LABEL: func.func @negative_unpack_dynamic_output_shape(
+// CHECK-SAME:    %[[ARG0:.+]]: tensor<1x63x1x16xf32>)
+// CHECK-NOT:     tensor.collapse_shape
+// CHECK:         linalg.unpack
+func.func @negative_unpack_dynamic_output_shape(%arg0: tensor<1x63x1x16xf32>) -> tensor<1x1000xf32> {
+  %empty = tensor.empty() : tensor<1x1000xf32>
+  %dynamic_empty = tensor.cast %empty : tensor<1x1000xf32> to tensor<1x?xf32>
+  %unpack = linalg.unpack %arg0 outer_dims_perm = [0, 1] inner_dims_pos = [0, 1] inner_tiles = [1, 16] into %dynamic_empty : tensor<1x63x1x16xf32> -> tensor<1x?xf32>
+  %result = tensor.cast %unpack : tensor<1x?xf32> to tensor<1x1000xf32>
+  return %result : tensor<1x1000xf32>
+}



More information about the Mlir-commits mailing list