1187 lines · plain
1// RUN: mlir-opt --split-input-file --tosa-layerwise-constant-fold %s | FileCheck %s2 3 4// RUN: mlir-opt --split-input-file --tosa-layerwise-constant-fold="aggressive-reduce-constant=true" %s | FileCheck %s --check-prefix=AGGRESIVE5 6// CHECK-LABEL: @armax_fold_dim_size_17func.func @armax_fold_dim_size_1(%arg0: tensor<2x1x3xf32>) -> tensor<2x3xi32> {8 // CHECK: "tosa.const"() <{values = dense<0> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>9 %0 = tosa.argmax %arg0 {axis = 1 : i32}: (tensor<2x1x3xf32>) -> tensor<2x3xi32>10 return %0 : tensor<2x3xi32>11}12 13// CHECK-LABEL: @argmax_dynamic_shape_no_fold_dim_size_114func.func @argmax_dynamic_shape_no_fold_dim_size_1(%arg0: tensor<?x1x3xf32>) -> tensor<?x3xi32> {15 // CHECK: tosa.argmax16 %0 = tosa.argmax %arg0 {axis = 1 : i32}: (tensor<?x1x3xf32>) -> tensor<?x3xi32>17 return %0 : tensor<?x3xi32>18}19 20// CHECK-LABEL: @transpose_fold21func.func @transpose_fold(%arg0: tensor<3x4xf32>) -> tensor<3x4xf32> {22 // CHECK: return %arg023 %1 = tosa.transpose %arg0 { perms = array<i32: 0, 1> }: (tensor<3x4xf32>) -> tensor<3x4xf32>24 return %1 : tensor<3x4xf32>25}26 27// CHECK-LABEL: @transpose_nofold28func.func @transpose_nofold(%arg0: tensor<3x3xf32>) -> tensor<3x3xf32> {29 // CHECK: tosa.transpose30 %1 = tosa.transpose %arg0 { perms = array<i32: 1, 0> }: (tensor<3x3xf32>) -> tensor<3x3xf32>31 return %1 : tensor<3x3xf32>32}33 34// CHECK-LABEL: @transpose_nofold_shape35func.func @transpose_nofold_shape(%arg0: tensor<3x4xf32>) -> tensor<?x?xf32> {36 // CHECK: tosa.transpose37 %1 = tosa.transpose %arg0 { perms = array<i32: 1, 0> }: (tensor<3x4xf32>) -> tensor<?x?xf32>38 return %1 : tensor<?x?xf32>39}40 41// CHECK-LABEL: @transpose_fold_splat42func.func @transpose_fold_splat() -> tensor<3x2xf32> {43 %input = "tosa.const"() {values = dense<4.0> : tensor<2x3xf32>} : () -> tensor<2x3xf32>44 // CHECK: %[[CST:.+]] = "tosa.const"() <{45 // CHECK-SAME{LITERAL}: values = dense<4.000000e+00> : tensor<3x2xf32>46 %1 = tosa.transpose %input { perms = array<i32: 1, 0> }: (tensor<2x3xf32>) -> tensor<3x2xf32>47 // CHECK: return %[[CST]]48 return %1 : tensor<3x2xf32>49}50 51// CHECK-LABEL: @transpose_fold_2d_float52func.func @transpose_fold_2d_float() -> tensor<3x2xf32> {53 %input = "tosa.const"() {values = dense<[[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]]> : tensor<2x3xf32>} : () -> tensor<2x3xf32>54 // CHECK: %[[CST:.+]] = "tosa.const"() <{55 // CHECK-SAME{LITERAL}: values = dense<[[0.000000e+00, 3.000000e+00], [1.000000e+00, 4.000000e+00], [2.000000e+00, 5.000000e+00]]> : tensor<3x2xf32>56 %1 = tosa.transpose %input { perms = array<i32: 1, 0> }: (tensor<2x3xf32>) -> tensor<3x2xf32>57 // CHECK: return %[[CST]]58 return %1 : tensor<3x2xf32>59}60 61// CHECK-LABEL: @transpose_fold_2d_bool62func.func @transpose_fold_2d_bool() -> tensor<3x2xi1> {63 %input = "tosa.const"() {values = dense<[[true, false, false], [false, false, true]]> : tensor<2x3xi1>} : () -> tensor<2x3xi1>64 // CHECK: %[[CST:.+]] = "tosa.const"() <{65 // CHECK-SAME{LITERAL}: values = dense<[[true, false], [false, false], [false, true]]> : tensor<3x2xi1>66 %1 = tosa.transpose %input { perms = array<i32: 1, 0> }: (tensor<2x3xi1>) -> tensor<3x2xi1>67 // CHECK: return %[[CST]]68 return %1 : tensor<3x2xi1>69}70 71// CHECK-LABEL: @transpose_fold_4d_int72func.func @transpose_fold_4d_int() -> tensor<3x1x4x2xi32> {73 %input = "tosa.const"() {values = dense<[[74 [[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]],75 [[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]]76 ]]> : tensor<1x2x3x4xi32>} : () -> tensor<1x2x3x4xi32>77 // CHECK: %[[CST:.+]] = "tosa.const"() <{78 // CHECK-SAME{LITERAL}: values = dense<[79 // CHECK-SAME{LITERAL}: [[[0, 12], [1, 13], [2, 14], [3, 15]]],80 // CHECK-SAME{LITERAL}: [[[4, 16], [5, 17], [6, 18], [7, 19]]],81 // CHECK-SAME{LITERAL}: [[[8, 20], [9, 21], [10, 22], [11, 23]]]82 // CHECK-SAME{LITERAL}: ]>83 %1 = tosa.transpose %input { perms = array<i32: 2, 0, 3, 1> }: (tensor<1x2x3x4xi32>) -> tensor<3x1x4x2xi32>84 // CHECK: return %[[CST]]85 return %1 : tensor<3x1x4x2xi32>86}87 88// CHECK-LABEL: @transpose_nofold_non_cst_input89func.func @transpose_nofold_non_cst_input(%input: tensor<2x3xf32>) -> tensor<3x2xf32> {90 // CHECK: tosa.transpose91 %1 = tosa.transpose %input { perms = array<i32: 1, 0> }: (tensor<2x3xf32>) -> tensor<3x2xf32>92 return %1 : tensor<3x2xf32>93}94 95// CHECK-LABEL: @transpose_nofold_multi_users96func.func @transpose_nofold_multi_users() -> (tensor<3x2xf32>, tensor<2x3xf32>) {97 %input = "tosa.const"() {values = dense<[[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]]> : tensor<2x3xf32>} : () -> tensor<2x3xf32>98 // CHECK: tosa.transpose99 %1 = tosa.transpose %input { perms = array<i32: 1, 0> }: (tensor<2x3xf32>) -> tensor<3x2xf32>100 return %1, %input : tensor<3x2xf32>, tensor<2x3xf32>101}102 103// CHECK-LABEL: @transpose_nofold_quantized_types104func.func @transpose_nofold_quantized_types() -> tensor<1x1x2x2x!quant.uniform<i8<-127:127>:f32:3, {1.000000e-01,1.000000e-01}>> {105 %input = "tosa.const"() {values = dense<-127> : tensor<2x1x1x2xi8>} : () -> tensor<2x1x1x2x!quant.uniform<i8<-127:127>:f32:3, {1.000000e-01,1.000000e-01}>>106 // CHECK: tosa.transpose107 %0 = tosa.transpose %input { perms = array<i32: 1, 2, 3, 0> }: (tensor<2x1x1x2x!quant.uniform<i8<-127:127>:f32:3, {1.000000e-01,1.000000e-01}>>) -> tensor<1x1x2x2x!quant.uniform<i8<-127:127>:f32:3, {1.000000e-01,1.000000e-01}>>108 return %0: tensor<1x1x2x2x!quant.uniform<i8<-127:127>:f32:3, {1.000000e-01,1.000000e-01}>>109}110 111// CHECK-LABEL: @transpose_fold_dense_resource112func.func @transpose_fold_dense_resource() -> tensor<2x2xf32> {113 %0 = "tosa.const"() <{values = dense_resource<resource> : tensor<2x2xf32>}> : () -> tensor<2x2xf32>114 115 // CHECK-NOT: tosa.transpose116 %2 = tosa.transpose %0 { perms = array<i32: 1, 0> }: (tensor<2x2xf32>) -> tensor<2x2xf32>117 return %2 : tensor<2x2xf32>118}119{-#120 dialect_resources: {121 builtin: {122 resource: "0x040000003f800000400000004040000040800000"123 }124 }125#-}126 127// -----128 129// CHECK-LABEL: @fold_add_zero_rhs_f32130func.func @fold_add_zero_rhs_f32(%arg0: tensor<f32>) -> tensor<f32> {131 %zero = "tosa.const"() {values = dense<0.0> : tensor<f32>} : () -> tensor<f32>132 %add = tosa.add %arg0, %zero : (tensor<f32>, tensor<f32>) -> tensor<f32>133 // CHECK: return %arg0134 return %add : tensor<f32>135}136 137// -----138 139// CHECK-LABEL: @fold_add_zero_lhs_f32140func.func @fold_add_zero_lhs_f32(%arg0: tensor<f32>) -> tensor<f32> {141 %zero = "tosa.const"() {values = dense<0.0> : tensor<f32>} : () -> tensor<f32>142 %add = tosa.add %zero, %arg0 : (tensor<f32>, tensor<f32>) -> tensor<f32>143 // CHECK: return %arg0144 return %add : tensor<f32>145}146 147// -----148 149// CHECK-LABEL: @fold_add_zero_rhs_i32150func.func @fold_add_zero_rhs_i32(%arg0: tensor<i32>) -> tensor<i32> {151 %zero = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>152 %add = tosa.add %arg0, %zero : (tensor<i32>, tensor<i32>) -> tensor<i32>153 // CHECK: return %arg0154 return %add : tensor<i32>155}156 157// -----158 159// CHECK-LABEL: @fold_add_zero_lhs_i32160func.func @fold_add_zero_lhs_i32(%arg0: tensor<i32>) -> tensor<i32> {161 %zero = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>162 %add = tosa.add %zero, %arg0 : (tensor<i32>, tensor<i32>) -> tensor<i32>163 // CHECK: return %arg0164 return %add : tensor<i32>165}166 167// -----168 169// CHECK-LABEL: @fold_add_splat_i32170func.func @fold_add_splat_i32() -> tensor<10xi32> {171 %one = "tosa.const"() {values = dense<1> : tensor<10xi32>} : () -> tensor<10xi32>172 %two = "tosa.const"() {values = dense<2> : tensor<10xi32>} : () -> tensor<10xi32>173 %add = tosa.add %one, %two : (tensor<10xi32>, tensor<10xi32>) -> tensor<10xi32>174 // CHECK: %[[THREE:.+]] = "tosa.const"() <{values = dense<3> : tensor<10xi32>}175 // CHECK: return %[[THREE]]176 return %add : tensor<10xi32>177}178 179// -----180 181// CHECK-LABEL: @fold_add_splat_f32182func.func @fold_add_splat_f32() -> tensor<10xf32> {183 %one = "tosa.const"() {values = dense<1.0> : tensor<10xf32>} : () -> tensor<10xf32>184 %two = "tosa.const"() {values = dense<2.0> : tensor<10xf32>} : () -> tensor<10xf32>185 %add = tosa.add %one, %two : (tensor<10xf32>, tensor<10xf32>) -> tensor<10xf32>186 // CHECK: %[[THREE:.+]] = "tosa.const"() <{values = dense<3.000000e+00>187 // CHECK: return %[[THREE]]188 return %add : tensor<10xf32>189}190 191// -----192 193// CHECK-LABEL: @fold_div_zero_lhs_i32194func.func @fold_div_zero_lhs_i32(%arg0: tensor<i32>) -> tensor<i32> {195 %zero = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>196 // CHECK: %[[ZERO:.+]] = "tosa.const"() <{values = dense<0>197 %div = tosa.intdiv %zero, %arg0 : (tensor<i32>, tensor<i32>) -> tensor<i32>198 // CHECK: return %[[ZERO]]199 return %div : tensor<i32>200}201 202// -----203 204// CHECK-LABEL: @fold_div_one_rhs_i32205func.func @fold_div_one_rhs_i32(%arg0: tensor<i32>) -> tensor<i32> {206 %one = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>207 %div = tosa.intdiv %arg0, %one : (tensor<i32>, tensor<i32>) -> tensor<i32>208 // CHECK: return %arg0209 return %div : tensor<i32>210}211 212// -----213 214// CHECK-LABEL: @fold_div_splat_i32215func.func @fold_div_splat_i32() -> tensor<i32> {216 %lhs = "tosa.const"() {values = dense<10> : tensor<i32>} : () -> tensor<i32>217 %rhs = "tosa.const"() {values = dense<-3> : tensor<i32>} : () -> tensor<i32>218 // CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<-3>219 %div = tosa.intdiv %lhs, %rhs : (tensor<i32>, tensor<i32>) -> tensor<i32>220 // CHECK: return %[[SPLAT]]221 return %div : tensor<i32>222}223 224// -----225 226 227// CHECK-LABEL: @fold_mul_zero_rhs_f32228func.func @fold_mul_zero_rhs_f32(%arg0: tensor<f32>) -> tensor<f32> {229 %zero = "tosa.const"() {values = dense<0.0> : tensor<f32>} : () -> tensor<f32>230 // CHECK: %[[ZERO:.+]] = "tosa.const"() <{values = dense<0.000000e+00>231 %shift = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>232 %mul = tosa.mul %arg0, %zero, %shift : (tensor<f32>, tensor<f32>, tensor<1xi8>) -> tensor<f32>233 // CHECK: return %[[ZERO]]234 return %mul : tensor<f32>235}236 237// -----238 239// CHECK-LABEL: @fold_mul_zero_lhs_f32240func.func @fold_mul_zero_lhs_f32(%arg0: tensor<f32>) -> tensor<f32> {241 %zero = "tosa.const"() {values = dense<0.0> : tensor<f32>} : () -> tensor<f32>242 // CHECK: %[[ZERO:.+]] = "tosa.const"() <{values = dense<0.000000e+00>243 %shift = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>244 %mul = tosa.mul %zero, %arg0, %shift : (tensor<f32>, tensor<f32>, tensor<1xi8>) -> tensor<f32>245 // CHECK: return %[[ZERO]]246 return %mul : tensor<f32>247}248 249// -----250 251// CHECK-LABEL: @fold_mul_zero_rhs_i32252func.func @fold_mul_zero_rhs_i32(%arg0: tensor<i32>) -> tensor<i32> {253 %zero = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>254 %shift = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>255 // CHECK: %[[ZERO:.+]] = "tosa.const"() <{values = dense<0>256 %mul = tosa.mul %arg0, %zero, %shift : (tensor<i32>, tensor<i32>, tensor<1xi8>) -> tensor<i32>257 // CHECK: return %[[ZERO]]258 return %mul : tensor<i32>259}260 261// -----262 263// CHECK-LABEL: @fold_mul_zero_lhs_i32264func.func @fold_mul_zero_lhs_i32(%arg0: tensor<i32>) -> tensor<i32> {265 %zero = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>266 %shift = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>267 // CHECK: %[[ZERO:.+]] = "tosa.const"() <{values = dense<0>268 %mul = tosa.mul %zero, %arg0, %shift : (tensor<i32>, tensor<i32>, tensor<1xi8>) -> tensor<i32>269 // CHECK: return %[[ZERO]]270 return %mul : tensor<i32>271}272 273// -----274 275// CHECK-LABEL: @fold_mul_one_rhs_f32276func.func @fold_mul_one_rhs_f32(%arg0: tensor<f32>) -> tensor<f32> {277 %one = "tosa.const"() {values = dense<1.0> : tensor<f32>} : () -> tensor<f32>278 %shift = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>279 %mul = tosa.mul %arg0, %one, %shift : (tensor<f32>, tensor<f32>, tensor<1xi8>) -> tensor<f32>280 // CHECK: return %arg0281 return %mul : tensor<f32>282}283 284// -----285 286// CHECK-LABEL: @fold_mul_one_lhs_f32287func.func @fold_mul_one_lhs_f32(%arg0: tensor<f32>) -> tensor<f32> {288 %one = "tosa.const"() {values = dense<1.0> : tensor<f32>} : () -> tensor<f32>289 %shift = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>290 %mul = tosa.mul %one, %arg0, %shift : (tensor<f32>, tensor<f32>, tensor<1xi8>) -> tensor<f32>291 // CHECK: return %arg0292 return %mul : tensor<f32>293}294 295// -----296 297// CHECK-LABEL: @fold_mul_one_rhs_i32298func.func @fold_mul_one_rhs_i32(%arg0: tensor<i32>) -> tensor<i32> {299 %one = "tosa.const"() {values = dense<64> : tensor<i32>} : () -> tensor<i32>300 %shift = "tosa.const"() {values = dense<6> : tensor<1xi8>} : () -> tensor<1xi8>301 %mul = tosa.mul %arg0, %one, %shift : (tensor<i32>, tensor<i32>, tensor<1xi8>) -> tensor<i32>302 // CHECK: return %arg0303 return %mul : tensor<i32>304}305 306// -----307 308// CHECK-LABEL: @fold_mul_one_lhs_i32309func.func @fold_mul_one_lhs_i32(%arg0: tensor<i32>) -> tensor<i32> {310 %one = "tosa.const"() {values = dense<64> : tensor<i32>} : () -> tensor<i32>311 %shift = "tosa.const"() {values = dense<6> : tensor<1xi8>} : () -> tensor<1xi8>312 %mul = tosa.mul %one, %arg0, %shift : (tensor<i32>, tensor<i32>, tensor<1xi8>) -> tensor<i32>313 // CHECK: return %arg0314 return %mul : tensor<i32>315}316 317// -----318 319// CHECK-LABEL: @fold_mul_splat_i8320func.func @fold_mul_splat_i8() -> tensor<10xi32> {321 %one = "tosa.const"() {values = dense<17> : tensor<10xi8>} : () -> tensor<10xi8>322 %two = "tosa.const"() {values = dense<32> : tensor<10xi8>} : () -> tensor<10xi8>323 %shift = "tosa.const"() {values = dense<3> : tensor<1xi8>} : () -> tensor<1xi8>324 %mul = tosa.mul %one, %two, %shift : (tensor<10xi8>, tensor<10xi8>, tensor<1xi8>) -> tensor<10xi32>325 // CHECK: %[[THREE:.+]] = "tosa.const"() <{values = dense<68> : tensor<10xi32>}326 // CHECK: return %[[THREE]]327 return %mul : tensor<10xi32>328}329 330// -----331 332// CHECK-LABEL: @fold_mul_splat_f32333func.func @fold_mul_splat_f32() -> tensor<10xf32> {334 %one = "tosa.const"() {values = dense<3.0> : tensor<10xf32>} : () -> tensor<10xf32>335 %two = "tosa.const"() {values = dense<2.0> : tensor<10xf32>} : () -> tensor<10xf32>336 %shift = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>337 %mul = tosa.mul %one, %two, %shift : (tensor<10xf32>, tensor<10xf32>, tensor<1xi8>) -> tensor<10xf32>338 // CHECK: %[[THREE:.+]] = "tosa.const"() <{values = dense<6.000000e+00> : tensor<10xf32>}339 // CHECK: return %[[THREE]]340 return %mul : tensor<10xf32>341}342 343// -----344 345// CHECK-LABEL: @fold_sub_zero_rhs_f32346func.func @fold_sub_zero_rhs_f32(%arg0: tensor<f32>) -> tensor<f32> {347 %zero = "tosa.const"() {values = dense<0.0> : tensor<f32>} : () -> tensor<f32>348 %sub = tosa.sub %arg0, %zero : (tensor<f32>, tensor<f32>) -> tensor<f32>349 // CHECK: return %arg0350 return %sub : tensor<f32>351}352 353// -----354 355// CHECK-LABEL: @fold_sub_zero_rhs_i32356func.func @fold_sub_zero_rhs_i32(%arg0: tensor<i32>) -> tensor<i32> {357 %zero = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>358 %sub = tosa.sub %arg0, %zero : (tensor<i32>, tensor<i32>) -> tensor<i32>359 // CHECK: return %arg0360 return %sub : tensor<i32>361}362 363// -----364 365// CHECK-LABEL: @fold_sub_splat_i32366func.func @fold_sub_splat_i32() -> tensor<10xi32> {367 %one = "tosa.const"() {values = dense<1> : tensor<10xi32>} : () -> tensor<10xi32>368 %two = "tosa.const"() {values = dense<2> : tensor<10xi32>} : () -> tensor<10xi32>369 %sub = tosa.sub %one, %two : (tensor<10xi32>, tensor<10xi32>) -> tensor<10xi32>370 // CHECK: %[[THREE:.+]] = "tosa.const"() <{values = dense<-1> : tensor<10xi32>}371 // CHECK: return %[[THREE]]372 return %sub : tensor<10xi32>373}374 375// -----376 377// CHECK-LABEL: @fold_sub_splat_f32378func.func @fold_sub_splat_f32() -> tensor<10xf32> {379 %one = "tosa.const"() {values = dense<1.0> : tensor<10xf32>} : () -> tensor<10xf32>380 %two = "tosa.const"() {values = dense<2.0> : tensor<10xf32>} : () -> tensor<10xf32>381 %sub = tosa.sub %one, %two : (tensor<10xf32>, tensor<10xf32>) -> tensor<10xf32>382 // CHECK: %[[THREE:.+]] = "tosa.const"() <{values = dense<-1.000000e+00> : tensor<10xf32>}383 // CHECK: return %[[THREE]]384 return %sub : tensor<10xf32>385}386 387// -----388 389// CHECK-LABEL: @fold_greater_splat_f32390func.func @fold_greater_splat_f32() -> (tensor<10xi1>, tensor<10xi1>) {391 %0 = "tosa.const"() {values = dense<4.0> : tensor<10xf32>} : () -> tensor<10xf32>392 %1 = "tosa.const"() {values = dense<2.0> : tensor<10xf32>} : () -> tensor<10xf32>393 %2 = "tosa.const"() {values = dense<1.0> : tensor<10xf32>} : () -> tensor<10xf32>394 %3 = "tosa.const"() {values = dense<2.0> : tensor<10xf32>} : () -> tensor<10xf32>395 %true = tosa.greater %0, %1 : (tensor<10xf32>, tensor<10xf32>) -> tensor<10xi1>396 %false = tosa.greater %2, %3 : (tensor<10xf32>, tensor<10xf32>) -> tensor<10xi1>397 // CHECK-DAG: %[[TRUE:.+]] = "tosa.const"() <{values = dense<true> : tensor<10xi1>}398 // CHECK-DAG: %[[FALSE:.+]] = "tosa.const"() <{values = dense<false> : tensor<10xi1>}399 // CHECK: return %[[TRUE]], %[[FALSE]]400 return %true, %false : tensor<10xi1>, tensor<10xi1>401}402 403// -----404 405// CHECK-LABEL: @fold_greater_splat_i32406func.func @fold_greater_splat_i32() -> (tensor<10xi1>, tensor<10xi1>) {407 %0 = "tosa.const"() {values = dense<-10> : tensor<10xi32>} : () -> tensor<10xi32>408 %1 = "tosa.const"() {values = dense<8> : tensor<10xi32>} : () -> tensor<10xi32>409 %2 = "tosa.const"() {values = dense<-10> : tensor<10xi32>} : () -> tensor<10xi32>410 %3 = "tosa.const"() {values = dense<-12> : tensor<10xi32>} : () -> tensor<10xi32>411 %false = tosa.greater %0, %1 : (tensor<10xi32>, tensor<10xi32>) -> tensor<10xi1>412 %true = tosa.greater %2, %3 : (tensor<10xi32>, tensor<10xi32>) -> tensor<10xi1>413 // CHECK-DAG: %[[FALSE:.+]] = "tosa.const"() <{values = dense<false> : tensor<10xi1>}414 // CHECK-DAG: %[[TRUE:.+]] = "tosa.const"() <{values = dense<true> : tensor<10xi1>}415 // CHECK: return %[[FALSE]], %[[TRUE]]416 return %false, %true : tensor<10xi1>, tensor<10xi1>417}418 419// -----420 421// CHECK-LABEL: @fold_greater_eq_splat_f32422func.func @fold_greater_eq_splat_f32() -> (tensor<10xi1>, tensor<10xi1>) {423 %0 = "tosa.const"() {values = dense<4.0> : tensor<10xf32>} : () -> tensor<10xf32>424 %1 = "tosa.const"() {values = dense<4.0> : tensor<10xf32>} : () -> tensor<10xf32>425 %2 = "tosa.const"() {values = dense<1.0> : tensor<10xf32>} : () -> tensor<10xf32>426 %3 = "tosa.const"() {values = dense<2.0> : tensor<10xf32>} : () -> tensor<10xf32>427 %true = tosa.greater_equal %0, %1 : (tensor<10xf32>, tensor<10xf32>) -> tensor<10xi1>428 %false = tosa.greater_equal %2, %3 : (tensor<10xf32>, tensor<10xf32>) -> tensor<10xi1>429 // CHECK-DAG: %[[TRUE:.+]] = "tosa.const"() <{values = dense<true> : tensor<10xi1>}430 // CHECK-DAG: %[[FALSE:.+]] = "tosa.const"() <{values = dense<false> : tensor<10xi1>}431 // CHECK: return %[[TRUE]], %[[FALSE]]432 return %true, %false : tensor<10xi1>, tensor<10xi1>433}434 435// -----436 437// CHECK-LABEL: @fold_greater_eq_splat_i32438func.func @fold_greater_eq_splat_i32() -> (tensor<10xi1>, tensor<10xi1>) {439 %0 = "tosa.const"() {values = dense<-10> : tensor<10xi32>} : () -> tensor<10xi32>440 %1 = "tosa.const"() {values = dense<8> : tensor<10xi32>} : () -> tensor<10xi32>441 %2 = "tosa.const"() {values = dense<-10> : tensor<10xi32>} : () -> tensor<10xi32>442 %3 = "tosa.const"() {values = dense<-10> : tensor<10xi32>} : () -> tensor<10xi32>443 %true = tosa.greater_equal %2, %3 : (tensor<10xi32>, tensor<10xi32>) -> tensor<10xi1>444 %false = tosa.greater_equal %0, %1 : (tensor<10xi32>, tensor<10xi32>) -> tensor<10xi1>445 // CHECK-DAG: %[[TRUE:.+]] = "tosa.const"() <{values = dense<true> : tensor<10xi1>}446 // CHECK-DAG: %[[FALSE:.+]] = "tosa.const"() <{values = dense<false> : tensor<10xi1>}447 // CHECK: return %[[TRUE]], %[[FALSE]]448 return %true, %false : tensor<10xi1>, tensor<10xi1>449}450 451// -----452 453// CHECK-LABEL: @fold_eq_splat_f32454func.func @fold_eq_splat_f32() -> (tensor<10xi1>, tensor<10xi1>) {455 %0 = "tosa.const"() {values = dense<4.0> : tensor<10xf32>} : () -> tensor<10xf32>456 %1 = "tosa.const"() {values = dense<4.0> : tensor<10xf32>} : () -> tensor<10xf32>457 %2 = "tosa.const"() {values = dense<1.0> : tensor<10xf32>} : () -> tensor<10xf32>458 %3 = "tosa.const"() {values = dense<2.0> : tensor<10xf32>} : () -> tensor<10xf32>459 %true = tosa.equal %0, %1 : (tensor<10xf32>, tensor<10xf32>) -> tensor<10xi1>460 %false = tosa.equal %2, %3 : (tensor<10xf32>, tensor<10xf32>) -> tensor<10xi1>461 // CHECK-DAG: %[[TRUE:.+]] = "tosa.const"() <{values = dense<true> : tensor<10xi1>}462 // CHECK-DAG: %[[FALSE:.+]] = "tosa.const"() <{values = dense<false> : tensor<10xi1>}463 // CHECK: return %[[TRUE]], %[[FALSE]]464 return %true, %false : tensor<10xi1>, tensor<10xi1>465}466 467// -----468 469// CHECK-LABEL: @fold_eq_splat_i32470func.func @fold_eq_splat_i32() -> (tensor<10xi1>, tensor<10xi1>) {471 %0 = "tosa.const"() {values = dense<-10> : tensor<10xi32>} : () -> tensor<10xi32>472 %1 = "tosa.const"() {values = dense<8> : tensor<10xi32>} : () -> tensor<10xi32>473 %2 = "tosa.const"() {values = dense<-10> : tensor<10xi32>} : () -> tensor<10xi32>474 %3 = "tosa.const"() {values = dense<-10> : tensor<10xi32>} : () -> tensor<10xi32>475 %true = tosa.equal %2, %3 : (tensor<10xi32>, tensor<10xi32>) -> tensor<10xi1>476 %false = tosa.equal %0, %1 : (tensor<10xi32>, tensor<10xi32>) -> tensor<10xi1>477 // CHECK-DAG: %[[TRUE:.+]] = "tosa.const"() <{values = dense<true> : tensor<10xi1>}478 // CHECK-DAG: %[[FALSE:.+]] = "tosa.const"() <{values = dense<false> : tensor<10xi1>}479 // CHECK: return %[[TRUE]], %[[FALSE]]480 return %true, %false : tensor<10xi1>, tensor<10xi1>481}482 483// -----484 485// CHECK-LABEL: @fold_eq_i32486func.func @fold_eq_i32(%arg0 : tensor<10xi32>) -> (tensor<10xi1>) {487 // CHECK: %[[TRUE:.+]] = "tosa.const"() <{values = dense<true> : tensor<10xi1>}488 %0 = tosa.equal %arg0, %arg0 : (tensor<10xi32>, tensor<10xi32>) -> tensor<10xi1>489 // CHECK: return %[[TRUE]]490 return %0 : tensor<10xi1>491}492 493// -----494 495func.func @reshape_splat() -> tensor<6x5x4xi32> {496 // CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<42> : tensor<6x5x4xi32>}497 %splat = "tosa.const"() {values = dense<42> : tensor<4x5x6xi32>} : () -> tensor<4x5x6xi32>498 %const = tosa.const_shape {values = dense<[6, 5, 4]> : tensor<3xindex>} : () -> !tosa.shape<3>499 %reshape = tosa.reshape %splat, %const : (tensor<4x5x6xi32>, !tosa.shape<3>) -> tensor<6x5x4xi32>500 // CHECK: return %[[SPLAT]]501 return %reshape : tensor<6x5x4xi32>502}503 504// -----505 506// CHECK-LABEL: @slice_splat507func.func @slice_splat() -> tensor<1x1x1xi32> {508 // CHECK: %[[SLICE:.+]] = "tosa.const"() <{values = dense<42> : tensor<1x1x1xi32>}509 %splat = "tosa.const"() {values = dense<42> : tensor<4x5x6xi32>} : () -> tensor<4x5x6xi32>510 %start = tosa.const_shape {values = dense<[1, 2, 3]> : tensor<3xindex>} : () -> !tosa.shape<3>511 %size = tosa.const_shape {values = dense<[1, 1, 1]> : tensor<3xindex>} : () -> !tosa.shape<3>512 %slice= tosa.slice %splat, %start, %size : (tensor<4x5x6xi32>, !tosa.shape<3>, !tosa.shape<3>) -> tensor<1x1x1xi32>513 514 // CHECK: return %[[SLICE]]515 return %slice : tensor<1x1x1xi32>516}517 518// -----519 520// CHECK-LABEL: @slice_singleton521func.func @slice_singleton() -> tensor<1x1xi32> {522 %splat = "tosa.const"() {values = dense<[[0, 1, 2], [3, 4, 5], [6, 7 ,8]]> : tensor<3x3xi32>} : () -> tensor<3x3xi32>523 // CHECK: %[[SLICE:.+]] = "tosa.const"() <{values = dense<4> : tensor<1x1xi32>}524 %start = tosa.const_shape {values = dense<[1, 1]> : tensor<2xindex>} : () -> !tosa.shape<2>525 %size = tosa.const_shape {values = dense<[1, 1]> : tensor<2xindex>} : () -> !tosa.shape<2>526 %slice= tosa.slice %splat, %start, %size : (tensor<3x3xi32>, !tosa.shape<2>, !tosa.shape<2>) -> tensor<1x1xi32>527 // CHECK: return %[[SLICE]]528 return %slice : tensor<1x1xi32>529}530 531// -----532 533// CHECK: func.func @cast_float_to_float534func.func @cast_float_to_float() -> tensor<f16> {535 %splat = "tosa.const"() {values = dense<42.0> : tensor<f32>} : () -> tensor<f32>536 // CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<4.200000e+01> : tensor<f16>}537 %cast = tosa.cast %splat : (tensor<f32>) -> tensor<f16>538 // CHECK: return %[[SPLAT]]539 return %cast : tensor<f16>540}541 542// -----543 544// CHECK: func.func @cast_int_to_float545func.func @cast_int_to_float() -> tensor<f16> {546 %splat = "tosa.const"() {values = dense<4> : tensor<i32>} : () -> tensor<i32>547 // CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<4.000000e+00> : tensor<f16>}548 %cast = tosa.cast %splat : (tensor<i32>) -> tensor<f16>549 // CHECK: return %[[SPLAT]]550 return %cast : tensor<f16>551}552 553// -----554 555// CHECK: func.func @cast_float_to_int556func.func @cast_float_to_int() -> tensor<i16> {557 %splat = "tosa.const"() {values = dense<-4.0> : tensor<f32>} : () -> tensor<f32>558 // CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<-4> : tensor<i16>}559 %cast = tosa.cast %splat : (tensor<f32>) -> tensor<i16>560 // CHECK: return %[[SPLAT]]561 return %cast : tensor<i16>562}563 564// -----565 566// CHECK: func.func @cast_float_to_int_round567func.func @cast_float_to_int_round() -> tensor<i16> {568 %splat = "tosa.const"() {values = dense<-3.5> : tensor<f32>} : () -> tensor<f32>569 // CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<-4> : tensor<i16>}570 %cast = tosa.cast %splat : (tensor<f32>) -> tensor<i16>571 // CHECK: return %[[SPLAT]]572 return %cast : tensor<i16>573}574 575// -----576 577// CHECK: func.func @cast_int_to_int_trunc578func.func @cast_int_to_int_trunc() -> tensor<i16> {579 %splat = "tosa.const"() {values = dense<-1> : tensor<i32>} : () -> tensor<i32>580 // CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<-1> : tensor<i16>}581 %cast = tosa.cast %splat : (tensor<i32>) -> tensor<i16>582 // CHECK: return %[[SPLAT]]583 return %cast : tensor<i16>584}585 586// -----587 588// CHECK: func.func @cast_int_to_int_sign589func.func @cast_int_to_int_sign() -> tensor<i32> {590 %splat = "tosa.const"() {values = dense<-1> : tensor<i16>} : () -> tensor<i16>591 // CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<-1> : tensor<i32>}592 %cast = tosa.cast %splat : (tensor<i16>) -> tensor<i32>593 // CHECK: return %[[SPLAT]]594 return %cast : tensor<i32>595}596 597// -----598 599// CHECK-LABEL: @reverse_splat600func.func @reverse_splat() -> tensor<10xi32> {601 // CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<42> : tensor<10xi32>}602 %splat = "tosa.const"() {values = dense<42> : tensor<10xi32>} : () -> tensor<10xi32>603 %reverse = tosa.reverse %splat { axis = 0 : i32 } : (tensor<10xi32>) -> tensor<10xi32>604 // CHECK: return %[[SPLAT]]605 return %reverse : tensor<10xi32>606}607 608// -----609 610// CHECK-LABEL: @reverse_length_one611func.func @reverse_length_one(%arg0 : tensor<10x1xi32>) -> (tensor<10x1xi32>, tensor<10x1xi32>) {612 %nofold = tosa.reverse %arg0 { axis = 0 : i32 } : (tensor<10x1xi32>) -> tensor<10x1xi32>613 %fold = tosa.reverse %arg0 { axis = 1 : i32 } : (tensor<10x1xi32>) -> tensor<10x1xi32>614 // CHECK: %[[NOFOLD:.+]] = tosa.reverse %arg0 {axis = 0 : i32}615 // CHECK: return %[[NOFOLD]], %arg0616 return %nofold, %fold : tensor<10x1xi32>, tensor<10x1xi32>617}618 619// -----620 621 func.func @reduce_sum_constant() -> tensor<1x3xi32> {622 // CHECK-LABEL: func.func @reduce_sum_constant() -> tensor<1x3xi32> {623 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}5, 7, 9]]> : tensor<1x3xi32>}> : () -> tensor<1x3xi32>624 // CHECK: return %[[VAL_0]] : tensor<1x3xi32>625 626 %const = "tosa.const"() {values = dense<[[1,2,3], [4,5,6]]> : tensor<2x3xi32>} : () -> tensor<2x3xi32>627 %0 = tosa.reduce_sum %const {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32>628 return %0 : tensor<1x3xi32>629 }630 631// -----632 633 func.func @reduce_sum_constant() -> tensor<2x1xi32> {634 // CHECK-LABEL: func.func @reduce_sum_constant() -> tensor<2x1xi32> {635 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}6], [15]]> : tensor<2x1xi32>}> : () -> tensor<2x1xi32>636 // CHECK: return %[[VAL_0]] : tensor<2x1xi32>637 // CHECK: }638 %const = "tosa.const"() <{values = dense<[[1,2,3], [4,5,6]]> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>639 %0 = tosa.reduce_sum %const {axis = 1 : i32} : (tensor<2x3xi32>) -> tensor<2x1xi32>640 return %0 : tensor<2x1xi32>641 }642 643 644// -----645 646func.func @reduce_sum_constant() -> tensor<3x1xi32> {647 // CHECK-LABEL: func.func @reduce_sum_constant() -> tensor<3x1xi32> {648 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}6], [15], [24]]> : tensor<3x1xi32>}> : () -> tensor<3x1xi32>649 // CHECK: return %[[VAL_0]] : tensor<3x1xi32>650 // CHECK: }651 %const = "tosa.const"() <{values = dense<[[1, 2, 3], [4, 5, 6], [7, 8, 9]]> : tensor<3x3xi32>}> : () -> tensor<3x3xi32>652 %0 = tosa.reduce_sum %const {axis = 1 : i32} : (tensor<3x3xi32>) -> tensor<3x1xi32>653 return %0 : tensor<3x1xi32>654}655 656// -----657 658func.func @reduce_sum_constant() -> tensor<2x1x4xi32> {659 // CHECK-LABEL: func.func @reduce_sum_constant() -> tensor<2x1x4xi32> {660 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}[15, 18, 21, 24]], {{\[\[}}51, 54, 57, 60]]]> : tensor<2x1x4xi32>}> : () -> tensor<2x1x4xi32>661 // CHECK: return %[[VAL_0]] : tensor<2x1x4xi32>662 // CHECK: }663 %const = "tosa.const"() <{values = dense<[[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], [[13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]]]> : tensor<2x3x4xi32>}> : () -> tensor<2x3x4xi32>664 %0 = tosa.reduce_sum %const {axis = 1 : i32} : (tensor<2x3x4xi32>) -> tensor<2x1x4xi32>665 return %0 : tensor<2x1x4xi32>666}667 668// -----669 670func.func @reduce_sum_constant() -> tensor<1x3x3xi32> {671 // CHECK-LABEL: func.func @reduce_sum_constant() -> tensor<1x3x3xi32> {672 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}[30, 33, 36], [39, 42, 45], [48, 51, 54]]]> : tensor<1x3x3xi32>}> : () -> tensor<1x3x3xi32>673 // CHECK: return %[[VAL_0]] : tensor<1x3x3xi32>674 // CHECK: }675 %const = "tosa.const"() <{values = dense<[[[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[10, 11, 12], [13, 14, 15], [16, 17, 18]], [[19, 20, 21], [22, 23, 24], [25, 26, 27]]]> : tensor<3x3x3xi32>}> : () -> tensor<3x3x3xi32>676 %0 = tosa.reduce_sum %const {axis = 0 : i32} : (tensor<3x3x3xi32>) -> tensor<1x3x3xi32>677 return %0 : tensor<1x3x3xi32>678}679 680// -----681 682func.func @reduce_sum_constant() -> tensor<2x2x2x1xi32> {683 // CHECK-LABEL: func.func @reduce_sum_constant() -> tensor<2x2x2x1xi32> {684 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}{{\[\[}}3], [7]], {{\[\[}}11], [15]]], {{\[\[}}[19], [23]], {{\[\[}}27], [31]]]]> : tensor<2x2x2x1xi32>}> : () -> tensor<2x2x2x1xi32>685 // CHECK: return %[[VAL_0]] : tensor<2x2x2x1xi32>686 // CHECK: }687 %const = "tosa.const"() <{values = dense<[[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]]> : tensor<2x2x2x2xi32>}> : () -> tensor<2x2x2x2xi32>688 %0 = tosa.reduce_sum %const {axis = 3 : i32} : (tensor<2x2x2x2xi32>) -> tensor<2x2x2x1xi32>689 return %0 : tensor<2x2x2x1xi32>690}691 692// -----693 694func.func @reduce_sum_constant() -> tensor<1x1x1xi32> {695 // CHECK-LABEL: func.func @reduce_sum_constant() -> tensor<1x1x1xi32> {696 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<42> : tensor<1x1x1xi32>}> : () -> tensor<1x1x1xi32>697 // CHECK: return %[[VAL_0]] : tensor<1x1x1xi32>698 // CHECK: }699 %const = "tosa.const"() <{values = dense<[[[42]]]> : tensor<1x1x1xi32>}> : () -> tensor<1x1x1xi32>700 %0 = tosa.reduce_sum %const {axis = 0 : i32} : (tensor<1x1x1xi32>) -> tensor<1x1x1xi32>701 return %0 : tensor<1x1x1xi32>702}703 704// -----705 706func.func @reduce_sum_constant() -> tensor<2x3x1x5xi32> {707 // CHECK-LABEL: func.func @reduce_sum_constant() -> tensor<2x3x1x5xi32> {708 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}{{\[\[}}34, 38, 42, 46, 50]], {{\[\[}}114, 118, 122, 126, 130]], {{\[\[}}194, 198, 202, 206, 210]]], {{\[\[}}[274, 278, 282, 286, 290]], {{\[\[}}354, 358, 362, 366, 370]], {{\[\[}}434, 438, 442, 446, 450]]]]> : tensor<2x3x1x5xi32>}> : () -> tensor<2x3x1x5xi32>709 // CHECK: return %[[VAL_0]] : tensor<2x3x1x5xi32>710 // CHECK: }711 %const = "tosa.const"() <{values = dense<[[[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]], [[21, 22, 23, 24, 25], [26, 27, 28, 29, 30], [31, 32, 33, 34, 35], [36, 37, 38, 39, 40]], [[41, 42, 43, 44, 45], [46, 47, 48, 49, 50], [51, 52, 53, 54, 55], [56, 57, 58, 59, 60]]], [[[61, 62, 63, 64, 65], [66, 67, 68, 69, 70], [71, 72, 73, 74, 75], [76, 77, 78, 79, 80]], [[81, 82, 83, 84, 85], [86, 87, 88, 89, 90], [91, 92, 93, 94, 95], [96, 97, 98, 99, 100]], [[101, 102, 103, 104, 105], [106, 107, 108, 109, 110], [111, 112, 113, 114, 115], [116, 117, 118, 119, 120]]]]> : tensor<2x3x4x5xi32>}> : () -> tensor<2x3x4x5xi32>712 %0 = tosa.reduce_sum %const {axis = 2 : i32} : (tensor<2x3x4x5xi32>) -> tensor<2x3x1x5xi32>713 return %0 : tensor<2x3x1x5xi32>714}715 716// -----717 718 func.func @reduce_prod_constant() -> tensor<1x3xi32> {719 // CHECK-LABEL: func.func @reduce_prod_constant() -> tensor<1x3xi32> {720 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}4, 10, 18]]> : tensor<1x3xi32>}> : () -> tensor<1x3xi32>721 // CHECK: return %[[VAL_0]] : tensor<1x3xi32>722 723 %const = "tosa.const"() <{values = dense<[[1,2,3], [4,5,6]]> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>724 %0 = tosa.reduce_product %const {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32>725 return %0 : tensor<1x3xi32>726 }727 728// -----729 730 func.func @reduce_prod_constant() -> tensor<2x1xi32> {731 // CHECK-LABEL: func.func @reduce_prod_constant() -> tensor<2x1xi32> {732 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}6], [120]]> : tensor<2x1xi32>}> : () -> tensor<2x1xi32>733 // CHECK: return %[[VAL_0]] : tensor<2x1xi32>734 // CHECK: }735 736 %const = "tosa.const"() <{values = dense<[[1,2,3], [4,5,6]]> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>737 %0 = tosa.reduce_product %const {axis = 1 : i32} : (tensor<2x3xi32>) -> tensor<2x1xi32>738 return %0 : tensor<2x1xi32>739 }740 741// -----742 743func.func @reduce_prod_constant() -> tensor<3x1xi32> {744 // CHECK-LABEL: func.func @reduce_prod_constant() -> tensor<3x1xi32> {745 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}6], [120], [504]]> : tensor<3x1xi32>}> : () -> tensor<3x1xi32>746 // CHECK: return %[[VAL_0]] : tensor<3x1xi32>747 // CHECK: }748 %const = "tosa.const"() <{values = dense<[[1, 2, 3], [4, 5, 6], [7, 8, 9]]> : tensor<3x3xi32>}> : () -> tensor<3x3xi32>749 %0 = tosa.reduce_product %const {axis = 1 : i32} : (tensor<3x3xi32>) -> tensor<3x1xi32>750 return %0 : tensor<3x1xi32>751}752 753// -----754 755func.func @reduce_prod_constant() -> tensor<2x1x4xi32> {756 // CHECK-LABEL: func.func @reduce_prod_constant() -> tensor<2x1x4xi32> {757 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}[45, 120, 231, 384]], {{\[\[}}4641, 5544, 6555, 7680]]]> : tensor<2x1x4xi32>}> : () -> tensor<2x1x4xi32>758 // CHECK: return %[[VAL_0]] : tensor<2x1x4xi32>759 // CHECK: }760 %const = "tosa.const"() <{values = dense<[[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], [[13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]]]> : tensor<2x3x4xi32>}> : () -> tensor<2x3x4xi32>761 %0 = tosa.reduce_product %const {axis = 1 : i32} : (tensor<2x3x4xi32>) -> tensor<2x1x4xi32>762 return %0 : tensor<2x1x4xi32>763}764 765// -----766 767func.func @reduce_prod_constant() -> tensor<1x3x3xi32> {768 // CHECK-LABEL: func.func @reduce_prod_constant() -> tensor<1x3x3xi32> {769 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}[190, 440, 756], [1144, 1610, 2160], [2800, 3536, 4374]]]> : tensor<1x3x3xi32>}> : () -> tensor<1x3x3xi32>770 // CHECK: return %[[VAL_0]] : tensor<1x3x3xi32>771 // CHECK: }772 %const = "tosa.const"() <{values = dense<[[[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[10, 11, 12], [13, 14, 15], [16, 17, 18]], [[19, 20, 21], [22, 23, 24], [25, 26, 27]]]> : tensor<3x3x3xi32>}> : () -> tensor<3x3x3xi32>773 %0 = tosa.reduce_product %const {axis = 0 : i32} : (tensor<3x3x3xi32>) -> tensor<1x3x3xi32>774 return %0 : tensor<1x3x3xi32>775}776 777// -----778 779func.func @reduce_prod_constant() -> tensor<2x2x2x1xi32> {780 // CHECK-LABEL: func.func @reduce_prod_constant() -> tensor<2x2x2x1xi32> {781 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}{{\[\[}}2], [12]], {{\[\[}}30], [56]]], {{\[\[}}[90], [132]], {{\[\[}}182], [240]]]]> : tensor<2x2x2x1xi32>}> : () -> tensor<2x2x2x1xi32>782 // CHECK: return %[[VAL_0]] : tensor<2x2x2x1xi32>783 // CHECK: }784 %const = "tosa.const"() <{values = dense<[[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]]> : tensor<2x2x2x2xi32>}> : () -> tensor<2x2x2x2xi32>785 %0 = tosa.reduce_product %const {axis = 3 : i32} : (tensor<2x2x2x2xi32>) -> tensor<2x2x2x1xi32>786 return %0 : tensor<2x2x2x1xi32>787}788 789// -----790 791func.func @reduce_prod_constant() -> tensor<1x1x1xi32> {792 // CHECK-LABEL: func.func @reduce_prod_constant() -> tensor<1x1x1xi32> {793 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<42> : tensor<1x1x1xi32>}> : () -> tensor<1x1x1xi32>794 // CHECK: return %[[VAL_0]] : tensor<1x1x1xi32>795 // CHECK: }796 %const = "tosa.const"() <{values = dense<[[[42]]]> : tensor<1x1x1xi32>}> : () -> tensor<1x1x1xi32>797 %0 = tosa.reduce_product %const {axis = 0 : i32} : (tensor<1x1x1xi32>) -> tensor<1x1x1xi32>798 return %0 : tensor<1x1x1xi32>799}800 801// -----802 803 func.func @reduce_max_constant() -> tensor<1x3xi32> {804 // CHECK-LABEL: func.func @reduce_max_constant() -> tensor<1x3xi32> {805 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}4, 5, 6]]> : tensor<1x3xi32>}> : () -> tensor<1x3xi32>806 // CHECK: return %[[VAL_0]] : tensor<1x3xi32>807 808 %const = "tosa.const"() <{values = dense<[[1,2,3], [4,5,6]]> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>809 %0 = tosa.reduce_max %const {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32>810 return %0 : tensor<1x3xi32>811 }812 813// -----814 815 func.func @reduce_max_constant() -> tensor<2x1xi32> {816 // CHECK-LABEL: func.func @reduce_max_constant() -> tensor<2x1xi32> {817 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}3], [6]]> : tensor<2x1xi32>}> : () -> tensor<2x1xi32>818 // CHECK: return %[[VAL_0]] : tensor<2x1xi32>819 // CHECK: }820 821 %const = "tosa.const"() <{values = dense<[[1,2,3], [4,5,6]]> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>822 %0 = tosa.reduce_max %const {axis = 1 : i32} : (tensor<2x3xi32>) -> tensor<2x1xi32>823 return %0 : tensor<2x1xi32>824 }825 826// -----827 828func.func @reduce_max_constant() -> tensor<3x1xi32> {829 // CHECK-LABEL: func.func @reduce_max_constant() -> tensor<3x1xi32> {830 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}3], [6], [9]]> : tensor<3x1xi32>}> : () -> tensor<3x1xi32>831 // CHECK: return %[[VAL_0]] : tensor<3x1xi32>832 // CHECK: }833 %const = "tosa.const"() <{values = dense<[[1, 2, 3], [4, 5, 6], [7, 8, 9]]> : tensor<3x3xi32>}> : () -> tensor<3x3xi32>834 %0 = tosa.reduce_max %const {axis = 1 : i32} : (tensor<3x3xi32>) -> tensor<3x1xi32>835 return %0 : tensor<3x1xi32>836}837 838// -----839 840func.func @reduce_max_constant() -> tensor<2x1x4xi32> {841 // CHECK-LABEL: func.func @reduce_max_constant() -> tensor<2x1x4xi32> {842 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}[9, 10, 11, 12]], {{\[\[}}21, 22, 23, 24]]]> : tensor<2x1x4xi32>}> : () -> tensor<2x1x4xi32>843 // CHECK: return %[[VAL_0]] : tensor<2x1x4xi32>844 // CHECK: }845 %const = "tosa.const"() <{values = dense<[[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], [[13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]]]> : tensor<2x3x4xi32>}> : () -> tensor<2x3x4xi32>846 %0 = tosa.reduce_max %const {axis = 1 : i32} : (tensor<2x3x4xi32>) -> tensor<2x1x4xi32>847 return %0 : tensor<2x1x4xi32>848}849 850// -----851 852func.func @reduce_max_constant() -> tensor<1x3x3xi32> {853 // CHECK-LABEL: func.func @reduce_max_constant() -> tensor<1x3x3xi32> {854 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}[19, 20, 21], [22, 23, 24], [25, 26, 27]]]> : tensor<1x3x3xi32>}> : () -> tensor<1x3x3xi32>855 // CHECK: return %[[VAL_0]] : tensor<1x3x3xi32>856 // CHECK: }857 %const = "tosa.const"() <{values = dense<[[[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[10, 11, 12], [13, 14, 15], [16, 17, 18]], [[19, 20, 21], [22, 23, 24], [25, 26, 27]]]> : tensor<3x3x3xi32>}> : () -> tensor<3x3x3xi32>858 %0 = tosa.reduce_max %const {axis = 0 : i32} : (tensor<3x3x3xi32>) -> tensor<1x3x3xi32>859 return %0 : tensor<1x3x3xi32>860}861 862// -----863 864func.func @reduce_max_constant() -> tensor<2x2x2x1xi32> {865 // CHECK-LABEL: func.func @reduce_max_constant() -> tensor<2x2x2x1xi32> {866 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}{{\[\[}}2], [4]], {{\[\[}}6], [8]]], {{\[\[}}[10], [12]], {{\[\[}}14], [16]]]]> : tensor<2x2x2x1xi32>}> : () -> tensor<2x2x2x1xi32>867 // CHECK: return %[[VAL_0]] : tensor<2x2x2x1xi32>868 // CHECK: }869 %const = "tosa.const"() <{values = dense<[[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]]> : tensor<2x2x2x2xi32>}> : () -> tensor<2x2x2x2xi32>870 %0 = tosa.reduce_max %const {axis = 3 : i32} : (tensor<2x2x2x2xi32>) -> tensor<2x2x2x1xi32>871 return %0 : tensor<2x2x2x1xi32>872}873 874// -----875 876func.func @reduce_max_constant() -> tensor<1x1x1xi32> {877 // CHECK-LABEL: func.func @reduce_max_constant() -> tensor<1x1x1xi32> {878 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<42> : tensor<1x1x1xi32>}> : () -> tensor<1x1x1xi32>879 // CHECK: return %[[VAL_0]] : tensor<1x1x1xi32>880 // CHECK: }881 %const = "tosa.const"() <{values = dense<[[[42]]]> : tensor<1x1x1xi32>}> : () -> tensor<1x1x1xi32>882 %0 = tosa.reduce_max %const {axis = 0 : i32} : (tensor<1x1x1xi32>) -> tensor<1x1x1xi32>883 return %0 : tensor<1x1x1xi32>884}885 886// -----887 888func.func @reduce_max_constant_no_overflow() -> tensor<1xi8> {889 // CHECK-LABEL: func.func @reduce_max_constant_no_overflow() -> tensor<1xi8> {890 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<120> : tensor<1xi8>}> : () -> tensor<1xi8>891 // CHECK: return %[[VAL_0]] : tensor<1xi8>892 // CHECK: }893 %const = "tosa.const"() <{values = dense<[-127, 120, -126]> : tensor<3xi8>}> : () -> tensor<3xi8>894 %0 = tosa.reduce_max %const {axis = 0 : i32} : (tensor<3xi8>) -> tensor<1xi8>895 return %0 : tensor<1xi8>896}897 898// -----899 900 func.func @reduce_min_constant() -> tensor<1x3xi32> {901 // CHECK-LABEL: func.func @reduce_min_constant() -> tensor<1x3xi32> {902 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}1, 2, 3]]> : tensor<1x3xi32>}> : () -> tensor<1x3xi32>903 // CHECK: return %[[VAL_0]] : tensor<1x3xi32>904 %const = "tosa.const"() <{values = dense<[[1,2,3], [4,5,6]]> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>905 %0 = tosa.reduce_min %const {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32>906 return %0 : tensor<1x3xi32>907 }908 909 910// -----911 912 func.func @reduce_min_constant() -> tensor<2x1xi32> {913 // CHECK-LABEL: func.func @reduce_min_constant() -> tensor<2x1xi32> {914 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}1], [4]]> : tensor<2x1xi32>}> : () -> tensor<2x1xi32>915 // CHECK: return %[[VAL_0]] : tensor<2x1xi32>916 // CHECK: }917 918 %const = "tosa.const"() <{values = dense<[[1,2,3], [4,5,6]]> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>919 %0 = tosa.reduce_min %const {axis = 1 : i32} : (tensor<2x3xi32>) -> tensor<2x1xi32>920 return %0 : tensor<2x1xi32>921 }922 923// -----924 925func.func @reduce_min_constant() -> tensor<3x1xi32> {926 // CHECK-LABEL: func.func @reduce_min_constant() -> tensor<3x1xi32> {927 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}1], [4], [7]]> : tensor<3x1xi32>}> : () -> tensor<3x1xi32>928 // CHECK: return %[[VAL_0]] : tensor<3x1xi32>929 // CHECK: }930 %const = "tosa.const"() <{values = dense<[[1, 2, 3], [4, 5, 6], [7, 8, 9]]> : tensor<3x3xi32>}> : () -> tensor<3x3xi32>931 %0 = tosa.reduce_min %const {axis = 1 : i32} : (tensor<3x3xi32>) -> tensor<3x1xi32>932 return %0 : tensor<3x1xi32>933}934 935// -----936 937func.func @reduce_min_constant() -> tensor<2x1x4xi32> {938 // CHECK-LABEL: func.func @reduce_min_constant() -> tensor<2x1x4xi32> {939 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}[1, 2, 3, 4]], {{\[\[}}13, 14, 15, 16]]]> : tensor<2x1x4xi32>}> : () -> tensor<2x1x4xi32>940 // CHECK: return %[[VAL_0]] : tensor<2x1x4xi32>941 // CHECK: }942 %const = "tosa.const"() <{values = dense<[[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], [[13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]]]> : tensor<2x3x4xi32>}> : () -> tensor<2x3x4xi32>943 %0 = tosa.reduce_min %const {axis = 1 : i32} : (tensor<2x3x4xi32>) -> tensor<2x1x4xi32>944 return %0 : tensor<2x1x4xi32>945}946 947// -----948 949func.func @reduce_min_constant() -> tensor<1x3x3xi32> {950 // CHECK-LABEL: func.func @reduce_min_constant() -> tensor<1x3x3xi32> {951 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}[1, 2, 3], [4, 5, 6], [7, 8, 9]]]> : tensor<1x3x3xi32>}> : () -> tensor<1x3x3xi32>952 // CHECK: return %[[VAL_0]] : tensor<1x3x3xi32>953 // CHECK: }954 %const = "tosa.const"() <{values = dense<[[[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[10, 11, 12], [13, 14, 15], [16, 17, 18]], [[19, 20, 21], [22, 23, 24], [25, 26, 27]]]> : tensor<3x3x3xi32>}> : () -> tensor<3x3x3xi32>955 %0 = tosa.reduce_min %const {axis = 0 : i32} : (tensor<3x3x3xi32>) -> tensor<1x3x3xi32>956 return %0 : tensor<1x3x3xi32>957}958 959// -----960 961func.func @reduce_min_constant() -> tensor<2x2x2x1xi32> {962 // CHECK-LABEL: func.func @reduce_min_constant() -> tensor<2x2x2x1xi32> {963 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}{{\[\[}}1], [3]], {{\[\[}}5], [7]]], {{\[\[}}[9], [11]], {{\[\[}}13], [15]]]]> : tensor<2x2x2x1xi32>}> : () -> tensor<2x2x2x1xi32>964 // CHECK: return %[[VAL_0]] : tensor<2x2x2x1xi32>965 // CHECK: }966 %const = "tosa.const"() <{values = dense<[[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]]> : tensor<2x2x2x2xi32>}> : () -> tensor<2x2x2x2xi32>967 %0 = tosa.reduce_min %const {axis = 3 : i32} : (tensor<2x2x2x2xi32>) -> tensor<2x2x2x1xi32>968 return %0 : tensor<2x2x2x1xi32>969}970 971// -----972 973func.func @reduce_min_constant() -> tensor<1x1x1xi32> {974 // CHECK-LABEL: func.func @reduce_min_constant() -> tensor<1x1x1xi32> {975 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<42> : tensor<1x1x1xi32>}> : () -> tensor<1x1x1xi32>976 // CHECK: return %[[VAL_0]] : tensor<1x1x1xi32>977 // CHECK: }978 %const = "tosa.const"() <{values = dense<[[[42]]]> : tensor<1x1x1xi32>}> : () -> tensor<1x1x1xi32>979 %0 = tosa.reduce_min %const {axis = 0 : i32} : (tensor<1x1x1xi32>) -> tensor<1x1x1xi32>980 return %0 : tensor<1x1x1xi32>981}982 983// -----984 985func.func @reduce_min_constant_no_overflow() -> tensor<1xi8> {986 // CHECK-LABEL: func.func @reduce_min_constant_no_overflow() -> tensor<1xi8> {987 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<-127> : tensor<1xi8>}> : () -> tensor<1xi8>988 // CHECK: return %[[VAL_0]] : tensor<1xi8>989 // CHECK: }990 %const = "tosa.const"() <{values = dense<[-127, 120, -126]> : tensor<3xi8>}> : () -> tensor<3xi8>991 %0 = tosa.reduce_min %const {axis = 0 : i32} : (tensor<3xi8>) -> tensor<1xi8>992 return %0 : tensor<1xi8>993}994 995 996// -----997 998func.func @reduce_any_constant() -> tensor<1x3xi1> {999 // CHECK-LABEL: func.func @reduce_any_constant() -> tensor<1x3xi1> {1000 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<true> : tensor<1x3xi1>}> : () -> tensor<1x3xi1>1001 // CHECK: return %[[VAL_0]] : tensor<1x3xi1>1002 1003 %const = "tosa.const"() <{values = dense<[[true,true,true], [true,false,true]]> : tensor<2x3xi1>}> : () -> tensor<2x3xi1>1004 %0 = tosa.reduce_any %const {axis = 0 : i32} : (tensor<2x3xi1>) -> tensor<1x3xi1>1005 return %0 : tensor<1x3xi1>1006}1007 1008 1009// -----1010 1011func.func @reduce_any_constant() -> tensor<2x1xi1> {1012// CHECK-LABEL: func.func @reduce_any_constant() -> tensor<2x1xi1> {1013// CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<true> : tensor<2x1xi1>}> : () -> tensor<2x1xi1>1014// CHECK: return %[[VAL_0]] : tensor<2x1xi1>1015// CHECK: }1016 1017 %const = "tosa.const"() <{values = dense<[[true,true,true], [true,false,true]]> : tensor<2x3xi1>}> : () -> tensor<2x3xi1>1018 %0 = tosa.reduce_any %const {axis = 1 : i32} : (tensor<2x3xi1>) -> tensor<2x1xi1>1019 return %0 : tensor<2x1xi1>1020}1021 1022// -----1023 1024func.func @reduce_any_constant() -> tensor<3x1xi1> {1025 // CHECK-LABEL: func.func @reduce_any_constant() -> tensor<3x1xi1> {1026 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}true], [false], [true]]> : tensor<3x1xi1>}> : () -> tensor<3x1xi1>1027 // CHECK: return %[[VAL_0]] : tensor<3x1xi1>1028 // CHECK: }1029 %const = "tosa.const"() <{values = dense<[[true, false, false], [false, false, false], [false, false, true]]> : tensor<3x3xi1>}> : () -> tensor<3x3xi1>1030 %0 = tosa.reduce_any %const {axis = 1 : i32} : (tensor<3x3xi1>) -> tensor<3x1xi1>1031 return %0 : tensor<3x1xi1>1032}1033 1034// -----1035 1036func.func @reduce_any_constant() -> tensor<2x1x4xi1> {1037 // CHECK-LABEL: func.func @reduce_any_constant() -> tensor<2x1x4xi1> {1038 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}[true, false, true, true]], {{\[\[}}true, false, true, false]]]> : tensor<2x1x4xi1>}> : () -> tensor<2x1x4xi1>1039 // CHECK: return %[[VAL_0]] : tensor<2x1x4xi1>1040 // CHECK: }1041 %const = "tosa.const"() <{values = dense<[[[true, false, false, true], [false, false, true, false], [true, false, true, true]], [[false, false, false, false], [false, false, true, false], [true, false, true, false]]]> : tensor<2x3x4xi1>}> : () -> tensor<2x3x4xi1>1042 %0 = tosa.reduce_any %const {axis = 1 : i32} : (tensor<2x3x4xi1>) -> tensor<2x1x4xi1>1043 return %0 : tensor<2x1x4xi1>1044}1045 1046// -----1047 1048 func.func @reduce_all_constant() -> tensor<1x3xi1> {1049 // CHECK-LABEL: func.func @reduce_all_constant() -> tensor<1x3xi1> {1050 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}true, false, true]]> : tensor<1x3xi1>}> : () -> tensor<1x3xi1>1051 // CHECK: return %[[VAL_0]] : tensor<1x3xi1>1052 // CHECK: }1053 %const = "tosa.const"() <{values = dense<[[true,true,true], [true,false,true]]> : tensor<2x3xi1>}> : () -> tensor<2x3xi1>1054 %0 = tosa.reduce_all %const {axis = 0 : i32} : (tensor<2x3xi1>) -> tensor<1x3xi1>1055 return %0 : tensor<1x3xi1>1056 }1057 1058// -----1059 1060 func.func @reduce_all_constant() -> tensor<2x1xi1> {1061 // CHECK-LABEL: func.func @reduce_all_constant() -> tensor<2x1xi1> {1062 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}true], [false]]> : tensor<2x1xi1>}> : () -> tensor<2x1xi1>1063 // CHECK: return %[[VAL_0]] : tensor<2x1xi1>1064 // CHECK: }1065 %const = "tosa.const"() <{values = dense<[[true,true,true], [true,false,true]]> : tensor<2x3xi1>}> : () -> tensor<2x3xi1>1066 %0 = tosa.reduce_all %const {axis = 1 : i32} : (tensor<2x3xi1>) -> tensor<2x1xi1>1067 return %0 : tensor<2x1xi1>1068 }1069 1070// -----1071 1072func.func @reduce_all_constant() -> tensor<3x1xi1> {1073 // CHECK-LABEL: func.func @reduce_all_constant() -> tensor<3x1xi1> {1074 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<false> : tensor<3x1xi1>}> : () -> tensor<3x1xi1>1075 // CHECK: return %[[VAL_0]] : tensor<3x1xi1>1076 // CHECK: }1077 %const = "tosa.const"() <{values = dense<[[true, false, false], [false, false, false], [false, false, true]]> : tensor<3x3xi1>}> : () -> tensor<3x3xi1>1078 %0 = tosa.reduce_all %const {axis = 1 : i32} : (tensor<3x3xi1>) -> tensor<3x1xi1>1079 return %0 : tensor<3x1xi1>1080}1081 1082// -----1083 1084func.func @reduce_all_constant() -> tensor<2x1x4xi1> {1085 // CHECK-LABEL: func.func @reduce_all_constant() -> tensor<2x1x4xi1> {1086 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<false> : tensor<2x1x4xi1>}> : () -> tensor<2x1x4xi1>1087 // CHECK: return %[[VAL_0]] : tensor<2x1x4xi1>1088 // CHECK: }1089 %const = "tosa.const"() <{values = dense<[[[true, false, false, true], [false, false, true, false], [true, false, true, true]], [[false, false, false, false], [false, false, true, false], [true, false, true, false]]]> : tensor<2x3x4xi1>}> : () -> tensor<2x3x4xi1>1090 %0 = tosa.reduce_all %const {axis = 1 : i32} : (tensor<2x3x4xi1>) -> tensor<2x1x4xi1>1091 return %0 : tensor<2x1x4xi1>1092}1093 1094// -----1095 1096func.func @reduce_sum_constant() -> tensor<1x3xi32> {1097// CHECK-LABEL: func.func @reduce_sum_constant() -> tensor<1x3xi32> {1098// CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<2> : tensor<1x3xi32>}> : () -> tensor<1x3xi32>1099// CHECK: return %[[VAL_0]] : tensor<1x3xi32>1100// CHECK: }1101 %const = "tosa.const"() <{values = dense<1> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>1102 %0 = tosa.reduce_sum %const {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32>1103 return %0 : tensor<1x3xi32>1104}1105 1106// -----1107 1108func.func @reduce_sum_constant() -> tensor<1x3xi32> {1109 // CHECK-LABEL: func.func @reduce_sum_constant() -> tensor<1x3xi32> {1110 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<{{\[\[}}1, 2, 3], [4, 5, 6]]> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>1111 // CHECK: %[[VAL_1:.*]] = "tosa.const"() <{values = dense<{{\[\[}}1, 2, 3], [4, 5, 7]]> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>1112 // CHECK: %[[VAL_2:.*]] = tosa.add %[[VAL_0]], %[[VAL_1]] : (tensor<2x3xi32>, tensor<2x3xi32>) -> tensor<2x3xi32>1113 // CHECK: %[[VAL_3:.*]] = tosa.reduce_sum %[[VAL_2]] {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32>1114 // CHECK: return %[[VAL_3]] : tensor<1x3xi32>1115 %arg0 = "tosa.const"() <{values = dense<[[1,2,3], [4,5,6]]> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>1116 %arg1 = "tosa.const"() <{values = dense<[[1,2,3], [4,5,7]]> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>1117 %arg2 = tosa.add %arg0, %arg1 : (tensor<2x3xi32>, tensor<2x3xi32>) -> tensor<2x3xi32>1118 %0 = tosa.reduce_sum %arg2 {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32>1119 return %0 : tensor<1x3xi32>1120}1121 1122// -----1123 1124func.func @reduce_sum_constant_aggressive() -> tensor<1x3xi32> {1125 // AGGRESIVE-LABEL: func.func @reduce_sum_constant_aggressive() -> tensor<1x3xi32> {1126 // AGGRESIVE: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<4> : tensor<1x3xi32>}> : () -> tensor<1x3xi32>1127 // AGGRESIVE: return %[[VAL_0:.*]] : tensor<1x3xi32>1128 1129 // CHECK-LABEL: func.func @reduce_sum_constant_aggressive() -> tensor<1x3xi32> {1130 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<1> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>1131 // CHECK: %[[VAL_1:.*]] = tosa.reduce_sum %[[VAL_0]] {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32>1132 // CHECK: %[[VAL_2:.*]] = tosa.reduce_sum %[[VAL_0]] {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32>1133 // CHECK: %[[VAL_3:.*]] = tosa.add %[[VAL_1]], %[[VAL_2]] : (tensor<1x3xi32>, tensor<1x3xi32>) -> tensor<1x3xi32>1134 // CHECK: return %[[VAL_3]] : tensor<1x3xi32>1135 1136 %const = "tosa.const"() {values = dense<1> : tensor<2x3xi32>} : () -> tensor<2x3xi32>1137 %0 = tosa.reduce_sum %const {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32>1138 %1 = tosa.reduce_sum %const {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32>1139 %res = tosa.add %0, %1 : (tensor<1x3xi32>, tensor<1x3xi32>) -> tensor<1x3xi32>1140 return %res : tensor<1x3xi32>1141}1142 1143// -----1144 1145func.func @reduce_sum_constant_aggressive() -> tensor<2x3xi32> {1146 // AGGRESIVE-LABEL: func.func @reduce_sum_constant_aggressive() -> tensor<2x3xi32> {1147 // AGGRESIVE-DAG: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<2> : tensor<1x2x3xi32>}> : () -> tensor<1x2x3xi32>1148 // AGGRESIVE-DAG: %[[VAL_1:.*]] = "tosa.const"() <{values = dense<1> : tensor<2x2x3xi32>}> : () -> tensor<2x2x3xi32>1149 // AGGRESIVE-DAG: %[[VAL_2:.*]] = "tosa.const"() <{values = dense<2> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>1150 // AGGRESIVE: %[[VAL_3:.*]] = tosa.argmax %[[VAL_0]] {axis = 1 : i32} : (tensor<1x2x3xi32>) -> tensor<1x3xi32>1151 // AGGRESIVE: %[[VAL_4:.*]] = tosa.argmax %[[VAL_1]] {axis = 0 : i32} : (tensor<2x2x3xi32>) -> tensor<2x3xi32>1152 // AGGRESIVE: %[[VAL_5:.*]] = tosa.add %[[VAL_3]], %[[VAL_2]] : (tensor<1x3xi32>, tensor<2x3xi32>) -> tensor<2x3xi32>1153 // AGGRESIVE: %[[VAL_6:.*]] = tosa.add %[[VAL_5]], %[[VAL_4]] : (tensor<2x3xi32>, tensor<2x3xi32>) -> tensor<2x3xi32>1154 // AGGRESIVE: return %[[VAL_6]] : tensor<2x3xi32>1155 1156 // CHECK-LABEL: func.func @reduce_sum_constant_aggressive() -> tensor<2x3xi32> {1157 // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<1> : tensor<2x2x3xi32>}> : () -> tensor<2x2x3xi32>1158 // CHECK: %[[VAL_1:.*]] = "tosa.const"() <{values = dense<2> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>1159 // CHECK: %[[VAL_2:.*]] = tosa.reduce_sum %[[VAL_0]] {axis = 0 : i32} : (tensor<2x2x3xi32>) -> tensor<1x2x3xi32>1160 // CHECK: %[[VAL_3:.*]] = tosa.argmax %[[VAL_2]] {axis = 1 : i32} : (tensor<1x2x3xi32>) -> tensor<1x3xi32>1161 // CHECK: %[[VAL_4:.*]] = tosa.argmax %[[VAL_0]] {axis = 0 : i32} : (tensor<2x2x3xi32>) -> tensor<2x3xi32>1162 // CHECK: %[[VAL_5:.*]] = tosa.add %[[VAL_3]], %[[VAL_1]] : (tensor<1x3xi32>, tensor<2x3xi32>) -> tensor<2x3xi32>1163 // CHECK: %[[VAL_6:.*]] = tosa.add %[[VAL_5]], %[[VAL_4]] : (tensor<2x3xi32>, tensor<2x3xi32>) -> tensor<2x3xi32>1164 // CHECK: return %[[VAL_6]] : tensor<2x3xi32>1165 1166 %const0 = "tosa.const"() {values = dense<1> : tensor<2x2x3xi32>} : () -> tensor<2x2x3xi32>1167 %const1 = "tosa.const"() {values = dense<2> : tensor<2x3xi32>} : () -> tensor<2x3xi32>1168 %reduce0 = tosa.reduce_sum %const0 {axis = 0 : i32} : (tensor<2x2x3xi32>) -> tensor<1x2x3xi32>1169 %argmax0 = tosa.argmax %reduce0 {axis = 1 : i32} : (tensor<1x2x3xi32>) -> tensor<1x3xi32>1170 %argmax1 = tosa.argmax %const0 {axis = 0 : i32} : (tensor<2x2x3xi32>) -> tensor<2x3xi32>1171 %res0 = tosa.add %argmax0, %const1 : (tensor<1x3xi32>, tensor<2x3xi32>) -> tensor<2x3xi32>1172 %res1 = tosa.add %res0, %argmax1 : (tensor<2x3xi32>, tensor<2x3xi32>) -> tensor<2x3xi32>1173 return %res1 : tensor<2x3xi32>1174}1175 1176// -----1177 1178// no_shift_op_reorder checks that %arg1 won't be reorder with %01179// by the folder pass.1180// CHECK-LABEL: @no_shift_op_reorder1181func.func @no_shift_op_reorder (%arg0 : tensor<44x1xi16>, %arg1 : tensor<1xi8>) -> tensor<44x57xi32> {1182 %0 = "tosa.const"() {values = dense<1> : tensor<44x57xi16>} : () -> tensor<44x57xi16>1183 // CHECK: tosa.mul %arg0, %0, %arg11184 %1 = tosa.mul %arg0, %0, %arg1 : (tensor<44x1xi16>, tensor<44x57xi16>, tensor<1xi8>) -> tensor<44x57xi32>1185 return %1 : tensor<44x57xi32>1186}1187