VRP (x << 31) < -1 fix (PR tree-optimization/56984)

Submitted by Jakub Jelinek on April 18, 2013, 6:35 a.m.

Details

Message ID 20130418063521.GX12880@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek April 18, 2013, 6:35 a.m.
Hi!

Like in the case a few lines below, if new_val is a minimum resp. a few
lines below maximum value, we end up with always true resp. always false
assertion, which VRP asserts that those aren't created.  So, we should punt
on those, and instead fold-const or gimple_fold should ideally optimize
those cases to false resp. true.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.8
branch?

2013-04-18  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/56984
	* tree-vrp.c (register_edge_assert_for_2): For (x >> M) < N
	and (x >> M) >= N don't register any assertion if N << M is the
	minimum value.

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


	Jakub

Comments

Richard Guenther April 18, 2013, 7:49 a.m.
On Thu, 18 Apr 2013, Jakub Jelinek wrote:

> Hi!
> 
> Like in the case a few lines below, if new_val is a minimum resp. a few
> lines below maximum value, we end up with always true resp. always false
> assertion, which VRP asserts that those aren't created.  So, we should punt
> on those, and instead fold-const or gimple_fold should ideally optimize
> those cases to false resp. true.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.8
> branch?

Ok.

When VRP asserts that we don't build such assert stmts can it at that
point simply drop the assert?  That's more user-friendly (instead of
just ICEing ...) I think.

Thanks.
Richard.

> 2013-04-18  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/56984
> 	* tree-vrp.c (register_edge_assert_for_2): For (x >> M) < N
> 	and (x >> M) >= N don't register any assertion if N << M is the
> 	minimum value.
> 
> 	* gcc.c-torture/compile/pr56984.c: New test.
> 
> --- gcc/tree-vrp.c.jj	2013-04-11 09:09:33.000000000 +0200
> +++ gcc/tree-vrp.c	2013-04-17 09:17:34.278242462 +0200
> @@ -4895,7 +4895,13 @@ register_edge_assert_for_2 (tree name, e
>  	      new_comp_code = comp_code == EQ_EXPR ? LE_EXPR : GT_EXPR;
>  	    }
>  	  else if (comp_code == LT_EXPR || comp_code == GE_EXPR)
> -	    new_val = val2;
> +	    {
> +	      double_int minval
> +		= double_int::min_value (prec, TYPE_UNSIGNED (TREE_TYPE (val)));
> +	      new_val = val2;
> +	      if (minval == tree_to_double_int (new_val))
> +		new_val = NULL_TREE;
> +	    }
>  	  else
>  	    {
>  	      double_int maxval
> --- gcc/testsuite/gcc.c-torture/compile/pr56984.c.jj	2013-04-17 09:24:44.689719328 +0200
> +++ gcc/testsuite/gcc.c-torture/compile/pr56984.c	2013-04-17 09:24:25.000000000 +0200
> @@ -0,0 +1,9 @@
> +/* PR tree-optimization/56984 */
> +
> +int
> +foo (int x)
> +{
> +  if ((x >> 31) < -1)
> +    x++;
> +  return x;
> +}
> 
> 	Jakub
> 
>

Patch hide | download patch | download mbox

--- gcc/tree-vrp.c.jj	2013-04-11 09:09:33.000000000 +0200
+++ gcc/tree-vrp.c	2013-04-17 09:17:34.278242462 +0200
@@ -4895,7 +4895,13 @@  register_edge_assert_for_2 (tree name, e
 	      new_comp_code = comp_code == EQ_EXPR ? LE_EXPR : GT_EXPR;
 	    }
 	  else if (comp_code == LT_EXPR || comp_code == GE_EXPR)
-	    new_val = val2;
+	    {
+	      double_int minval
+		= double_int::min_value (prec, TYPE_UNSIGNED (TREE_TYPE (val)));
+	      new_val = val2;
+	      if (minval == tree_to_double_int (new_val))
+		new_val = NULL_TREE;
+	    }
 	  else
 	    {
 	      double_int maxval
--- gcc/testsuite/gcc.c-torture/compile/pr56984.c.jj	2013-04-17 09:24:44.689719328 +0200
+++ gcc/testsuite/gcc.c-torture/compile/pr56984.c	2013-04-17 09:24:25.000000000 +0200
@@ -0,0 +1,9 @@ 
+/* PR tree-optimization/56984 */
+
+int
+foo (int x)
+{
+  if ((x >> 31) < -1)
+    x++;
+  return x;
+}