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] Fix vrp_meet (PR tree-optimization/86231)


Hi!

On the second following testcase, we call vrp_meet on [1B, 2B] and ~[0B, 1B]
and instead of computing the right ~[0B, 0B], we compute invalid ~[0B, -1B].

Similarly, on the first testcase, vrp_meet on [4, 8] and ~[2, 6] computes
~[2, 1] which is invalid and is canonicalized into VARYING, while we want
~[2, 3].

The problem is a thinko, for the new minimum we need to subtract 1 from the
vr0's minimum, but we overwrite it before that with the vr1's minimum and so
always compute ~[vr1min, vr1min-1].

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

2018-06-20  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/86231
	* tree-vrp.c (union_ranges): For (  [  )  ] or (   )[   ] range and
	anti-range don't overwrite *vr0min before using it to compute *vr0max.

	* gcc.dg/tree-ssa/vrp119.c: New test.
	* gcc.c-torture/execute/pr86231.c: New test.

--- gcc/tree-vrp.c.jj	2018-05-31 20:53:31.200438223 +0200
+++ gcc/tree-vrp.c	2018-06-20 09:36:55.536561840 +0200
@@ -5922,9 +5922,9 @@ union_ranges (enum value_range_type *vr0
 	  if (TREE_CODE (*vr0min) == INTEGER_CST)
 	    {
 	      *vr0type = vr1type;
-	      *vr0min = vr1min;
 	      *vr0max = int_const_binop (MINUS_EXPR, *vr0min,
 					 build_int_cst (TREE_TYPE (*vr0min), 1));
+	      *vr0min = vr1min;
 	    }
 	  else
 	    goto give_up;
--- gcc/testsuite/gcc.dg/tree-ssa/vrp119.c.jj	2018-06-20 09:31:06.984238418 +0200
+++ gcc/testsuite/gcc.dg/tree-ssa/vrp119.c	2018-06-20 09:33:07.526350273 +0200
@@ -0,0 +1,20 @@
+/* PR tree-optimization/86231 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-vrp1" } */
+/* { dg-final { scan-tree-dump-not "link_error" "vrp1" } } */
+
+int bar (int);
+void link_error (void);
+
+int
+foo (int x, int y, int z)
+{
+  if (x < 4 || x > 8) __builtin_unreachable ();
+  if (y >= 2 && y <= 6) __builtin_unreachable ();
+  /* x is [4, 8], y is ~[2, 6], resulting range of e should be ~[2, 3].  */
+  int e = (z ? x : y);
+  bar (bar (bar (bar (bar (bar (bar (bar (bar (bar (bar (bar (e))))))))))));
+  if (e == 2 || e == 3)
+    link_error ();
+  return e;
+}
--- gcc/testsuite/gcc.c-torture/execute/pr86231.c.jj	2018-06-20 09:19:46.797601458 +0200
+++ gcc/testsuite/gcc.c-torture/execute/pr86231.c	2018-06-20 09:30:44.437217496 +0200
@@ -0,0 +1,30 @@
+/* PR tree-optimization/86231 */
+
+#define ONE ((void *) 1)
+#define TWO ((void *) 2)
+
+__attribute__((noipa)) int
+foo (void *p, int x)
+{
+  if (p == ONE) return 0;
+  if (!p)
+    p = x ? TWO : ONE;
+  return p == ONE ? 0 : 1;
+}
+
+int v[8];
+
+int
+main ()
+{
+  if (foo ((void *) 0, 0) != 0
+      || foo ((void *) 0, 1) != 1
+      || foo (ONE, 0) != 0
+      || foo (ONE, 1) != 0
+      || foo (TWO, 0) != 1
+      || foo (TWO, 1) != 1
+      || foo (&v[7], 0) != 1
+      || foo (&v[7], 1) != 1)
+    __builtin_abort ();
+  return 0;
+}

	Jakub


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