From: Jakub Jelinek Date: Wed, 20 Jun 2018 14:47:28 +0000 (+0200) Subject: re PR tree-optimization/86231 (vrp_meet causes wrong-code) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c81a5aecc58eb17bc951d0306945c029439b5fcb;p=gcc.git re PR tree-optimization/86231 (vrp_meet causes wrong-code) 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. From-SVN: r261805 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d43118c22a3..5d267eb1fac 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-06-20 Jakub Jelinek + + 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. + 2018-06-20 Tom de Vries PR tree-optimization/86097 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ad3b600603f..5b3de8da4d2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-06-20 Jakub Jelinek + + PR tree-optimization/86231 + * gcc.dg/tree-ssa/vrp119.c: New test. + * gcc.c-torture/execute/pr86231.c: New test. + 2018-06-20 Tom de Vries PR tree-optimization/86097 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr86231.c b/gcc/testsuite/gcc.c-torture/execute/pr86231.c new file mode 100644 index 00000000000..79232ebd7f1 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr86231.c @@ -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; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp119.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp119.c new file mode 100644 index 00000000000..92c490e542c --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp119.c @@ -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; +} diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index fad25ed2e33..7c675396d78 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -5922,9 +5922,9 @@ union_ranges (enum value_range_type *vr0type, 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;