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, Fix PR 31098] a*C == b*C is not foldded to a == b with --fast-math/floating point


On Sat, 13 Oct 2007, Pranav Bhandarkar wrote:

> Hi,
> The attached patch addresses the points raised by Paolo, Kaveh and Tom.
> Bootstrapped and regtested on i686-pc-linux-gnu.
> Is this ok ?
> cheers!
> Pranav
>
> +      /* (a OP c) CMP (b OP c) -> a CMP b, iff c is not zero
> +	 if c is negative then convert into (a swap(CMP) b) */
> +      if (flag_unsafe_math_optimizations
> +	  && !HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg0)))
> +	  && !flag_trapping_math && (TREE_CODE (arg0) == TREE_CODE (arg1))
> +	  && BINARY_CLASS_P (arg0) && !real_zerop (TREE_OPERAND (arg0,1)))
> +	{
> +	  if (TREE_CODE (TREE_OPERAND (arg0, 1)) == REAL_CST
> +	      && TREE_CODE (TREE_OPERAND (arg1, 1)) == REAL_CST )
> +	    {
> +	      REAL_VALUE_TYPE *cst0, *cst1;
> +	      cst0 = &TREE_REAL_CST (TREE_OPERAND (arg0, 1));
> +	      cst1 = &TREE_REAL_CST (TREE_OPERAND (arg1, 1));
> +
> +	      if (real_compare (EQ_EXPR, cst0, cst1))
> +		{
> +		  if (real_isneg (cst0))
> +		    return fold_build2 (swap_tree_comparison (code), type, TREE_OPERAND (arg0,0), TREE_OPERAND (arg1,0));
> +		  else
> +		    return fold_build2 (code, type, TREE_OPERAND (arg0,0), TREE_OPERAND (arg1,0));
> +
> +		}
> +	    }
> +	}
> +

Hmm, is BINARY_CLASS_P() narrow enough for this transformation to be
always valid?

		--Kaveh
--
Kaveh R. Ghazi			ghazi@caip.rutgers.edu


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