@@ -1226,4 +1226,43 @@ func.func @slice_dynamic_size_static_output_canonicalize(%arg0: tensor<2x60x59x?
12261226 %1 = tosa.const_shape {values = dense <[-1 , 60 , 58 , -1 ]> : tensor <4 xindex >} : () -> !tosa.shape <4 >
12271227 %2 = tosa.slice %arg0 , %0 , %1 : (tensor <2 x60 x59 x?xf32 >, !tosa.shape <4 >, !tosa.shape <4 >) -> tensor <2 x60 x58 x?xf32 >
12281228 return %2 : tensor <2 x60 x58 x?xf32 >
1229- }
1229+ }
1230+
1231+ // -----
1232+
1233+ // CHECK-LABEL: @fold_mul_shift
1234+ // CHECK-DAG: "tosa.const"() <{values = dense<1> : tensor<i32>}> : () -> tensor<i32>
1235+ func.func @fold_mul_shift () -> tensor <i32 > {
1236+ %0 = " tosa.const" () <{values = dense <-23661 > : tensor <i32 >}> : () -> tensor <i32 >
1237+ %1 = " tosa.const" () <{values = dense <-33022 > : tensor <i32 >}> : () -> tensor <i32 >
1238+ %2 = " tosa.const" () <{values = dense <30 > : tensor <1 xi8 >}> : () -> tensor <1 xi8 >
1239+ %3 = tosa.mul %0 , %1 , %2 : (tensor <i32 >, tensor <i32 >, tensor <1 xi8 >) -> tensor <i32 >
1240+ return %3 : tensor <i32 >
1241+ }
1242+
1243+ // -----
1244+
1245+ // CHECK-LABEL: @fold_mul_no_shift
1246+ // CHECK-DAG: "tosa.const"() <{values = dense<781333542> : tensor<i32>}> : () -> tensor<i32>
1247+ func.func @fold_mul_no_shift () -> tensor <i32 > {
1248+ %0 = " tosa.const" () <{values = dense <-23661 > : tensor <i32 >}> : () -> tensor <i32 >
1249+ %1 = " tosa.const" () <{values = dense <-33022 > : tensor <i32 >}> : () -> tensor <i32 >
1250+ %2 = " tosa.const" () <{values = dense <0 > : tensor <1 xi8 >}> : () -> tensor <1 xi8 >
1251+ %3 = tosa.mul %0 , %1 , %2 : (tensor <i32 >, tensor <i32 >, tensor <1 xi8 >) -> tensor <i32 >
1252+ return %3 : tensor <i32 >
1253+ }
1254+
1255+ // -----
1256+
1257+ // CHECK-LABEL: @no_fold_mul_result_exceeds_i32
1258+ // CHECK-DAG: %[[LHS:.*]] = "tosa.const"() <{values = dense<23661> : tensor<i32>}> : () -> tensor<i32>
1259+ // CHECK-DAG: %[[RHS:.*]] = "tosa.const"() <{values = dense<330222> : tensor<i32>}> : () -> tensor<i32>
1260+ // CHECK-DAG: %[[SHIFT:.*]] = "tosa.const"() <{values = dense<1> : tensor<1xi8>}> : () -> tensor<1xi8>
1261+ // CHECK: tosa.mul %[[LHS]], %[[RHS]], %[[SHIFT]] : (tensor<i32>, tensor<i32>, tensor<1xi8>) -> tensor<i32>
1262+ func.func @no_fold_mul_result_exceeds_i32 () -> tensor <i32 > {
1263+ %0 = " tosa.const" () <{values = dense <23661 > : tensor <i32 >}> : () -> tensor <i32 >
1264+ %1 = " tosa.const" () <{values = dense <330222 > : tensor <i32 >}> : () -> tensor <i32 >
1265+ %2 = " tosa.const" () <{values = dense <1 > : tensor <1 xi8 >}> : () -> tensor <1 xi8 >
1266+ %3 = tosa.mul %0 , %1 , %2 : (tensor <i32 >, tensor <i32 >, tensor <1 xi8 >) -> tensor <i32 >
1267+ return %3 : tensor <i32 >
1268+ }
0 commit comments