The following fixes PR87280 (and PR87169 in a different way).
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2018-09-12 Richard Biener <rguent...@suse.de> PR tree-optimization/87280 * tree-ssa-sccvn.c (process_bb): Handle the case of executable edge but unreachable target. (do_rpo_vn): For conservatively handling a PHI only mark the backedge executable but not the block reachable. * gcc.dg/torture/pr87280.c: New testcase. Index: gcc/tree-ssa-sccvn.c =================================================================== --- gcc/tree-ssa-sccvn.c (revision 264234) +++ gcc/tree-ssa-sccvn.c (working copy) @@ -5976,15 +5976,24 @@ process_bb (rpo_elim &avail, basic_block { FOR_EACH_EDGE (e, ei, bb->succs) { - if (e->flags & EDGE_EXECUTABLE) - continue; - if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, - "marking outgoing edge %d -> %d executable\n", - e->src->index, e->dest->index); - gcc_checking_assert (iterate || !(e->flags & EDGE_DFS_BACK)); - e->flags |= EDGE_EXECUTABLE; - e->dest->flags |= BB_EXECUTABLE; + if (!(e->flags & EDGE_EXECUTABLE)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "marking outgoing edge %d -> %d executable\n", + e->src->index, e->dest->index); + gcc_checking_assert (iterate || !(e->flags & EDGE_DFS_BACK)); + e->flags |= EDGE_EXECUTABLE; + e->dest->flags |= BB_EXECUTABLE; + } + else if (!(e->dest->flags & BB_EXECUTABLE)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "marking destination block %d reachable\n", + e->dest->index); + e->dest->flags |= BB_EXECUTABLE; + } } } for (gimple_stmt_iterator gsi = gsi_start_bb (bb); @@ -6124,20 +6133,37 @@ process_bb (rpo_elim &avail, basic_block e->flags |= EDGE_EXECUTABLE; e->dest->flags |= BB_EXECUTABLE; } + else if (!(e->dest->flags & BB_EXECUTABLE)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "marking destination block %d reachable\n", + e->dest->index); + e->dest->flags |= BB_EXECUTABLE; + } } else if (gsi_one_before_end_p (gsi)) { FOR_EACH_EDGE (e, ei, bb->succs) { - if (e->flags & EDGE_EXECUTABLE) - continue; - if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, - "marking outgoing edge %d -> %d executable\n", - e->src->index, e->dest->index); - gcc_checking_assert (iterate || !(e->flags & EDGE_DFS_BACK)); - e->flags |= EDGE_EXECUTABLE; - e->dest->flags |= BB_EXECUTABLE; + if (!(e->flags & EDGE_EXECUTABLE)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "marking outgoing edge %d -> %d executable\n", + e->src->index, e->dest->index); + gcc_checking_assert (iterate || !(e->flags & EDGE_DFS_BACK)); + e->flags |= EDGE_EXECUTABLE; + e->dest->flags |= BB_EXECUTABLE; + } + else if (!(e->dest->flags & BB_EXECUTABLE)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "marking destination block %d reachable\n", + e->dest->index); + e->dest->flags |= BB_EXECUTABLE; + } } } @@ -6399,7 +6425,6 @@ do_rpo_vn (function *fn, edge entry, bit if (e->flags & EDGE_DFS_BACK) { e->flags |= EDGE_EXECUTABLE; - e->dest->flags |= BB_EXECUTABLE; /* There can be a non-latch backedge into the header which is part of an outer irreducible region. We cannot avoid iterating this block then. */ Index: gcc/testsuite/gcc.dg/torture/pr87280.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr87280.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr87280.c (working copy) @@ -0,0 +1,61 @@ +/* { dg-do compile } */ +/* { dg-additional-options "--param rpo-vn-max-loop-depth=5" } */ + +int uc; + +void +j8 (int *xv, int f3) +{ + uc = 0; + while (uc < 1) + { + } + + if (*xv == 0) + { + int *o8 = xv; + + if (0) + { +n3: + *o8 = 0; + while (*o8 < 1) + { +h5: + *o8 = 0; + } + } + + while (*xv < 1) + if (*xv == 0) + goto h5; + +g5: + ; + } + + *xv = 0; + for (;;) + { + while (uc < 1) + { + } + + while (f3 < 1) + { + if (*xv == 0) + goto n3; + + while (f3 < 1) + while (*xv < 1) + while (*xv < 1) + while (*xv < 1) + while (*xv < 1) + { + } + } + + if (*xv == 0) + goto g5; + } +}