The following adds a missed valueization to vn_nary_build_or_lookup_1 which previously could have returned an available SSA name as simplification result instead of its value-number.
Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2018-09-03 Richard Biener <rguent...@suse.de> PR tree-optimization/87200 * tree-ssa-sccvn.c (vn_nary_build_or_lookup_1): Valueize a simplify result. * gcc.dg/torture/pr87200.c: New testcase. Index: gcc/tree-ssa-sccvn.c =================================================================== --- gcc/tree-ssa-sccvn.c (revision 264049) +++ gcc/tree-ssa-sccvn.c (working copy) @@ -1759,8 +1759,13 @@ vn_nary_build_or_lookup_1 (gimple_match_ gimple *new_stmt = NULL; if (res && gimple_simplified_result_is_gimple_val (res_op)) - /* The expression is already available. */ - result = res_op->ops[0]; + { + /* The expression is already available. */ + result = res_op->ops[0]; + /* Valueize it, simplification returns sth in AVAIL only. */ + if (TREE_CODE (result) == SSA_NAME) + result = SSA_VAL (result); + } else { tree val = vn_lookup_simplify_result (res_op); Index: gcc/testsuite/gcc.dg/torture/pr87200.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr87200.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr87200.c (working copy) @@ -0,0 +1,23 @@ +/* { dg-do compile } */ + +unsigned long long int ry; + +int +gl (void) +{ + long long int my = 0; + unsigned long long int *oi = (unsigned long long int *) &my; + int s9; + + s9 = !!gl () ? ry : 0; + if (s9 != 0) + oi = &ry; + else + { + my = ry; + *oi += my; + } + + return *oi; +} +