xref: /llvm-project/mlir/test/Dialect/Linalg/test-drop-unit-dims.mlir (revision 67399932c767f0a64c83a500dc6f7806c09d9401)
1// RUN: mlir-opt -test-linalg-drop-unit-dims --split-input-file %s | FileCheck %s
2
3// Drop only the outermost unit dimension (controlled using a control function)
4func.func @drop_outermost_unit_dims(%arg0: tensor<1x1x42xf32>) -> tensor<1x1x42xf32> {
5  %0 = tensor.empty() : tensor<1x1x42xf32>
6  %1 = linalg.generic {
7    indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1, d2)>,
8                     affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
9    iterator_types = ["parallel", "parallel", "parallel"]}
10    ins(%arg0 : tensor<1x1x42xf32>) outs(%0 : tensor<1x1x42xf32>) {
11      ^bb0(%b0: f32, %b1 : f32):
12        %2 = arith.addf %b0, %b1 : f32
13        linalg.yield %2 : f32
14    } -> tensor<1x1x42xf32>
15  return %1 : tensor<1x1x42xf32>
16}
17// CHECK-LABEL: func @drop_outermost_unit_dims
18//  CHECK-SAME:     %[[ARG0:.+]]: tensor<1x1x42xf32>
19//       CHECK:   %[[OUTS:.+]] = tensor.empty()
20//       CHECK:   %[[ARG0_RESHAPE:.+]] = tensor.collapse_shape %[[ARG0]] {{\[}}[0, 1], [2]{{\]}}
21//       CHECK:   %[[OUTS_RESHAPE:.+]] = tensor.collapse_shape %[[OUTS]] {{\[}}[0, 1], [2]{{\]}}
22//       CHECK:   %[[GENERIC:.+]] = linalg.generic
23//  CHECK-SAME:       ins(%[[ARG0_RESHAPE]] :
24//  CHECK-SAME:       outs(%[[OUTS_RESHAPE]] :
25//       CHECK:   %[[EXPAND_SHAPE:.+]] = tensor.expand_shape %[[GENERIC]] {{\[}}[0, 1], [2]{{\]}}
26//       CHECK:   return %[[EXPAND_SHAPE]]
27