@@ -624,18 +624,22 @@ func.func @transpose_canonicalize_strip_quant() -> (tensor<2x1x3x!quant.uniform<
624624
625625// CHECK-LABEL: @slice_fold
626626func.func @slice_fold (%arg0: tensor <3 x4 xf32 >) -> tensor <3 x4 xf32 > {
627+ %0 = tosa.const_shape {value = dense <[0 , 0 ]> : tensor <2 xindex >} : () -> !tosa.shape <2 >
628+ %1 = tosa.const_shape {value = dense <[3 , 4 ]> : tensor <2 xindex >} : () -> !tosa.shape <2 >
627629 // CHECK: return %arg0
628- %0 = tosa.slice %arg0 { size = array< i64 : 3 , 4 >, start = array< i64 : 0 , 0 >}: ( tensor < 3 x 4 x f32 >) -> tensor <3 x4 xf32 >
629- return %0 : tensor <3 x4 xf32 >
630+ %3 = tosa.slice %arg0 , %0 , %1 : ( tensor < 3 x 4 x f32 >, !tosa.shape < 2 >, !tosa.shape < 2 >) -> tensor <3 x4 xf32 >
631+ return %3 : tensor <3 x4 xf32 >
630632}
631633
632634// -----
633635
634636// CHECK-LABEL: @slice_nofold
635637func.func @slice_nofold (%arg0: tensor <?x4 xf32 >) -> tensor <?x4 xf32 > {
638+ %0 = tosa.const_shape {value = dense <[0 , 0 ]> : tensor <2 xindex >} : () -> !tosa.shape <2 >
639+ %1 = tosa.const_shape {value = dense <[3 , 4 ]> : tensor <2 xindex >} : () -> !tosa.shape <2 >
636640 // CHECK: tosa.slice
637- %0 = tosa.slice %arg0 { size = array< i64 : 3 , 4 >, start = array< i64 : 0 , 0 >}: (tensor <?x4 xf32 >) -> tensor <?x4 xf32 >
638- return %0 : tensor <?x4 xf32 >
641+ %3 = tosa.slice %arg0 , %0 , %1 : (tensor <?x4 xf32 >, !tosa.shape < 2 >, !tosa.shape < 2 >) -> tensor <?x4 xf32 >
642+ return %3 : tensor <?x4 xf32 >
639643}
640644
641645// -----
@@ -715,9 +719,12 @@ func.func @fold_resize_bilinear(%arg0 : tensor<1x15x13x1xi8>) -> tensor<1x15x13x
715719// CHECK: return %[[VAL_0]], %[[VAL_1]] : tensor<1x12x12x1xf32>, tensor<1x12x12x1xf32>
716720func.func @canonicalize_concat_slice_final_axis (%arg0 : tensor <1 x12 x12 x1 xf32 >, %arg1 : tensor <1 x12 x12 x1 xf32 >) -> (tensor <1 x12 x12 x1 xf32 >, tensor <1 x12 x12 x1 xf32 >) {
717721 %0 = tosa.concat %arg0 , %arg1 {axis = 3 : i32 } : (tensor <1 x12 x12 x1 xf32 >, tensor <1 x12 x12 x1 xf32 >) -> tensor <1 x12 x12 x2 xf32 >
718- %1 = tosa.slice %0 {size = array<i64 : 1 , 12 , 12 , 1 >, start = array<i64 : 0 , 0 , 0 , 0 >} : (tensor <1 x12 x12 x2 xf32 >) -> tensor <1 x12 x12 x1 xf32 >
719- %2 = tosa.slice %0 {size = array<i64 : 1 , 12 , 12 , 1 >, start = array<i64 : 0 , 0 , 0 , 1 >} : (tensor <1 x12 x12 x2 xf32 >) -> tensor <1 x12 x12 x1 xf32 >
720- return %1 , %2 : tensor <1 x12 x12 x1 xf32 >, tensor <1 x12 x12 x1 xf32 >
722+ %1 = tosa.const_shape {value = dense <[0 , 0 , 0 , 0 ]> : tensor <4 xindex >} : () -> !tosa.shape <4 >
723+ %2 = tosa.const_shape {value = dense <[0 , 0 , 0 , 1 ]> : tensor <4 xindex >} : () -> !tosa.shape <4 >
724+ %3 = tosa.const_shape {value = dense <[1 , 12 , 12 , 1 ]> : tensor <4 xindex >} : () -> !tosa.shape <4 >
725+ %4 = tosa.slice %0 , %1 , %3 : (tensor <1 x12 x12 x2 xf32 >, !tosa.shape <4 >, !tosa.shape <4 >) -> tensor <1 x12 x12 x1 xf32 >
726+ %5 = tosa.slice %0 , %2 , %3 : (tensor <1 x12 x12 x2 xf32 >, !tosa.shape <4 >, !tosa.shape <4 >) -> tensor <1 x12 x12 x1 xf32 >
727+ return %4 , %5 : tensor <1 x12 x12 x1 xf32 >, tensor <1 x12 x12 x1 xf32 >
721728}
722729
723730// -----
@@ -727,38 +734,56 @@ func.func @canonicalize_concat_slice_final_axis(%arg0 : tensor<1x12x12x1xf32>, %
727734// CHECK: return %[[VAL_0]], %[[VAL_1]] : tensor<1x12x12xf32>, tensor<1x12x12xf32>
728735func.func @canonicalize_concat_slice_middle_axis (%arg0 : tensor <1 x12 x12 xf32 >, %arg1 : tensor <1 x12 x12 xf32 >) -> (tensor <1 x12 x12 xf32 >, tensor <1 x12 x12 xf32 >) {
729736 %0 = tosa.concat %arg0 , %arg1 {axis = 1 : i32 } : (tensor <1 x12 x12 xf32 >, tensor <1 x12 x12 xf32 >) -> tensor <1 x24 x12 xf32 >
730- %1 = tosa.slice %0 {size = array<i64 : 1 , 12 , 12 >, start = array<i64 : 0 , 0 , 0 >} : (tensor <1 x24 x12 xf32 >) -> tensor <1 x12 x12 xf32 >
731- %2 = tosa.slice %0 {size = array<i64 : 1 , 12 , 12 >, start = array<i64 : 0 , 12 , 0 >} : (tensor <1 x24 x12 xf32 >) -> tensor <1 x12 x12 xf32 >
732- return %1 , %2 : tensor <1 x12 x12 xf32 >, tensor <1 x12 x12 xf32 >
737+ %1 = tosa.const_shape {value = dense <[0 , 0 , 0 ]> : tensor <3 xindex >} : () -> !tosa.shape <3 >
738+ %2 = tosa.const_shape {value = dense <[0 , 12 , 0 ]> : tensor <3 xindex >} : () -> !tosa.shape <3 >
739+ %3 = tosa.const_shape {value = dense <[1 , 12 , 12 ]> : tensor <3 xindex >} : () -> !tosa.shape <3 >
740+ %4 = tosa.slice %0 , %1 , %3 : (tensor <1 x24 x12 xf32 >, !tosa.shape <3 >, !tosa.shape <3 >) -> tensor <1 x12 x12 xf32 >
741+ %5 = tosa.slice %0 , %2 , %3 : (tensor <1 x24 x12 xf32 >, !tosa.shape <3 >, !tosa.shape <3 >) -> tensor <1 x12 x12 xf32 >
742+ return %4 , %5 : tensor <1 x12 x12 xf32 >, tensor <1 x12 x12 xf32 >
733743}
734744
735745// -----
736746
737747// CHECK-LABEL: @canonicalize_cross_concat_inputs
738748// CHECK-SAME: %[[VAL_0:.*]]: tensor<1x12x12xf32>, %[[VAL_1:.*]]: tensor<1x12x12xf32>
739- // CHECK: %[[VAL_2:.*]] = tosa.concat %[[VAL_0]], %[[VAL_1]] {axis = 2 : i32} : (tensor<1x12x12xf32>, tensor<1x12x12xf32>) -> tensor<1x12x24xf32>
740- // CHECK: %[[VAL_3:.*]] = tosa.slice %[[VAL_2]] {size = array<i64: 1, 12, 15>, start = array<i64: 0, 0, 0>} : (tensor<1x12x24xf32>) -> tensor<1x12x15xf32>
741- // CHECK: %[[VAL_4:.*]] = tosa.slice %[[VAL_2]] {size = array<i64: 1, 12, 20>, start = array<i64: 0, 0, 4>} : (tensor<1x12x24xf32>) -> tensor<1x12x20xf32>
742- // CHECK: return %[[VAL_3]], %[[VAL_4]] : tensor<1x12x15xf32>, tensor<1x12x20xf32>
749+ // CHECK-DAG: %[[VAL_2:.*]] = tosa.const_shape {value = dense<[1, 12, 20]> : tensor<3xindex>}
750+ // CHECK-DAG: %[[VAL_3:.*]] = tosa.const_shape {value = dense<[1, 12, 15]> : tensor<3xindex>}
751+ // CHECK-DAG: %[[VAL_4:.*]] = tosa.const_shape {value = dense<[0, 0, 4]> : tensor<3xindex>}
752+ // CHECK-DAG: %[[VAL_5:.*]] = tosa.const_shape {value = dense<0> : tensor<3xindex>}
753+ // CHECK: %[[VAL_6:.*]] = tosa.concat %[[VAL_0]], %[[VAL_1]] {axis = 2 : i32} : (tensor<1x12x12xf32>, tensor<1x12x12xf32>) -> tensor<1x12x24xf32>
754+ // CHECK: %[[VAL_7:.*]] = tosa.slice %[[VAL_6]], %[[VAL_5]], %[[VAL_3]]
755+ // CHECK: %[[VAL_8:.*]] = tosa.slice %[[VAL_6]], %[[VAL_4]], %[[VAL_2]]
756+ // CHECK: return %[[VAL_7]], %[[VAL_8]] : tensor<1x12x15xf32>, tensor<1x12x20xf32>
743757func.func @canonicalize_cross_concat_inputs (%arg0 : tensor <1 x12 x12 xf32 >, %arg1 : tensor <1 x12 x12 xf32 >) -> (tensor <1 x12 x15 xf32 >, tensor <1 x12 x20 xf32 >) {
744758 %0 = tosa.concat %arg0 , %arg1 {axis = 2 : i32 } : (tensor <1 x12 x12 xf32 >, tensor <1 x12 x12 xf32 >) -> tensor <1 x12 x24 xf32 >
745- %1 = tosa.slice %0 {size = array<i64 : 1 , 12 , 15 >, start = array<i64 : 0 , 0 , 0 >} : (tensor <1 x12 x24 xf32 >) -> tensor <1 x12 x15 xf32 >
746- %2 = tosa.slice %0 {size = array<i64 : 1 , 12 , 20 >, start = array<i64 : 0 , 0 , 4 >} : (tensor <1 x12 x24 xf32 >) -> tensor <1 x12 x20 xf32 >
747- return %1 , %2 : tensor <1 x12 x15 xf32 >, tensor <1 x12 x20 xf32 >
759+ %1 = tosa.const_shape {value = dense <[0 , 0 , 0 ]> : tensor <3 xindex >} : () -> !tosa.shape <3 >
760+ %2 = tosa.const_shape {value = dense <[0 , 0 , 4 ]> : tensor <3 xindex >} : () -> !tosa.shape <3 >
761+ %3 = tosa.const_shape {value = dense <[1 , 12 , 15 ]> : tensor <3 xindex >} : () -> !tosa.shape <3 >
762+ %4 = tosa.const_shape {value = dense <[1 , 12 , 20 ]> : tensor <3 xindex >} : () -> !tosa.shape <3 >
763+ %5 = tosa.slice %0 , %1 , %3 : (tensor <1 x12 x24 xf32 >, !tosa.shape <3 >, !tosa.shape <3 >) -> tensor <1 x12 x15 xf32 >
764+ %6 = tosa.slice %0 , %2 , %4 : (tensor <1 x12 x24 xf32 >, !tosa.shape <3 >, !tosa.shape <3 >) -> tensor <1 x12 x20 xf32 >
765+ return %5 , %6 : tensor <1 x12 x15 xf32 >, tensor <1 x12 x20 xf32 >
748766}
749767
750768// -----
751769
752770// CHECK-LABEL: @canonicalize_concat_slice_on_non_concat_axis
753771// CHECK-SAME: %[[VAL_0:.*]]: tensor<1x12x12xf32>, %[[VAL_1:.*]]: tensor<1x12x12xf32>
754- // CHECK: %[[VAL_2:.*]] = tosa.slice %[[VAL_0]] {size = array<i64: 1, 6, 12>, start = array<i64: 0, 0, 0>} : (tensor<1x12x12xf32>) -> tensor<1x6x12xf32>
755- // CHECK: %[[VAL_3:.*]] = tosa.slice %[[VAL_1]] {size = array<i64: 1, 3, 12>, start = array<i64: 1, 3, 0>} : (tensor<1x12x12xf32>) -> tensor<1x3x12xf32>
756- // CHECK: return %[[VAL_2]], %[[VAL_3]] : tensor<1x6x12xf32>, tensor<1x3x12xf32>
772+ // CHECK-DAG: %[[VAL_2:.*]] = tosa.const_shape {value = dense<[1, 3, 0]> : tensor<3xindex>}
773+ // CHECK-DAG: %[[VAL_3:.*]] = tosa.const_shape {value = dense<[1, 3, 12]> : tensor<3xindex>}
774+ // CHECK-DAG: %[[VAL_4:.*]] = tosa.const_shape {value = dense<0> : tensor<3xindex>}
775+ // CHECK-DAG: %[[VAL_5:.*]] = tosa.const_shape {value = dense<[1, 6, 12]> : tensor<3xindex>}
776+ // CHECK: %[[VAL_6:.*]] = tosa.slice %[[VAL_0]], %[[VAL_4]], %[[VAL_5]]
777+ // CHECK: %[[VAL_7:.*]] = tosa.slice %[[VAL_1]], %[[VAL_2]], %[[VAL_3]]
778+ // CHECK: return %[[VAL_6]], %[[VAL_7]] : tensor<1x6x12xf32>, tensor<1x3x12xf32>
757779func.func @canonicalize_concat_slice_on_non_concat_axis (%arg0 : tensor <1 x12 x12 xf32 >, %arg1 : tensor <1 x12 x12 xf32 >) -> (tensor <1 x6 x12 xf32 >, tensor <1 x3 x12 xf32 >) {
758780 %0 = tosa.concat %arg0 , %arg1 {axis = 2 : i32 } : (tensor <1 x12 x12 xf32 >, tensor <1 x12 x12 xf32 >) -> tensor <1 x12 x24 xf32 >
759- %1 = tosa.slice %0 {size = array<i64 : 1 , 6 , 12 >, start = array<i64 : 0 , 0 , 0 >} : (tensor <1 x12 x24 xf32 >) -> tensor <1 x6 x12 xf32 >
760- %2 = tosa.slice %0 {size = array<i64 : 1 , 3 , 12 >, start = array<i64 : 1 , 3 , 12 >} : (tensor <1 x12 x24 xf32 >) -> tensor <1 x3 x12 xf32 >
761- return %1 , %2 : tensor <1 x6 x12 xf32 >, tensor <1 x3 x12 xf32 >
781+ %1 = tosa.const_shape {value = dense <[0 , 0 , 0 ]> : tensor <3 xindex >} : () -> !tosa.shape <3 >
782+ %2 = tosa.const_shape {value = dense <[1 , 6 , 12 ]> : tensor <3 xindex >} : () -> !tosa.shape <3 >
783+ %3 = tosa.const_shape {value = dense <[1 , 3 , 12 ]> : tensor <3 xindex >} : () -> !tosa.shape <3 >
784+ %4 = tosa.slice %0 , %1 , %2 : (tensor <1 x12 x24 xf32 >, !tosa.shape <3 >, !tosa.shape <3 >) -> tensor <1 x6 x12 xf32 >
785+ %5 = tosa.slice %0 , %3 , %3 : (tensor <1 x12 x24 xf32 >, !tosa.shape <3 >, !tosa.shape <3 >) -> tensor <1 x3 x12 xf32 >
786+ return %4 , %5 : tensor <1 x6 x12 xf32 >, tensor <1 x3 x12 xf32 >
762787}
763788
764789// -----
0 commit comments