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

Jerry Shih llvmlistbot at llvm.org
Fri Jul 17 10:01:07 PDT 2026


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

>From 93774b2a280c0f9078a3abf6bfb9d97528e14fb2 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/4] 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 f4f3cb233d45e..6f6da9c41a974 100644
--- a/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
+++ b/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
@@ -16,11 +16,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>
@@ -69,10 +69,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>
@@ -80,10 +80,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>
@@ -134,10 +134,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>
@@ -162,10 +162,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>
@@ -173,10 +173,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>
@@ -216,10 +216,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>
@@ -227,10 +227,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>
@@ -277,10 +277,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 0603e88408c312005f24aa926b6e3da705888599 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/4] 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 6f6da9c41a974..875e153f5af56 100644
--- a/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
+++ b/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
@@ -428,3 +428,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>
+}

>From 3c0c3b28c75d8f6b324b7d652b571890a999e1cf Mon Sep 17 00:00:00 2001
From: Jerry Shih <bignose1007 at gmail.com>
Date: Fri, 17 Jul 2026 07:50:33 -0700
Subject: [PATCH 3/4] Address review comments.

---
 .../Dialect/Linalg/simplify-pack-unpack.mlir     | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir b/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
index 875e153f5af56..c80de4734657a 100644
--- a/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
+++ b/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
@@ -80,10 +80,11 @@ func.func @negative_packing_with_outer_dims_perm(%arg0: tensor<5x256xf32>) -> te
 
 // -----
 
-// CHECK-LABEL: func.func @negative_single_first_inner_dim_packing(
+// This sort of packing requires transposition.
+// CHECK-LABEL: func.func @negative_packing_non_trailing_dim(
 // CHECK-NOT:     tensor.expand_shape
 // CHECK:         linalg.pack
-func.func @negative_single_first_inner_dim_packing(%arg0: tensor<256x5xf32>) -> tensor<8x5x32xf32> {
+func.func @negative_packing_non_trailing_dim(%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>
@@ -134,6 +135,7 @@ func.func @pack_32x1_to_16x1x2x1(%arg0 : tensor<32x1xf32>) -> tensor<1x16x2x1xf3
 
 // -----
 
+// Impossible to compute a re-association map.
 // CHECK-LABEL: func.func @negative_pack_32x1_to_16x1x1x2
 // CHECK-NOT:     tensor.expand_shape
 // CHECK:         linalg.pack
@@ -227,10 +229,10 @@ func.func @negative_unpacking_with_outer_dims_perm(%arg0: tensor<8x5x32xf32>) ->
 
 // -----
 
-// CHECK-LABEL: func.func @negative_single_first_inner_dim_unpacking(
+// CHECK-LABEL: func.func @negative_packed_non_trailing_dim(
 // CHECK-NOT:     tensor.collapse_shape
 // CHECK:         linalg.unpack
-func.func @negative_single_first_inner_dim_unpacking(%arg0: tensor<8x5x32xf32>) -> tensor<256x5xf32> {
+func.func @negative_packed_non_trailing_dim(%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>
@@ -432,11 +434,11 @@ func.func @unpad_like_unpack_with_transpose(%arg0: tensor<32x1x16x64xf32>) -> te
 // -----
 
 // 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-LABEL: func.func @negative_pack_with_non_unit_non_packed_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> {
+func.func @negative_pack_with_non_unit_non_packed_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>
@@ -464,7 +466,7 @@ func.func @negative_pack_with_non_unit_packed_dims(%arg0: tensor<4x4xf32>) -> te
 // 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>
+  %0 = linalg.pack %arg0 outer_dims_perm = [0, 1] inner_dims_pos = [1, 0] inner_tiles = [32, 32] into %empty : tensor<32x32xf32> -> tensor<1x1x32x32xf32>
   return %0 : tensor<1x1x32x32xf32>
 }
 

>From b6da105d40b09a0ee127e8b3da4d0ac91ef25a25 Mon Sep 17 00:00:00 2001
From: Jerry Shih <bignose1007 at gmail.com>
Date: Fri, 17 Jul 2026 09:51:26 -0700
Subject: [PATCH 4/4] Reorder test case.

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

diff --git a/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir b/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
index c80de4734657a..39d1398a131c3 100644
--- a/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
+++ b/mlir/test/Dialect/Linalg/simplify-pack-unpack.mlir
@@ -92,6 +92,18 @@ func.func @negative_packing_non_trailing_dim(%arg0: tensor<256x5xf32>) -> tensor
 
 // -----
 
+// 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>
+}
+
+// -----
+
 //===========================================================================//
 // Packing: Multi-dim unpacked source
 //===========================================================================//
@@ -148,6 +160,20 @@ func.func @negative_pack_32x1_to_16x1x1x2(%arg0 : tensor<32x1xf32>) -> tensor<16
 
 // -----
 
+// The non-packed outer dims are not unit-size and permuted.
+// CHECK-LABEL: func.func @negative_pack_with_non_unit_non_packed_outer_tile_dims_perm(
+// CHECK-SAME:    %[[ARG0:.+]]: tensor<3x3x32x64xf32>)
+// CHECK-NOT:     tensor.expand_shape
+// CHECK:         linalg.pack
+func.func @negative_pack_with_non_unit_non_packed_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>
+
+}
+
+// -----
+
 //===========================================================================//
 // Un-Packing: 1D unpacked dest
 //===========================================================================//
@@ -291,6 +317,46 @@ func.func @negative_unpack_16x1x1x2_to_32x1(%arg0 : tensor<16x1x1x2xf32>) -> ten
 
 // -----
 
+// 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>
+}
+
+// -----
+
+// 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>
+}
+
+// -----
+
 //===========================================================================//
 // Packing: Pad-like pack
 //
@@ -362,6 +428,19 @@ func.func @pad_like_pack_with_transpose(%arg0: tensor<32x64x16xf32>) -> tensor<3
 
 // -----
 
+// 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 = [0, 1] inner_dims_pos = [1, 0] inner_tiles = [32, 32] into %empty : tensor<32x32xf32> -> tensor<1x1x32x32xf32>
+  return %0 : tensor<1x1x32x32xf32>
+}
+
+// -----
+
 //===========================================================================//
 // Un-Packing: Un-Pad-like unpack
 //
@@ -433,45 +512,6 @@ func.func @unpad_like_unpack_with_transpose(%arg0: tensor<32x1x16x64xf32>) -> te
 
 // -----
 
-// The non-packed outer dims are not unit-size and permuted.
-// CHECK-LABEL: func.func @negative_pack_with_non_unit_non_packed_outer_tile_dims_perm(
-// CHECK-SAME:    %[[ARG0:.+]]: tensor<3x3x32x64xf32>)
-// CHECK-NOT:     tensor.expand_shape
-// CHECK:         linalg.pack
-func.func @negative_pack_with_non_unit_non_packed_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 = [0, 1] 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
@@ -484,52 +524,12 @@ func.func @negative_unpack_with_non_unit_outer_tile_dims_perm(%arg0: tensor<3x3x
 
 // -----
 
-// 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>
+  %0 = linalg.unpack %arg0 outer_dims_perm = [0, 1] 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