Bootstrapped / tested on x86_64-unknown-linux-gnu, applied. Richard.
2017-01-23 Richard Biener <rguent...@suse.de> PR tree-optimization/79186 * tree-vrp.c (register_new_assert_for): Make sure we've seen both incoming edges before moving an assert. * gcc.dg/torture/pr79186.c: New testcase. * gcc.dg/torture/pr79187.c: Likewise. Index: gcc/tree-vrp.c =================================================================== --- gcc/tree-vrp.c (revision 244771) +++ gcc/tree-vrp.c (working copy) @@ -5035,6 +5035,7 @@ register_new_assert_for (tree name, tree /* If we have the same assertion on all incoming edges of a BB instead insert it at the beginning of it. */ if (e && loc->e + && e != loc->e && dest_bb == loc->e->dest && EDGE_COUNT (dest_bb->preds) == 2) { Index: gcc/testsuite/gcc.dg/torture/pr79186.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr79186.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr79186.c (working copy) @@ -0,0 +1,16 @@ +/* { dg-do run } */ + +int a, b; +unsigned char c, d, e; + +int main () +{ + if (b || !a) + { + c = a; + if (!c && !a) + d = 0; + e = -a; + } + return 0; +} Index: gcc/testsuite/gcc.dg/torture/pr79187.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr79187.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr79187.c (working copy) @@ -0,0 +1,19 @@ +/* { dg-do run } */ + +int printf (const char *, ...); + +int a, b = -600, c, d[] = { 0 }, e, f, g = -1, h; +unsigned i = ~0; + +int main () +{ + for (; h < 2; h++) + { + if (a > 0) + printf ("%d\n", d[b]); + f = ~(b % i); + c = g | (f && g) && e | b; + a = ~(~g & b); + } + return 0; +}