@@ -985,6 +985,78 @@ func.func @canonicalize_concat_slice_on_non_concat_axis(%arg0 : tensor<1x12x12xf
985
985
986
986
// -----
987
987
988
+ // CHECK-LABEL: @canonicalize_pad_slice_overlap
989
+ // CHECK-DAG: %[[PAD_CONST:.*]] = "tosa.const"() <{values = dense<0.000000e+00> : tensor<1xf32>}> : () -> tensor<1xf32>
990
+ // CHECK-DAG: %[[ZERO:.*]] = tosa.const_shape {values = dense<0> : tensor<4xindex>} : () -> !tosa.shape<4>
991
+ // CHECK-DAG: %[[PADDING:.*]] = tosa.const_shape {values = dense<[0, 0, 0, 0, 1, 1, 0, 0]> : tensor<8xindex>}
992
+ // CHECK-DAG: %[[SLICE_SIZE:.*]] = tosa.const_shape {values = dense<[-1, 14, 18, 3]> : tensor<4xindex>}
993
+ // CHECK: %[[PADDED:.*]] = tosa.pad %arg0, %[[PADDING]], %[[PAD_CONST]]
994
+ // CHECK: %[[SLICED:.*]] = tosa.slice %[[PADDED]], %[[ZERO]], %[[SLICE_SIZE]]
995
+ func.func @canonicalize_pad_slice_overlap (%arg0: tensor <?x16 x16 x3 xf32 >) -> tensor <?x14 x18 x3 xf32 > {
996
+ %pad_const = " tosa.const" () <{values = dense <0.000000e+00 > : tensor <1 xf32 >}> : () -> tensor <1 xf32 >
997
+ %padding = tosa.const_shape {values = dense <[0 , 0 , 0 , 0 , 2 , 2 , 0 , 0 ]> : tensor <8 xindex >} : () -> !tosa.shape <8 >
998
+ %padded = tosa.pad %arg0 , %padding , %pad_const : (tensor <?x16 x16 x3 xf32 >, !tosa.shape <8 >, tensor <1 xf32 >) -> tensor <?x16 x20 x3 xf32 >
999
+ %start = tosa.const_shape {values = dense <[0 , 0 , 1 , 0 ]> : tensor <4 xindex >} : () -> !tosa.shape <4 >
1000
+ %size = tosa.const_shape {values = dense <[-1 , 14 , 18 , 3 ]> : tensor <4 xindex >} : () -> !tosa.shape <4 >
1001
+ %sliced = tosa.slice %padded , %start , %size : (tensor <?x16 x20 x3 xf32 >, !tosa.shape <4 >, !tosa.shape <4 >) -> tensor <?x14 x18 x3 xf32 >
1002
+ return %sliced : tensor <?x14 x18 x3 xf32 >
1003
+ }
1004
+
1005
+ // -----
1006
+
1007
+ // CHECK-LABEL: @canonicalize_pad_slice_inside
1008
+ // CHECK-DAG: %[[SLICE_START:.*]] = tosa.const_shape {values = dense<[0, 1, 2, 0]> : tensor<4xindex>}
1009
+ // CHECK-DAG: %[[SLICE_SIZE:.*]] = tosa.const_shape {values = dense<[1, 14, 10, 3]> : tensor<4xindex>}
1010
+ // CHECK-NOT: tosa.pad
1011
+ // CHECK: %[[SLICED:.*]] = tosa.slice %arg0, %[[SLICE_START]], %[[SLICE_SIZE]]
1012
+ func.func @canonicalize_pad_slice_inside (%arg0: tensor <1 x16 x16 x3 xf32 >) -> tensor <1 x14 x14 x3 xf32 > {
1013
+ %pad_const = " tosa.const" () <{values = dense <0.000000e+00 > : tensor <1 xf32 >}> : () -> tensor <1 xf32 >
1014
+ %padding = tosa.const_shape {values = dense <[0 , 0 , 0 , 0 , 2 , 2 , 0 , 0 ]> : tensor <8 xindex >} : () -> !tosa.shape <8 >
1015
+ %padded = tosa.pad %arg0 , %padding , %pad_const : (tensor <1 x16 x16 x3 xf32 >, !tosa.shape <8 >, tensor <1 xf32 >) -> tensor <1 x16 x20 x3 xf32 >
1016
+ %start = tosa.const_shape {values = dense <[0 , 1 , 4 , 0 ]> : tensor <4 xindex >} : () -> !tosa.shape <4 >
1017
+ %size = tosa.const_shape {values = dense <[1 , 14 , 10 , 3 ]> : tensor <4 xindex >} : () -> !tosa.shape <4 >
1018
+ %sliced = tosa.slice %padded , %start , %size : (tensor <1 x16 x20 x3 xf32 >, !tosa.shape <4 >, !tosa.shape <4 >) -> tensor <1 x14 x14 x3 xf32 >
1019
+ return %sliced : tensor <1 x14 x14 x3 xf32 >
1020
+ }
1021
+
1022
+ // -----
1023
+
1024
+ // CHECK-LABEL: func @canonicalize_pad_slice_exact
1025
+ // CHECK-DAG: %[[PAD_CONST:.*]] = "tosa.const"() <{values = dense<0.000000e+00> : tensor<1xf32>}> : () -> tensor<1xf32>
1026
+ // CHECK-DAG: %[[ZERO:.*]] = tosa.const_shape {values = dense<0> : tensor<4xindex>} : () -> !tosa.shape<4>
1027
+ // CHECK-DAG: %[[PADDING:.*]] = tosa.const_shape {values = dense<[0, 0, 0, 0, 2, 2, 0, 0]> : tensor<8xindex>}
1028
+ // CHECK-DAG: %[[SLICE_SIZE:.*]] = tosa.const_shape {values = dense<[1, 16, 20, 2]> : tensor<4xindex>}
1029
+ // CHECK: %[[PADDED:.*]] = tosa.pad %arg0, %[[PADDING]], %[[PAD_CONST]]
1030
+ // CHECK: %[[SLICED:.*]] = tosa.slice %[[PADDED]], %[[ZERO]], %[[SLICE_SIZE]]
1031
+ func.func @canonicalize_pad_slice_exact (%arg0: tensor <1 x16 x16 x3 xf32 >) -> tensor <1 x16 x20 x2 xf32 > {
1032
+ %pad_const = " tosa.const" () <{values = dense <0.000000e+00 > : tensor <1 xf32 >}> : () -> tensor <1 xf32 >
1033
+ %padding = tosa.const_shape {values = dense <[0 , 0 , 0 , 0 , 2 , 2 , 0 , 0 ]> : tensor <8 xindex >} : () -> !tosa.shape <8 >
1034
+ %padded = tosa.pad %arg0 , %padding , %pad_const : (tensor <1 x16 x16 x3 xf32 >, !tosa.shape <8 >, tensor <1 xf32 >) -> tensor <1 x16 x20 x3 xf32 >
1035
+ %start = tosa.const_shape {values = dense <[0 , 0 , 0 , 0 ]> : tensor <4 xindex >} : () -> !tosa.shape <4 >
1036
+ %size = tosa.const_shape {values = dense <[1 , 16 , 20 , 2 ]> : tensor <4 xindex >} : () -> !tosa.shape <4 >
1037
+ %sliced = tosa.slice %padded , %start , %size : (tensor <1 x16 x20 x3 xf32 >, !tosa.shape <4 >, !tosa.shape <4 >) -> tensor <1 x16 x20 x2 xf32 >
1038
+ return %sliced : tensor <1 x16 x20 x2 xf32 >
1039
+ }
1040
+
1041
+ // -----
1042
+
1043
+ // CHECK-LABEL: func @canonicalize_pad_slice_dynamic_noupdate
1044
+ // CHECK-DAG: tosa.const_shape {values = dense<[0, 0, 0, 0, 2, 2, 0, 0]> : tensor<8xindex>}
1045
+ // CHECK-DAG: tosa.const_shape {values = dense<[1, 16, 15, 2]> : tensor<4xindex>}
1046
+ // CHECK: tosa.pad
1047
+ // CHECK: tosa.slice
1048
+ func.func @canonicalize_pad_slice_dynamic_noupdate (%arg0: tensor <1 x16 x?x3 xf32 >) -> tensor <1 x16 x?x2 xf32 > {
1049
+ %pad_const = " tosa.const" () <{values = dense <0.000000e+00 > : tensor <1 xf32 >}> : () -> tensor <1 xf32 >
1050
+ %padding = tosa.const_shape {values = dense <[0 , 0 , 0 , 0 , 2 , 2 , 0 , 0 ]> : tensor <8 xindex >} : () -> !tosa.shape <8 >
1051
+ %padded = tosa.pad %arg0 , %padding , %pad_const : (tensor <1 x16 x?x3 xf32 >, !tosa.shape <8 >, tensor <1 xf32 >) -> tensor <1 x16 x?x3 xf32 >
1052
+ %start = tosa.const_shape {values = dense <[0 , 0 , 0 , 0 ]> : tensor <4 xindex >} : () -> !tosa.shape <4 >
1053
+ %size = tosa.const_shape {values = dense <[1 , 16 , 15 , 2 ]> : tensor <4 xindex >} : () -> !tosa.shape <4 >
1054
+ %sliced = tosa.slice %padded , %start , %size : (tensor <1 x16 x?x3 xf32 >, !tosa.shape <4 >, !tosa.shape <4 >) -> tensor <1 x16 x?x2 xf32 >
1055
+ return %sliced : tensor <1 x16 x?x2 xf32 >
1056
+ }
1057
+
1058
+ // -----
1059
+
988
1060
// CHECK-LABEL: @fold_log_exp
989
1061
func.func @fold_log_exp (%arg0: tensor <?x1 xf32 >) -> tensor <?x1 xf32 > {
990
1062
// CHECK: return %arg{{.*}} : tensor<?x1xf32>
0 commit comments