101 lines · plain
1// RUN: mlir-opt %s --tosa-arith-const-to-tosa-const --split-input-file | FileCheck %s2 3// CHECK-LABEL: func.func @rewrite_f32_tensor4// CHECK: %[[CST:.*]] = "tosa.const"() <{values = dense<[1.000000e+00, 2.000000e+00]> : tensor<2xf32>}> : () -> tensor<2xf32>5// CHECK: return %[[CST]]6func.func @rewrite_f32_tensor() -> tensor<2xf32> {7 %c = arith.constant dense<[1.000000e+00, 2.000000e+00]> : tensor<2xf32>8 return %c : tensor<2xf32>9}10 11// -----12 13// CHECK-LABEL: func.func @rewrite_i32_tensor14// CHECK: %[[CST:.*]] = "tosa.const"() <{values = dense<[1, 0, -1]> : tensor<3xi32>}> : () -> tensor<3xi32>15// CHECK: return %[[CST]]16func.func @rewrite_i32_tensor() -> tensor<3xi32> {17 %c = arith.constant dense<[1, 0, -1]> : tensor<3xi32>18 return %c : tensor<3xi32>19}20 21// -----22 23// CHECK-LABEL: func.func @rewrite_i1_tensor24// CHECK: %[[CST:.*]] = "tosa.const"() <{values = dense<[true, false]> : tensor<2xi1>}> : () -> tensor<2xi1>25func.func @rewrite_i1_tensor() -> tensor<2xi1> {26 %c = arith.constant dense<[true, false]> : tensor<2xi1>27 return %c : tensor<2xi1>28}29 30// -----31 32// CHECK-LABEL: func.func @rewrite_rank0_tensor33// CHECK: %[[CST:.*]] = "tosa.const"() <{values = dense<1.234500e+00> : tensor<f32>}> : () -> tensor<f32>34func.func @rewrite_rank0_tensor() -> tensor<f32> {35 %c = arith.constant dense<1.234500e+00> : tensor<f32>36 return %c : tensor<f32>37}38 39// -----40 41// CHECK-LABEL: func.func @preserve_scalar_i3242// CHECK: %[[CST:.*]] = arith.constant 42 : i3243func.func @preserve_scalar_i32() -> i32 {44 %c = arith.constant 42 : i3245 return %c : i3246}47 48// -----49 50// CHECK-LABEL: func.func @preserve_index_tensor51// CHECK: %[[CST:.*]] = arith.constant dense<[0, 1]> : tensor<2xindex>52func.func @preserve_index_tensor() -> tensor<2xindex> {53 %c = arith.constant dense<[0, 1]> : tensor<2xindex>54 return %c : tensor<2xindex>55}56 57// -----58 59// CHECK-LABEL: func.func @rewrite_resource_tensor60// CHECK: %[[CST:.*]] = "tosa.const"() <{values = dense_resource<blob1> : tensor<4xf32>}> : () -> tensor<4xf32>61func.func @rewrite_resource_tensor() -> tensor<4xf32> {62 %c = arith.constant dense_resource<"blob1"> : tensor<4xf32>63 return %c : tensor<4xf32>64}65 66// -----67 68// CHECK-LABEL: func.func @rewrite_quant_tensor69// CHECK: %[[CST:.*]] = "tosa.const"() <{values = dense<[10, 20]> : tensor<2xui8>}> : () -> tensor<2xui8>70func.func @rewrite_quant_tensor() -> tensor<2xui8> {71 %c = arith.constant dense<[10, 20]> : tensor<2xui8>72 return %c : tensor<2xui8>73}74 75// -----76 77// CHECK-LABEL: func.func @rewrite_quant_uniform_tensor78// CHECK: %[[CST:.*]] = "tosa.const"() <{values = dense<["10", "20"]> : tensor<2x!quant.uniform<i8:f32, 5.000000e-01>>}> : () -> tensor<2x!quant.uniform<i8:f32, 5.000000e-01>>79func.func @rewrite_quant_uniform_tensor() -> tensor<2x!quant.uniform<i8:f32, 0.5:0>> {80 %c = arith.constant dense<["10", "20"]> : tensor<2x!quant.uniform<i8:f32, 0.5:0>>81 return %c : tensor<2x!quant.uniform<i8:f32, 0.5:0>>82}83 84// -----85 86// CHECK-LABEL: func.func @rewrite_fp8_tensor87// CHECK: %[[CST:.*]] = "tosa.const"() <{values = dense<[1.000000e+00, -5.000000e-01]> : tensor<2xf8E4M3FN>}> : () -> tensor<2xf8E4M3FN>88func.func @rewrite_fp8_tensor() -> tensor<2xf8E4M3FN> {89 %c = arith.constant dense<[1.0, -0.5]> : tensor<2xf8E4M3FN>90 return %c : tensor<2xf8E4M3FN>91}92 93// -----94 95// CHECK-LABEL: func.func @rewrite_mxint8_tensor96// CHECK: %[[CST:.*]] = "tosa.const"() <{values = dense<["0x00", "0x7F"]> : tensor<2x!tosa.mxint8>}> : () -> tensor<2x!tosa.mxint8>97func.func @rewrite_mxint8_tensor() -> tensor<2x!tosa.mxint8> {98 %c = arith.constant dense<["0x00", "0x7F"]> : tensor<2x!tosa.mxint8>99 return %c : tensor<2x!tosa.mxint8>100}101