I am testing the following patch to fix a missed optimization and wrong-code issue in region VN.
{,O1-}Bootstrap and regtest running on x86_64-unknown-linux-gnu. 2018-08-31 Richard Biener <rguent...@suse.de> PR tree-optimization/87168 * tree-ssa-sccvn.c (SSA_VAL): Add visited output parameter. (rpo_elim::eliminate_avail): When OP was not visited it must be available. * gcc.dg/torture/pr87168.c: New testcase. Index: gcc/tree-ssa-sccvn.c =================================================================== --- gcc/tree-ssa-sccvn.c (revision 263982) +++ gcc/tree-ssa-sccvn.c (working copy) @@ -456,10 +456,14 @@ VN_INFO (tree name) /* Return the SSA value of X. */ inline tree -SSA_VAL (tree x) +SSA_VAL (tree x, bool *visited = NULL) { vn_ssa_aux_t tem = vn_ssa_aux_hash->find_with_hash (x, SSA_NAME_VERSION (x)); - return tem && tem->visited ? tem->valnum : x; + if (!tem) + return x; + if (visited) + *visited = tem->visited; + return tem->visited ? tem->valnum : x; } /* Return whether X was visited. */ @@ -5681,7 +5685,12 @@ rpo_elim::~rpo_elim () tree rpo_elim::eliminate_avail (basic_block bb, tree op) { - tree valnum = SSA_VAL (op); + bool visited; + tree valnum = SSA_VAL (op, &visited); + /* If we didn't visit OP then it must be defined outside of the + region we process and also dominate it. So it is available. */ + if (!visited) + return op; if (TREE_CODE (valnum) == SSA_NAME) { if (SSA_NAME_IS_DEFAULT_DEF (valnum)) Index: gcc/testsuite/gcc.dg/torture/pr87168.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr87168.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr87168.c (working copy) @@ -0,0 +1,30 @@ +/* { dg-do compile } */ + +int a, b, c, d, e, f, *g; + +int main () +{ + unsigned i; + while (b) + { + int j, m; +L1: + f = j; +L2: + if (i && e) + { + i = f; + goto L2; + } + j = f; + if (a) + goto L3; + for (m = 0; m < 2; m++) + if (d) + goto L1; + goto L2; +L3: + (&j != g) | c; + } + return 0; +}