From bf32bb7e056c9174cf1cf1a4bf78a339494aed95 Mon Sep 17 00:00:00 2001 From: Eugene Zhulenev Date: Mon, 18 Oct 2021 09:06:09 -0700 Subject: [PATCH] [mlir] Update approximation range for Tanh operation Use wider range for approximating Tanh to match results computed in Eigen with AVX. Reviewed By: cota Differential Revision: https://reviews.llvm.org/D112011 --- mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp | 4 ++-- mlir/test/Dialect/Math/polynomial-approximation.mlir | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp b/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp index 94442dd..29fd0b6 100644 --- a/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp +++ b/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp @@ -209,8 +209,8 @@ TanhApproximation::matchAndRewrite(math::TanhOp op, }; // Clamp operand into [plusClamp, minusClamp] range. - Value minusClamp = bcast(f32Cst(builder, -7.9053111076354980f)); - Value plusClamp = bcast(f32Cst(builder, 7.90531110763549805f)); + Value minusClamp = bcast(f32Cst(builder, -7.99881172180175781f)); + Value plusClamp = bcast(f32Cst(builder, 7.99881172180175781f)); Value x = clamp(builder, op.operand(), minusClamp, plusClamp); // Mask for tiny values that are approximated with `operand`. diff --git a/mlir/test/Dialect/Math/polynomial-approximation.mlir b/mlir/test/Dialect/Math/polynomial-approximation.mlir index 3ffc108..7d9ec88 100644 --- a/mlir/test/Dialect/Math/polynomial-approximation.mlir +++ b/mlir/test/Dialect/Math/polynomial-approximation.mlir @@ -248,8 +248,8 @@ func @log1p_vector(%arg0: vector<8xf32>) -> vector<8xf32> { // CHECK-LABEL: func @tanh_scalar( // CHECK-SAME: %[[VAL_0:.*]]: f32) -> f32 { -// CHECK: %[[VAL_1:.*]] = arith.constant -7.90531111 : f32 -// CHECK: %[[VAL_2:.*]] = arith.constant 7.90531111 : f32 +// CHECK: %[[VAL_1:.*]] = arith.constant -7.99881172 : f32 +// CHECK: %[[VAL_2:.*]] = arith.constant 7.99881172 : f32 // CHECK: %[[VAL_3:.*]] = arith.constant 4.000000e-04 : f32 // CHECK: %[[VAL_4:.*]] = arith.constant 0.00489352457 : f32 // CHECK: %[[VAL_5:.*]] = arith.constant 6.37261954E-4 : f32 @@ -290,7 +290,7 @@ func @tanh_scalar(%arg0: f32) -> f32 { // CHECK-LABEL: func @tanh_vector( // CHECK-SAME: %[[VAL_0:.*]]: vector<8xf32>) -> vector<8xf32> { -// CHECK: %[[VAL_1:.*]] = arith.constant dense<-7.90531111> : vector<8xf32> +// CHECK: %[[VAL_1:.*]] = arith.constant dense<-7.99881172> : vector<8xf32> // CHECK-NOT: tanh // CHECK-COUNT-2: select // CHECK: %[[VAL_33:.*]] = select -- 2.7.4