This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH]: Remove special case for log(e) -> 1


Prior to the MPFR integration, GCC had a bunch of code to handle
special-case values for various math functions, e.g. sin(0), atan(1),
exp(0), etc.

I removed most of them once MPFR was available to solve every case.
However one got left behind, it was for solving log(e) -> 1.  This case
was protected by -ffast-math because at low precision (i.e. float) logf(e)
actually should resolve to 0.9999... due to truncation of 'e'.  (The
higher precisions (double, long double) did actually return exactly 1).
Removing this bit of code can be considered a bugfix since it increases
the accuracy of the result.

In doing so, there were a couple of tests that assumed all precisions of
log{,f,l} functions resolved to exactly 1 and had to be removed.

Tested on mainline and 4.3 branch on x86_64-unknown-linux-gnu, no
regressions.  (The 4.3 version is slightly different because "dconste" was
renamed to "dconst_e()", but is otherwise the same).

Okay for mainline and 4.3?

		Thanks,
		--Kaveh


2008-12-22  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* builtins.c (real_dconstp): Delete.
	(fold_builtin_logarithm): Remove inaccurate log(e) special case.

testsuite:
	* gcc.dg/torture/builtin-explog-1.c: Remove tests that aren't true
	for low precision (i.e. float).

diff -rup orig/egcc-SVN20081222/gcc/builtins.c egcc-SVN20081222/gcc/builtins.c
--- orig/egcc-SVN20081222/gcc/builtins.c	2008-12-20 02:00:08.000000000 +0100
+++ egcc-SVN20081222/gcc/builtins.c	2008-12-22 16:18:37.000000000 +0100
@@ -8311,21 +8311,6 @@ fold_builtin_bswap (tree fndecl, tree ar
   return NULL_TREE;
 }

-/* Return true if EXPR is the real constant contained in VALUE.  */
-
-static bool
-real_dconstp (tree expr, const REAL_VALUE_TYPE *value)
-{
-  STRIP_NOPS (expr);
-
-  return ((TREE_CODE (expr) == REAL_CST
-	   && !TREE_OVERFLOW (expr)
-	   && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), *value))
-	  || (TREE_CODE (expr) == COMPLEX_CST
-	      && real_dconstp (TREE_REALPART (expr), value)
-	      && real_zerop (TREE_IMAGPART (expr))));
-}
-
 /* A subroutine of fold_builtin to fold the various logarithmic
    functions.  Return NULL_TREE if no simplification can me made.
    FUNC is the corresponding MPFR logarithm function.  */
@@ -8340,17 +8325,6 @@ fold_builtin_logarithm (tree fndecl, tre
       tree res;
       const enum built_in_function fcode = builtin_mathfn_code (arg);

-      /* Optimize log(e) = 1.0.  We're never passed an exact 'e',
-	 instead we'll look for 'e' truncated to MODE.  So only do
-	 this if flag_unsafe_math_optimizations is set.  */
-      if (flag_unsafe_math_optimizations && func == mpfr_log)
-        {
-	  const REAL_VALUE_TYPE e_truncated =
-	    real_value_truncate (TYPE_MODE (type), dconst_e ());
-	  if (real_dconstp (arg, &e_truncated))
-	    return build_real (type, dconst1);
-	}
-
       /* Calculate the result when the argument is a constant.  */
       if ((res = do_mpfr_arg1 (arg, type, func, &dconst0, NULL, false)))
 	return res;
diff -rup orig/egcc-SVN20081222/gcc/testsuite/gcc.dg/torture/builtin-explog-1.c egcc-SVN20081222/gcc/testsuite/gcc.dg/torture/builtin-explog-1.c
--- orig/egcc-SVN20081222/gcc/testsuite/gcc.dg/torture/builtin-explog-1.c	2008-03-14 00:39:11.000000000 +0100
+++ egcc-SVN20081222/gcc/testsuite/gcc.dg/torture/builtin-explog-1.c	2008-12-22 17:03:01.000000000 +0100
@@ -53,7 +53,6 @@ void test(double d1, double d2, float f1
  if (LOG(BASE) != 1.0 || LOG##f(BASE##F) != 1.0F || LOG##l(BASE##L) != 1.0L) \
     link_failure_##LOG##_N()

-  LOG_N(log, M_E);
   LOG_N(log2, 2.0);
   LOG_N(log10, 10.0);

@@ -74,7 +73,6 @@ void test(double d1, double d2, float f1
  if (LOG(EXP(d1)) != d1*LOG(BASE) || LOG##f(EXP##f(f1)) != f1*LOG##f(BASE##F) \
   || LOG##l(EXP##l(ld1)) != ld1*LOG##l(BASE##L)) link_failure_##LOG##_##EXP()

-  LOGEXP(log,exp,M_E);
   LOGEXP(log,exp2,2.0);
   LOGEXP(log,exp10,10.0);
   LOGEXP(log,pow10,10.0);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]