The following fixes PR61452 - when keeping a lattice value at VARYING we shouldn't adjust the lattice ->expr or ->has_constants.
Bootstrap and regtest pending on x86_64-unknown-linux-gnu. Richard. 2014-06-10 Richard Biener <rguent...@suse.de> PR tree-optimization/61452 * tree-ssa-sccvn.c (visit_phi): Remove pointless setting of expr and has_constants in case we found a leader. * gcc.dg/torture/pr61452.c: New testcase. Index: gcc/tree-ssa-sccvn.c =================================================================== *** gcc/tree-ssa-sccvn.c (revision 211403) --- gcc/tree-ssa-sccvn.c (working copy) *************** visit_phi (gimple phi) *** 3140,3174 **** /* If all value numbered to the same value, the phi node has that value. */ if (allsame) ! { ! if (is_gimple_min_invariant (sameval)) ! { ! VN_INFO (PHI_RESULT (phi))->has_constants = true; ! if (sameval != VN_TOP) ! VN_INFO (PHI_RESULT (phi))->expr = sameval; ! } ! else ! { ! VN_INFO (PHI_RESULT (phi))->has_constants = false; ! if (sameval != VN_TOP) ! VN_INFO (PHI_RESULT (phi))->expr = sameval; ! } ! ! if (TREE_CODE (sameval) == SSA_NAME) ! return visit_copy (PHI_RESULT (phi), sameval); ! ! return set_ssa_val_to (PHI_RESULT (phi), sameval); ! } /* Otherwise, see if it is equivalent to a phi node in this block. */ result = vn_phi_lookup (phi); if (result) ! { ! if (TREE_CODE (result) == SSA_NAME) ! changed = visit_copy (PHI_RESULT (phi), result); ! else ! changed = set_ssa_val_to (PHI_RESULT (phi), result); ! } else { vn_phi_insert (phi, PHI_RESULT (phi)); --- 3140,3151 ---- /* If all value numbered to the same value, the phi node has that value. */ if (allsame) ! return set_ssa_val_to (PHI_RESULT (phi), sameval); /* Otherwise, see if it is equivalent to a phi node in this block. */ result = vn_phi_lookup (phi); if (result) ! changed = set_ssa_val_to (PHI_RESULT (phi), result); else { vn_phi_insert (phi, PHI_RESULT (phi)); Index: gcc/testsuite/gcc.dg/torture/pr61452.c =================================================================== *** gcc/testsuite/gcc.dg/torture/pr61452.c (revision 0) --- gcc/testsuite/gcc.dg/torture/pr61452.c (working copy) *************** *** 0 **** --- 1,31 ---- + /* { dg-do run } */ + + int a, b; + short c, d; + char e, f; + + int + fn1 (int p1, char p2) + { + return p1 || p2 ? 0 : p2; + } + + void + fn2 () + { + for (; a;) + { + int g; + g = c = e; + for (; a;) + b = fn1 (g = d = e, g); + f = g; + } + } + + int + main () + { + fn2 (); + return 0; + }