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]

Re: Reduce startup cost of compiler (patch 1)


On Mon, 23 Jul 2007, Jan Hubicka wrote:

> Hi,
> it seems to help. do_add is still relatively high, but it is not too
> critical at least until optabs are tracked down.

Sorry the impact isn't highest.  I'm most familiar with that area, so I
contribute where I am able. :-)


> My little benchmark works now at 1.24s user, 2.35s real now.
> The patch seems to break later in bootstrap, but I am sure you can solve
> that ;)

Oops, got nailed by -Werror for an unused function.  I *did* says it was
untested...  :-)

This version passes bootstrap on sparc-sun-solaris2.10, no regressions.
Ok for mainline?

		Thanks,
		--Kaveh


2007-07-24  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* builtins.c (mathfn_built_in_1): Split out from mathfn_built_in
	and accept a new arg "implicit".
	(mathfn_built_in): Call mathfn_built_in_1 with implicit=true.
	(fold_builtin_cabs): Don't use dconstsqrt2.
	(real_dconstp): Delete.
	(fold_builtin_logarithm): Don't use dconste.
	(fold_builtin_hypot): Don't use dconstsqrt2.
	* emit-rtl.c (dconstsqrt2, dconste): Delete.
	(init_emit_once): Don't initialize dconstsqrt2 or dconste.
	* real.h (dconstsqrt2, dconste): Delete.

diff -rup orig/egcc-SVN20070721/gcc/builtins.c egcc-SVN20070721/gcc/builtins.c
--- orig/egcc-SVN20070721/gcc/builtins.c	2007-07-21 18:17:01.000000000 -0400
+++ egcc-SVN20070721/gcc/builtins.c	2007-07-24 03:07:35.449537339 -0400
@@ -1657,11 +1657,17 @@ expand_builtin_classify_type (tree exp)
   fcodel = BUILT_IN_MATHFN##L_R ; break;

 /* Return mathematic function equivalent to FN but operating directly
-   on TYPE, if available.  If we can't do the conversion, return zero.  */
-tree
-mathfn_built_in (tree type, enum built_in_function fn)
+   on TYPE, if available.  If we can't do the conversion, return zero.
+   The IMPLCIT parameter specifies whether we look in the implicit
+   decl array or the explicit one.  The explicit array is the
+   equivalent of the "__builtin_" style call.  */
+
+static tree
+mathfn_built_in_1 (tree type, enum built_in_function fn, bool implicit)
 {
   enum built_in_function fcode, fcodef, fcodel;
+  tree const *const decls_array
+    = implicit ? implicit_built_in_decls : built_in_decls;

   switch (fn)
     {
@@ -1753,15 +1759,23 @@ mathfn_built_in (tree type, enum built_i
       }

   if (TYPE_MAIN_VARIANT (type) == double_type_node)
-    return implicit_built_in_decls[fcode];
+    return decls_array[fcode];
   else if (TYPE_MAIN_VARIANT (type) == float_type_node)
-    return implicit_built_in_decls[fcodef];
+    return decls_array[fcodef];
   else if (TYPE_MAIN_VARIANT (type) == long_double_type_node)
-    return implicit_built_in_decls[fcodel];
+    return decls_array[fcodel];
   else
     return NULL_TREE;
 }

+/* Call the helper function with implicit=true.  */
+
+tree
+mathfn_built_in (tree type, enum built_in_function fn)
+{
+  return mathfn_built_in_1 (type, fn, /*implicit=*/ true);
+}
+
 /* If errno must be maintained, expand the RTL to check if the result,
    TARGET, of a built-in function call, EXP, is NaN, and if so set
    errno to EDOM.  */
@@ -7410,12 +7424,13 @@ fold_builtin_cabs (tree arg, tree type,
       if (flag_unsafe_math_optimizations
 	  && operand_equal_p (real, imag, OEP_PURE_SAME))
         {
-	  const REAL_VALUE_TYPE sqrt2_trunc
-	    = real_value_truncate (TYPE_MODE (type), dconstsqrt2);
+	  tree sqrt2 = build_call_expr (mathfn_built_in_1 (type,
+							   BUILT_IN_SQRT, 0),
+					1, build_real (type, dconst2));
 	  STRIP_NOPS (real);
 	  return fold_build2 (MULT_EXPR, type,
 			      fold_build1 (ABS_EXPR, type, real),
-			      build_real (type, sqrt2_trunc));
+			      sqrt2);
 	}
     }

