@@ -1076,6 +1076,44 @@ func.func @drop_known_unit_constant_low_high(%arg0: tensor<1x383x128xf32>) -> te
1076
1076
1077
1077
// -----
1078
1078
1079
+ func.func @drop_unit_dim_mixed_static_dynamic (%arg0: tensor <1 x?xf32 >) -> tensor <1 x16 xf32 > {
1080
+ %c0 = arith.constant 0 : index
1081
+ %c1 = arith.constant 1 : index
1082
+ %cst = arith.constant 0.000000e+00 : f32
1083
+ %padded = tensor.pad %arg0 low [%c0 , %c1 ] high [%c0 , %c0 ] {
1084
+ ^bb0 (%arg1: index , %arg2: index ):
1085
+ tensor.yield %cst : f32
1086
+ } : tensor <1 x?xf32 > to tensor <1 x16 xf32 >
1087
+ return %padded : tensor <1 x16 xf32 >
1088
+ }
1089
+ // CHECK-LABEL: func @drop_unit_dim_mixed_static_dynamic
1090
+ // CHECK: %[[CST:.*]] = arith.constant 0.000000e+00 : f32
1091
+ // CHECK: %[[COLLAPSE:.+]] = tensor.collapse_shape %[[ARGS:.*]] : tensor<1x?xf32> into tensor<?xf32>
1092
+ // CHECK: %[[PADDED:.*]] = tensor.pad %[[COLLAPSE]] low[1] high[0] {
1093
+ // CHECK: ^bb0(%[[IDX:.*]]: index):
1094
+ // CHECK: tensor.yield %[[CST]] : f32
1095
+ // CHECK: } : tensor<?xf32> to tensor<16xf32>
1096
+ // CHECK: %[[EXPANDED:.*]] = tensor.expand_shape %[[PADDED]] {{\[\[}}0, 1]] output_shape [1, 16] : tensor<16xf32> into tensor<1x16xf32>
1097
+ // CHECK: return %[[EXPANDED]] : tensor<1x16xf32>
1098
+
1099
+ // -----
1100
+
1101
+ #map = affine_map <(d0 , d1 , d2 , d3 , d4 , d5 , d6 ) -> (d0 , d1 + d4 , d2 + d5 , d6 )>
1102
+ #map1 = affine_map <(d0 , d1 , d2 , d3 , d4 , d5 , d6 ) -> (d4 , d5 , d6 , d3 )>
1103
+ #map2 = affine_map <(d0 , d1 , d2 , d3 , d4 , d5 , d6 ) -> (d0 , d1 , d2 , d3 )>
1104
+ module {
1105
+ func.func @drop_unit_dim_corresponding_to_dynamic_dim (%arg0: tensor <1 x?x?x1 xf32 >, %arg1: index ) -> tensor <?x1 x61 x1 xf32 > {
1106
+ %cst = arith.constant dense <1.000000e+00 > : tensor <1 x1 x1 x1 xf32 >
1107
+ %0 = tensor.empty (%arg1 ) : tensor <?x1 x61 x1 xf32 >
1108
+ %1 = linalg.generic {index ing_maps = [#map , #map1 , #map2 ], iterator_types = [" parallel" , " parallel" , " parallel" , " parallel" , " reduction" , " reduction" , " reduction" ]} ins (%arg0 , %cst : tensor <1 x?x?x1 xf32 >, tensor <1 x1 x1 x1 xf32 >) outs (%0 : tensor <?x1 x61 x1 xf32 >) {
1109
+ ^bb0 (%in: f32 , %in_0: f32 , %out: f32 ):
1110
+ %2 = arith.mulf %in , %in_0 : f32
1111
+ %3 = arith.addf %out , %2 : f32
1112
+ linalg.yield %3 : f32
1113
+ } -> tensor <?x1 x61 x1 xf32 >
1114
+ return %1 : tensor <?x1 x61 x1 xf32 >
1115
+ }
1116
+ }
1079
1117
// CHECK: #[[$MAP1:.+]] = affine_map<(d0) -> (0, d0)>
1080
1118
// CHECK: #[[$MAP2:.+]] = affine_map<(d0) -> ()>
1081
1119
@@ -1097,23 +1135,6 @@ func.func @drop_known_unit_constant_low_high(%arg0: tensor<1x383x128xf32>) -> te
1097
1135
// CHECK: return %[[VAL_14]] : tensor<?x1x61x1xf32>
1098
1136
// CHECK: }
1099
1137
1100
- #map = affine_map <(d0 , d1 , d2 , d3 , d4 , d5 , d6 ) -> (d0 , d1 + d4 , d2 + d5 , d6 )>
1101
- #map1 = affine_map <(d0 , d1 , d2 , d3 , d4 , d5 , d6 ) -> (d4 , d5 , d6 , d3 )>
1102
- #map2 = affine_map <(d0 , d1 , d2 , d3 , d4 , d5 , d6 ) -> (d0 , d1 , d2 , d3 )>
1103
- module {
1104
- func.func @drop_unit_dim_corresponding_to_dynamic_dim (%arg0: tensor <1 x?x?x1 xf32 >, %arg1: index ) -> tensor <?x1 x61 x1 xf32 > {
1105
- %cst = arith.constant dense <1.000000e+00 > : tensor <1 x1 x1 x1 xf32 >
1106
- %0 = tensor.empty (%arg1 ) : tensor <?x1 x61 x1 xf32 >
1107
- %1 = linalg.generic {index ing_maps = [#map , #map1 , #map2 ], iterator_types = [" parallel" , " parallel" , " parallel" , " parallel" , " reduction" , " reduction" , " reduction" ]} ins (%arg0 , %cst : tensor <1 x?x?x1 xf32 >, tensor <1 x1 x1 x1 xf32 >) outs (%0 : tensor <?x1 x61 x1 xf32 >) {
1108
- ^bb0 (%in: f32 , %in_0: f32 , %out: f32 ):
1109
- %2 = arith.mulf %in , %in_0 : f32
1110
- %3 = arith.addf %out , %2 : f32
1111
- linalg.yield %3 : f32
1112
- } -> tensor <?x1 x61 x1 xf32 >
1113
- return %1 : tensor <?x1 x61 x1 xf32 >
1114
- }
1115
- }
1116
-
1117
1138
// -----
1118
1139
1119
1140
func.func @no_fold_empty_tensor_dim_out_of_bounds (%arg0: tensor <1 x?x10 xf32 >) -> tensor <1 x?xf32 > {
0 commit comments