Patchwork Fix ccp evaluate_stmt for tcc_comparison assignments (PR tree-optimization/47140)

login
register
mail settings
Submitter Jakub Jelinek
Date Jan. 1, 2011, 6:22 p.m.
Message ID <20110101182228.GW16156@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/77147/
State New
Headers show

Comments

Jakub Jelinek - Jan. 1, 2011, 6:22 p.m.
Hi!

For tcc_comparison binary assignments the lhs type is often different
from the type of the comparison operands, so when we bit_value_binop with
rhs1's type instead of lhs' type, the type of the constant might be
incorrect.

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

2011-01-01  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/47140
	* tree-ssa-ccp.c (evaluate_stmt): For binary assignments, use
	TREE_TYPE (lhs) instead of TREE_TYPE (rhs1) as second argument
	to bit_value_binop.

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


	Jakub
Richard Guenther - Jan. 2, 2011, 4:12 p.m.
On Sat, Jan 1, 2011 at 7:22 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> For tcc_comparison binary assignments the lhs type is often different
> from the type of the comparison operands, so when we bit_value_binop with
> rhs1's type instead of lhs' type, the type of the constant might be
> incorrect.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

Ok.

Thanks,
Richard.

> 2011-01-01  Jakub Jelinek  <jakub@redhat.com>
>
>        PR tree-optimization/47140
>        * tree-ssa-ccp.c (evaluate_stmt): For binary assignments, use
>        TREE_TYPE (lhs) instead of TREE_TYPE (rhs1) as second argument
>        to bit_value_binop.
>
>        * gcc.c-torture/compile/pr47140.c: New test.
>
> --- gcc/tree-ssa-ccp.c.jj       2010-12-16 10:55:33.000000000 +0100
> +++ gcc/tree-ssa-ccp.c  2011-01-01 16:12:57.000000000 +0100
> @@ -2156,9 +2156,10 @@ evaluate_stmt (gimple stmt)
>              if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
>                  || POINTER_TYPE_P (TREE_TYPE (rhs1)))
>                {
> +                 tree lhs = gimple_assign_lhs (stmt);
>                  tree rhs2 = gimple_assign_rhs2 (stmt);
>                  val = bit_value_binop (subcode,
> -                                        TREE_TYPE (rhs1), rhs1, rhs2);
> +                                        TREE_TYPE (lhs), rhs1, rhs2);
>                }
>              break;
>
> --- gcc/testsuite/gcc.c-torture/compile/pr47140.c.jj    2011-01-01 16:18:47.000000000 +0100
> +++ gcc/testsuite/gcc.c-torture/compile/pr47140.c       2011-01-01 16:19:32.000000000 +0100
> @@ -0,0 +1,25 @@
> +/* PR tree-optimization/47140 */
> +
> +static inline int
> +foo (int x, short y)
> +{
> +  return y == 0 ? x : x + y;
> +}
> +
> +static inline unsigned short
> +bar (unsigned short x, unsigned char y)
> +{
> +  return x - y;
> +}
> +
> +int w;
> +
> +int baz (void);
> +
> +int
> +test (void)
> +{
> +  int i;
> +  for (i = 0; i < 50; i++)
> +    w += foo ((unsigned char) (1 + baz ()) >= bar (0, 1), 0);
> +}
>
>        Jakub
>

Patch

--- gcc/tree-ssa-ccp.c.jj	2010-12-16 10:55:33.000000000 +0100
+++ gcc/tree-ssa-ccp.c	2011-01-01 16:12:57.000000000 +0100
@@ -2156,9 +2156,10 @@  evaluate_stmt (gimple stmt)
 	      if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
 		  || POINTER_TYPE_P (TREE_TYPE (rhs1)))
 		{
+		  tree lhs = gimple_assign_lhs (stmt);
 		  tree rhs2 = gimple_assign_rhs2 (stmt);
 		  val = bit_value_binop (subcode,
-					 TREE_TYPE (rhs1), rhs1, rhs2);
+					 TREE_TYPE (lhs), rhs1, rhs2);
 		}
 	      break;
 
--- gcc/testsuite/gcc.c-torture/compile/pr47140.c.jj	2011-01-01 16:18:47.000000000 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr47140.c	2011-01-01 16:19:32.000000000 +0100
@@ -0,0 +1,25 @@ 
+/* PR tree-optimization/47140 */
+
+static inline int
+foo (int x, short y)
+{
+  return y == 0 ? x : x + y;
+}
+
+static inline unsigned short
+bar (unsigned short x, unsigned char y)
+{
+  return x - y;
+}
+
+int w;
+
+int baz (void);
+
+int
+test (void)
+{
+  int i;
+  for (i = 0; i < 50; i++)
+    w += foo ((unsigned char) (1 + baz ()) >= bar (0, 1), 0);
+}