From 63a7ed55acf60d144279ccf6849b373ef24d3a96 Mon Sep 17 00:00:00 2001 From: Tina Jung Date: Wed, 29 Mar 2023 09:32:52 +0100 Subject: [PATCH] Add over-/underflow tests for reciprocal folding Test that cases described in the general section [0] are also folded properly. [0] https://www.mlplatform.org/tosa/tosa_spec.html#_main_inference_profile --- .../Dialect/Tosa/constant-reciproc-opt.mlir | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mlir/test/Dialect/Tosa/constant-reciproc-opt.mlir b/mlir/test/Dialect/Tosa/constant-reciproc-opt.mlir index 7ad2bcb90b31b02..cc71c43d53ce29b 100644 --- a/mlir/test/Dialect/Tosa/constant-reciproc-opt.mlir +++ b/mlir/test/Dialect/Tosa/constant-reciproc-opt.mlir @@ -73,6 +73,26 @@ func.func @reciprocal_div_neg_infinity() -> tensor { return %1 : tensor } +// CHECK-LABEL: @reciprocal_div_underflow +func.func @reciprocal_div_underflow() -> tensor<2xf16> { + // CHECK: [[RES:]] ={{.*}}tosa.const{{.*}}-0.{{0*}}e+00, 0.{{0*}}e+00 + // CHECK-NOT: tosa.reciprocal + // CHECK: return [[RES]] + %0 = "tosa.const"() {value = dense<[-6.0e+15, 6.0e+15]> : tensor<2xf16>} : () -> tensor<2xf16> + %1 = "tosa.reciprocal"(%0) : (tensor<2xf16>) -> tensor<2xf16> + return %1 : tensor<2xf16> +} + +// CHECK-LABEL: @reciprocal_div_overflow +func.func @reciprocal_div_overflow() -> tensor<2xf16> { + // CHECK: [[RES:]] ={{.*}}tosa.const{{.*}}0x7C00, 0xFC00 + // CHECK-NOT: tosa.reciprocal + // CHECK: return [[RES]] + %0 = "tosa.const"() {value = dense<[0.0000001, -0.0000001]> : tensor<2xf16>} : () -> tensor<2xf16> + %1 = "tosa.reciprocal"(%0) : (tensor<2xf16>) -> tensor<2xf16> + return %1 : tensor<2xf16> +} + // CHECK-LABEL: @reciprocal_no_fold // The folding optimization works only intra-procedurally, so we won't be able // to fold anything here