https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118817
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Richard Biener <rgue...@gcc.gnu.org>: https://gcc.gnu.org/g:0a1d2ea57722c248777e1130de076e28c443ff8b commit r15-7472-g0a1d2ea57722c248777e1130de076e28c443ff8b Author: Richard Biener <rguent...@suse.de> Date: Tue Feb 11 10:29:18 2025 +0100 tree-optimization/118817 - missed folding of PRE inserted code When PRE inserts code it is not fully folded with following SSA edges which can cause missed optimizations since the next fully folding pass is way ahead, after strlen which in the PRs case leads to diagnostics emitted on dead code. The following mitigates the missed expression canonicalization that happens during PHI translation where to be inserted expressions are calculated. It is largely refactoring and eliminating the single use of fully_constant_expression and otherwise leverages the work already done by vn_nary_simplify by updating the NARY with the simplified expression. PR tree-optimization/118817 * tree-ssa-pre.cc (fully_constant_expression): Fold into the single caller. (phi_translate_1): Refactor folded in fully_constant_expression. * tree-ssa-sccvn.cc (vn_nary_simplify): Update the NARY with the simplified expression. * g++.dg/lto/pr118817_0.C: New testcase.