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] Restrict pow -> cbrt expansion to unsafe math and positive args or finite math


As discussed in the cbrt expansion thread.

Bootstrapped and tested on x86_64-unknown-linux-gnu, will apply to
mainline tomorrow.

Richard.

2006-12-05  Richard Guenther  <rguenther@suse.de>

	* builtins.c (expand_builtin_pow): Adjust predicates for
	pow to cbrt expansion to unsafe math and !HONOR_NANS for
	negative base.

Index: builtins.c
===================================================================
*** builtins.c	(revision 119540)
--- builtins.c	(working copy)
*************** expand_builtin_pow (tree exp, rtx target
*** 2679,2687 ****
      }
  
    /* Try if the exponent is a third of an integer.  In this case
!      we can expand to x**(n/3) * cbrt(x)**(n%3).  */
    fn = mathfn_built_in (type, BUILT_IN_CBRT);
!   if (fn != NULL_TREE)
      {
        real_arithmetic (&c2, MULT_EXPR, &c, &dconst3);
        real_round (&c2, mode, &c2);
--- 2679,2693 ----
      }
  
    /* Try if the exponent is a third of an integer.  In this case
!      we can expand to x**(n/3) * cbrt(x)**(n%3).  As cbrt (x) is
!      different from pow (x, 1./3.) due to rounding and behavior
!      with negative x we need to constrain this transformation to
!      unsafe math and positive x or finite math.  */
    fn = mathfn_built_in (type, BUILT_IN_CBRT);
!   if (fn != NULL_TREE
!       && flag_unsafe_math_optimizations
!       && (tree_expr_nonnegative_p (arg0)
! 	  || !HONOR_NANS (mode)))
      {
        real_arithmetic (&c2, MULT_EXPR, &c, &dconst3);
        real_round (&c2, mode, &c2);
*************** expand_builtin_pow (tree exp, rtx target
*** 2691,2697 ****
        real_convert (&c2, mode, &c2);
        if (real_identical (&c2, &c)
  	  && ((!optimize_size
- 	       && flag_unsafe_math_optimizations
  	       && powi_cost (n/3) <= POWI_MAX_MULTS)
  	      || n == 1))
  	{
--- 2697,2702 ----


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