https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128651
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Richard Biener <[email protected]>: https://gcc.gnu.org/g:2686ecea4f63daf463ab8674c657b2d7f30de737 commit r17-6183-g2686ecea4f63daf463ab8674c657b2d7f30de737 Author: Richard Biener <[email protected]> Date: Thu Nov 12 16:11:21 2026 +0100 tree-optimization/128651 - do not keep optimistic inserted expressions in VN vn_nary_build_or_lookup_1 inserts expressions it creates into valid_info->nary and unlinks them from the undo chain, so that iteration does not create a new SSA name for the same expression over and over. But the hashtable entry is keyed on the value numbers of the operands, which can be optimistic. In the testcase, when _13 has the optimistic value x.2_7, we insert _9 = (unsigned long) _13 and record it as (unsigned long) x.2_7. When iteration finds _13 varying, the stale entry survives and later lookups of (unsigned long) x.2_7 wrongly get _9. The following links the entry into the undo chain like any other entry. To still re-use the SSA name across iterations, a new inserted_exprs table records inserted expressions keyed on the operands of the inserted statement, not their value numbers, and is not unwound. A re-used expression then goes through the same path as a newly built one. The table is only allocated and maintained when iterating. PR tree-optimization/128651 * tree-ssa-sccvn.cc (vn_tables_s::inserted_exprs): New member. (vn_nary_build_or_lookup_1): Look up and record inserted expressions in valid_info->inserted_exprs to re-use the SSA name across iterations. Insert the expression into valid_info->nary with vn_nary_op_insert_stmt so it is unwound on iteration. (allocate_vn_table): Initialize inserted_exprs to NULL. (free_vn_table): Free inserted_exprs. (do_rpo_vn_1): Allocate inserted_exprs when iterating. * gcc.dg/torture/pr128651.c: New testcase.
