[gcc r17-3497] Fixup PRE phi-translation expression simplification
Richard Biener via Gcc-cvs <[email protected]>
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:1f73f91ea78c9c6b986630d236cabd8298788aa6 commit r17-3497-g1f73f91ea78c9c6b986630d236cabd8298788aa6 Author: Richard Biener <[email protected]> Date: Fri Aug 21 09:58:38 2026 +0200 Fixup PRE phi-translation expression simplification PHI translation simplifies/canonicalizes expressions now but the previous limitations as of what NAME results we allow are ineffective and we're now even encoding those previously rejected NAMEs as NARY. The following fixes this by making sure to restore the original unsimplified NARY in such cases. I have noticed this on the testcase for PR126965 * tree-ssa-pre.cc (get_or_alloc_expr_for_nary): Assert we do not try to encode a SSA name or a constant as NARY. (phi_translate_1): Save the translated NARY so we can restore it if we want to reject a simplification to a SSA name. Diff: --- gcc/tree-ssa-pre.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc index 79f1639e1436..3f001fe47630 100644 --- a/gcc/tree-ssa-pre.cc +++ b/gcc/tree-ssa-pre.cc @@ -431,6 +431,8 @@ get_or_alloc_expr_for_nary (vn_nary_op_t nary, unsigned value_id, unsigned int result_id; gcc_assert (value_id == 0 || !value_id_constant_p (value_id)); + gcc_assert (nary->opcode != SSA_NAME + && TREE_CODE_CLASS (nary->opcode) != tcc_constant); expr.kind = NARY; expr.id = 0; @@ -1626,6 +1628,12 @@ phi_translate_1 (bitmap_set_t dest, { unsigned int new_val_id; + vn_nary_op_t saved_newnary + = XALLOCAVAR (struct vn_nary_op_s, + sizeof_vn_nary_op (newnary->length)); + memcpy (saved_newnary, newnary, + sizeof_vn_nary_op (newnary->length)); + /* Try to simplify the new NARY. */ tree res = vn_nary_simplify (newnary); if (res) @@ -1673,6 +1681,10 @@ phi_translate_1 (bitmap_set_t dest, return constant; } } + /* Restore the unsimplified newnary, it was simplified + to a NAME that we do not want (not as NARY anyway). */ + memcpy (newnary, saved_newnary, + sizeof_vn_nary_op (saved_newnary->length)); } tree result = vn_nary_op_lookup_pieces (newnary->length,