[Mlir-commits] [mlir] bf32bb7 - [mlir] Update approximation range for Tanh operation
Eugene Zhulenev
llvmlistbot at llvm.org
Mon Oct 18 10:57:40 PDT 2021
Author: Eugene Zhulenev
Date: 2021-10-18T10:57:31-07:00
New Revision: bf32bb7e056c9174cf1cf1a4bf78a339494aed95
URL: https://github.com/llvm/llvm-project/commit/bf32bb7e056c9174cf1cf1a4bf78a339494aed95
DIFF: https://github.com/llvm/llvm-project/commit/bf32bb7e056c9174cf1cf1a4bf78a339494aed95.diff
LOG: [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
Added:
Modified:
mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
mlir/test/Dialect/Math/polynomial-approximation.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp b/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
index 94442dd605415..29fd0b6cda3ab 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 3ffc108534506..7d9ec8832acf1 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
More information about the Mlir-commits
mailing list