[Mlir-commits] [mlir] [mlir][tosa] Add F32 to F16 type narrowing pass (PR #218900)
Luke Hutton
llvmlistbot at llvm.org
Tue Sep 1 07:57:58 PDT 2026
================
@@ -0,0 +1,200 @@
+// RUN: mlir-opt -split-input-file -verify-diagnostics -tosa-narrow-f32-to-f16="convert-function-boundaries=0" %s | FileCheck %s --allow-unused-prefixes --check-prefixes=COMMON,DEFAULT
+// RUN: mlir-opt -split-input-file -verify-diagnostics -tosa-narrow-f32-to-f16="convert-function-boundaries=1" %s | FileCheck %s --allow-unused-prefixes --check-prefixes=COMMON,FUNCBOUND
+
+// -----
+
+// CHECK-LABEL: test_f32_identity_chain
+func.func @test_f32_identity_chain(%arg0: tensor<1xf32>) -> tensor<1xf32> {
+ // DEFAULT: %[[CAST_IN:.*]] = tosa.cast %arg0 : (tensor<1xf32>) -> tensor<1xf16>
+ // DEFAULT: %[[ID1:.*]] = tosa.identity %[[CAST_IN]] : (tensor<1xf16>) -> tensor<1xf16>
+ // FUNCBOUND: %[[ID1:.*]] = tosa.identity %arg0 : (tensor<1xf16>) -> tensor<1xf16>
+ %0 = tosa.identity %arg0 : (tensor<1xf32>) -> tensor<1xf32>
+ // COMMON: %[[ID2:.*]] = tosa.identity %[[ID1]] : (tensor<1xf16>) -> tensor<1xf16>
+ %1 = tosa.identity %0 : (tensor<1xf32>) -> tensor<1xf32>
+ // DEFAULT: %[[CAST_OUT:.*]] = tosa.cast %[[ID2]] : (tensor<1xf16>) -> tensor<1xf32>
+ // DEFAULT: return %[[CAST_OUT]] : tensor<1xf32>
+ // FUNCBOUND: return %[[ID2]] : tensor<1xf16>
+ return %1 : tensor<1xf32>
+}
+
+// -----
+
+// CHECK-LABEL: test_f32_const
+func.func @test_f32_const() -> tensor<2xf32> {
+ // COMMON: %[[CONST:.*]] = "tosa.const"() <{values = dense<[1.000000e+00, 2.000000e+00]> : tensor<2xf16>}> : () -> tensor<2xf16>
+ %0 = "tosa.const"() <{values = dense<[1.000000e+00, 2.000000e+00]> : tensor<2xf32>}> : () -> tensor<2xf32>
----------------
lhutton1 wrote:
It would be good to test negative values as well
https://github.com/llvm/llvm-project/pull/218900
More information about the Mlir-commits
mailing list