https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102681
--- Comment #21 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #14) > Created attachment 51650 [details] > Little more reduced > > So FRE is able to figure out for the following: > # _20 = PHI <0(2), 1(3)> > # const_upper_26 = PHI <const_upper_27(D)(2), _19(3)> > .... > # _30 = PHI <0(12), 1(13)> > # const_upper_33 = PHI <const_upper_34(D)(12), _29(13)> > > That _30 is the same as _20 but not _26 is the same as _33 even though it > does figure out that _19 and _29 are the same as _10. If it is able to > figure that out, then things would just work. > > Richi, > I assume FRE does not Value number default SSA names (non-parm) the same > which is why this is happening is that correct? The issue with CSE here is that with RPO VN I made unvisited vars VARYING due to on-demand handling. While vn_visit_phis has special handling for undefs the hashtable insert/lookup do not. I am testing the following to rectify this (which then CSEs this PHI). diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index ae0172a143e..893b1d0ddaa 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -4499,7 +4499,12 @@ vn_phi_lookup (gimple *phi, bool backedges_varying_p) tree def = PHI_ARG_DEF_FROM_EDGE (phi, e); if (TREE_CODE (def) == SSA_NAME && (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK))) - def = SSA_VAL (def); + { + if (ssa_undefined_value_p (def, false)) + def = VN_TOP; + else + def = SSA_VAL (def); + } vp1->phiargs[e->dest_idx] = def; } vp1->type = TREE_TYPE (gimple_phi_result (phi)); @@ -4543,7 +4548,12 @@ vn_phi_insert (gimple *phi, tree result, bool backedges_varying_p) tree def = PHI_ARG_DEF_FROM_EDGE (phi, e); if (TREE_CODE (def) == SSA_NAME && (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK))) - def = SSA_VAL (def); + { + if (ssa_undefined_value_p (def, false)) + def = VN_TOP; + else + def = SSA_VAL (def); + } vp1->phiargs[e->dest_idx] = def; } vp1->value_id = VN_INFO (result)->value_id;