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]

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


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.

--- 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


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