@@ -8117,21 +8132,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.  */
@@ -8151,9 +8151,9 @@ fold_builtin_logarithm (tree fndecl, tre
 	 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), dconste);
-	  if (real_dconstp (arg, &e_truncated))
+	  tree e = build_call_expr (mathfn_built_in_1 (type, BUILT_IN_EXP, 0),
+				    1, build_real (type, dconst1));
+	  if (operand_equal_p (arg, e, 0))
 	    return build_real (type, dconst1);
 	}

@@ -8185,8 +8185,8 @@ fold_builtin_logarithm (tree fndecl, tre
 	  {
 	  CASE_FLT_FN (BUILT_IN_EXP):
 	    /* Prepare to do logN(exp(exponent) -> exponent*logN(e).  */
-	    x = build_real (type,
-			    real_value_truncate (TYPE_MODE (type), dconste));
+	    x = build_call_expr (mathfn_built_in_1 (type, BUILT_IN_EXP, 0),
+				 1, build_real (type, dconst1));
 	    exponent = CALL_EXPR_ARG (arg, 0);
 	    break;
 	  CASE_FLT_FN (BUILT_IN_EXP2):
@@ -8268,11 +8268,11 @@ fold_builtin_hypot (tree fndecl, tree ar
   if (flag_unsafe_math_optimizations
       && operand_equal_p (arg0, arg1, OEP_PURE_SAME))
     {
-      const REAL_VALUE_TYPE sqrt2_trunc
-	= real_value_truncate (TYPE_MODE (type), dconstsqrt2);
+      tree sqrt2 = build_call_expr (mathfn_built_in_1 (type, BUILT_IN_SQRT, 0),
+				    1, build_real (type, dconst2));
       return fold_build2 (MULT_EXPR, type,
 			  fold_build1 (ABS_EXPR, type, arg0),
-			  build_real (type, sqrt2_trunc));
+			  sqrt2);
     }

   return NULL_TREE;
diff -rup orig/egcc-SVN20070721/gcc/emit-rtl.c egcc-SVN20070721/gcc/emit-rtl.c
--- orig/egcc-SVN20070721/gcc/emit-rtl.c	2007-07-13 12:23:51.000000000 -0400
+++ egcc-SVN20070721/gcc/emit-rtl.c	2007-07-24 01:47:06.487031591 -0400
@@ -106,8 +106,6 @@ REAL_VALUE_TYPE dconstm1;
 REAL_VALUE_TYPE dconstm2;
 REAL_VALUE_TYPE dconsthalf;
 REAL_VALUE_TYPE dconstthird;
-REAL_VALUE_TYPE dconstsqrt2;
-REAL_VALUE_TYPE dconste;

 /* All references to the following fixed hard registers go through
    these unique rtl objects.  On machines where the frame-pointer and
@@ -5180,13 +5178,6 @@ init_emit_once (int line_numbers)

   real_arithmetic (&dconstthird, RDIV_EXPR, &dconst1, &dconst3);

-  /* Initialize mathematical constants for constant folding builtins.
-     These constants need to be given to at least 160 bits precision.  */
-  real_from_string (&dconstsqrt2,
-    "1.4142135623730950488016887242096980785696718753769480731766797379907");
-  real_from_string (&dconste,
-    "2.7182818284590452353602874713526624977572470936999595749669676277241");
-
   for (i = 0; i < (int) ARRAY_SIZE (const_tiny_rtx); i++)
     {
       REAL_VALUE_TYPE *r =
diff -rup orig/egcc-SVN20070721/gcc/real.h egcc-SVN20070721/gcc/real.h
--- orig/egcc-SVN20070721/gcc/real.h	2007-07-18 13:46:10.000000000 -0400
+++ egcc-SVN20070721/gcc/real.h	2007-07-24 01:47:06.488182494 -0400
@@ -386,8 +386,6 @@ extern REAL_VALUE_TYPE dconstm1;
 extern REAL_VALUE_TYPE dconstm2;
 extern REAL_VALUE_TYPE dconsthalf;
 extern REAL_VALUE_TYPE dconstthird;
-extern REAL_VALUE_TYPE dconstsqrt2;
-extern REAL_VALUE_TYPE dconste;

 /* Function to return a real value (not a tree node)
    from a given integer constant.  */


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