https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117123
--- Comment #12 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:c33d8c55a79f08e4a14b4bc601b270268d3c4c89 commit r15-4539-gc33d8c55a79f08e4a14b4bc601b270268d3c4c89 Author: Richard Biener <rguent...@suse.de> Date: Mon Oct 21 14:01:23 2024 +0200 tree-optimization/117123 - missed PHI equivalence in VN Value-numbering can use its set of equivalences to prove that a PHI node with args <a_1, 5, 10> is equal to a_1 iff on the edges with the constants a_1 == 5 and a_1 == 10 hold. This breaks down when the order of PHI args is <5, 10, a_1> as then we drop to VARYING early. The following mitigates this by shuffling a copy of the edge vector to always process a SSA name argument first. Which should also handle the special-case of a two argument <5, a_1> we already had. PR tree-optimization/117123 * tree-ssa-sccvn.cc (visit_phi): First process a non-constant argument edge to handle more equivalences. Remove the two-arg special case. * g++.dg/tree-ssa/pr117123.C: New testcase.