https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122497
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <[email protected]>: https://gcc.gnu.org/g:7b9d32aa2ffcb5b02643b280c8404020c1e9d6b2 commit r16-4905-g7b9d32aa2ffcb5b02643b280c8404020c1e9d6b2 Author: Andrew Pinski <[email protected]> Date: Thu Oct 30 17:46:54 2025 -0700 sccp: Fix ICE during folding after proping const in some cases [PR122497] In this case we originally had: ``` # g_4.3_21 = PHI <g_4.3_12(3)> _1 = g_4.3_21 + 2; _2 = g_2[_1][g_4.3_21]; ``` SCCP figures out g_4.3_12/g_4.3_21 is 1. final_value_replacement_loop would remove the phi defining _12. do the constant prop of the const 1 but that would ICE as we try to fold the reference `g_2[_1][g_4.3_21]` but that would try to see the range of `_1` but since `_1` refers back to _21 there would be an ICE as the phi is already been removed. The obvious fix is to move the constant prop until after the new statement for _21 is created. This fixes the change done by r14-6010-g2dde9f326ded84 and r14-6114-gde0ab339a79535. This does not fix gcc.dg/graphite/pr82819.c nor tr2/dynamic_bitset/pr92059.cc though; I will look into those issues in a few. Pushed as obvious after bootstrap/test. PR tree-optimization/122497 gcc/ChangeLog: * tree-scalar-evolution.cc (final_value_replacement_loop): Call replace_uses_by only after the replacement statement was created. gcc/testsuite/ChangeLog: * gcc.dg/torture/pr122497-1.c: New test. Signed-off-by: Andrew Pinski <[email protected]>
