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: [PATCH] Fold sqrt comparisons against constants (take 3)


On Tue, Mar 18, 2003 at 10:41:10PM -0700, Roger Sayle wrote:
> 	* fold-const.c (fold_mathfn_compare): New function to simplify
> 	comparisons against built-in math functions.  Fold comparisons
> 	of sqrt against constants.
> 	(fold): Call fold_mathfn_compare when appropriate.

Nearly there.

> + 	  /* sqrt(x) < y is always false, if y is negative.  */
> + 	  if (code == EQ_EXPR || code == LT_EXPR || code == LE_EXPR)
> + 	    return omit_one_operand (type,
> + 				     convert (type, integer_zero_node),
> + 				     arg);
> +
> + 	  /* sqrt(x) > y is always true, if y is negative and we
> + 	     don't care about NaNs, i.e. negative values of x.  */
> + 	  if (! HONOR_NANS (mode))
> + 	    return omit_one_operand (type,
> + 				     convert (type, integer_one_node),
> + 				     arg);
> +
> + 	  /* sqrt(x) > y is the same as x >= 0, if y is negative.  */
> + 	  return fold (build (GE_EXPR, type, arg,
> + 			      build_real (TREE_TYPE (arg), dconst0)));

Isn't this test always true for NE_EXPR, regardless of NANs?

> + 	      /* sqrt(x) > y is x == +Inf, when y is very large.  */
> + 	      /* sqrt(x) < y is x != +Inf when y is very large and we
> + 	      /* sqrt(x) < y is x >= 0 && x != +Inf, when y is large.  */

While these are all true and correct, I'd really prefer that
we didn't compare against Inf directly, since this traps for
emulation on Alpha and Mips (at least).

Better is to test {>,<=} DBL_MAX.

It should be easy to add a function to real.c that can build
this constant for you for any particular fp type.


r~


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