Patchwork Another EQ/NE folder type fix (PR c/48305)

login
register
mail settings
Submitter Jakub Jelinek
Date March 29, 2011, 3:53 p.m.
Message ID <20110329155348.GL18914@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/88804/
State New
Headers show

Comments

Jakub Jelinek - March 29, 2011, 3:53 p.m.
Hi!

I've left these 4 out because I thought they should be fine given
that the other operands are equal.  But the testcase shows I was wrong.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
for trunk?

2011-03-29  Jakub Jelinek  <jakub@redhat.com>

	PR c/48305
	* fold-const.c (fold_binary_loc) <case EQ_EXPR, NE_EXPR>: Make sure
	arg10/arg11 in (X ^ Y) == (Z ^ W) are always fold converted to
	matching arg00/arg01 types.

	* gcc.c-torture/compile/pr48305.c: New test.


	Jakub
Richard Guenther - March 30, 2011, 9:41 a.m.
On Tue, Mar 29, 2011 at 5:53 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> I've left these 4 out because I thought they should be fine given
> that the other operands are equal.  But the testcase shows I was wrong.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
> for trunk?

Ok.

Thanks,
Richard.

> 2011-03-29  Jakub Jelinek  <jakub@redhat.com>
>
>        PR c/48305
>        * fold-const.c (fold_binary_loc) <case EQ_EXPR, NE_EXPR>: Make sure
>        arg10/arg11 in (X ^ Y) == (Z ^ W) are always fold converted to
>        matching arg00/arg01 types.
>
>        * gcc.c-torture/compile/pr48305.c: New test.
>
> --- gcc/fold-const.c.jj 2011-03-25 07:56:32.000000000 +0100
> +++ gcc/fold-const.c    2011-03-28 12:45:58.000000000 +0200
> @@ -12625,13 +12625,21 @@ fold_binary_loc (location_t loc,
>             operand_equal_p guarantees no side-effects so we don't need
>             to use omit_one_operand on Z.  */
>          if (operand_equal_p (arg01, arg11, 0))
> -           return fold_build2_loc (loc, code, type, arg00, arg10);
> +           return fold_build2_loc (loc, code, type, arg00,
> +                                   fold_convert_loc (loc, TREE_TYPE (arg00),
> +                                                     arg10));
>          if (operand_equal_p (arg01, arg10, 0))
> -           return fold_build2_loc (loc, code, type, arg00, arg11);
> +           return fold_build2_loc (loc, code, type, arg00,
> +                                   fold_convert_loc (loc, TREE_TYPE (arg00),
> +                                                     arg11));
>          if (operand_equal_p (arg00, arg11, 0))
> -           return fold_build2_loc (loc, code, type, arg01, arg10);
> +           return fold_build2_loc (loc, code, type, arg01,
> +                                   fold_convert_loc (loc, TREE_TYPE (arg01),
> +                                                     arg10));
>          if (operand_equal_p (arg00, arg10, 0))
> -           return fold_build2_loc (loc, code, type, arg01, arg11);
> +           return fold_build2_loc (loc, code, type, arg01,
> +                                   fold_convert_loc (loc, TREE_TYPE (arg01),
> +                                                     arg11));
>
>          /* Optimize (X ^ C1) op (Y ^ C2) as (X ^ (C1 ^ C2)) op Y.  */
>          if (TREE_CODE (arg01) == INTEGER_CST
> --- gcc/testsuite/gcc.c-torture/compile/pr48305.c.jj    2011-03-28 12:48:02.000000000 +0200
> +++ gcc/testsuite/gcc.c-torture/compile/pr48305.c       2011-03-28 12:47:49.000000000 +0200
> @@ -0,0 +1,7 @@
> +/* PR c/48305 */
> +
> +int
> +foo (int x)
> +{
> +  return (x ^ 1) == (x ^ 1U);
> +}
>
>        Jakub
>

Patch

--- gcc/fold-const.c.jj	2011-03-25 07:56:32.000000000 +0100
+++ gcc/fold-const.c	2011-03-28 12:45:58.000000000 +0200
@@ -12625,13 +12625,21 @@  fold_binary_loc (location_t loc,
 	     operand_equal_p guarantees no side-effects so we don't need
 	     to use omit_one_operand on Z.  */
 	  if (operand_equal_p (arg01, arg11, 0))
-	    return fold_build2_loc (loc, code, type, arg00, arg10);
+	    return fold_build2_loc (loc, code, type, arg00,
+				    fold_convert_loc (loc, TREE_TYPE (arg00),
+						      arg10));
 	  if (operand_equal_p (arg01, arg10, 0))
-	    return fold_build2_loc (loc, code, type, arg00, arg11);
+	    return fold_build2_loc (loc, code, type, arg00,
+				    fold_convert_loc (loc, TREE_TYPE (arg00),
+						      arg11));
 	  if (operand_equal_p (arg00, arg11, 0))
-	    return fold_build2_loc (loc, code, type, arg01, arg10);
+	    return fold_build2_loc (loc, code, type, arg01,
+				    fold_convert_loc (loc, TREE_TYPE (arg01),
+						      arg10));
 	  if (operand_equal_p (arg00, arg10, 0))
-	    return fold_build2_loc (loc, code, type, arg01, arg11);
+	    return fold_build2_loc (loc, code, type, arg01,
+				    fold_convert_loc (loc, TREE_TYPE (arg01),
+						      arg11));
 
 	  /* Optimize (X ^ C1) op (Y ^ C2) as (X ^ (C1 ^ C2)) op Y.  */
 	  if (TREE_CODE (arg01) == INTEGER_CST
--- gcc/testsuite/gcc.c-torture/compile/pr48305.c.jj	2011-03-28 12:48:02.000000000 +0200
+++ gcc/testsuite/gcc.c-torture/compile/pr48305.c	2011-03-28 12:47:49.000000000 +0200
@@ -0,0 +1,7 @@ 
+/* PR c/48305 */
+
+int
+foo (int x)
+{
+  return (x ^ 1) == (x ^ 1U);
+}