]> git.ipfire.org Git - thirdparty/gcc.git/commit
sccp: Fix ICE during folding after proping const in some cases [PR122497]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Fri, 31 Oct 2025 00:46:54 +0000 (17:46 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Fri, 31 Oct 2025 04:42:09 +0000 (21:42 -0700)
commit7b9d32aa2ffcb5b02643b280c8404020c1e9d6b2
treeb241f08ab0e63cb96cfdd6b9b90e81390323a47d
parent2be505ace7e5e29a29ab53025762cf1a100a6d76
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 <andrew.pinski@oss.qualcomm.com>
gcc/testsuite/gcc.dg/torture/pr122497-1.c [new file with mode: 0644]
gcc/tree-scalar-evolution.cc