https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122497
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Before:
```
<bb 2> [local count: 118111600]:
g_4.3_11 = g_4;
if (g_4.3_11 != 0)
goto <bb 6>; [89.00%]
else
goto <bb 5>; [11.00%]
<bb 6> [local count: 105119324]:
<bb 3> [local count: 955630224]:
# g_4.3_12 = PHI <_4(7), g_4.3_11(6)>
_4 = g_4.3_12 + -1;
if (_4 != 0)
goto <bb 7>; [89.00%]
else
goto <bb 4>; [11.00%]
<bb 7> [local count: 850510900]:
goto <bb 3>; [100.00%]
<bb 4> [local count: 105119324]:
# _22 = PHI <_4(3)>
# g_4.3_21 = PHI <g_4.3_12(3)>
_1 = g_4.3_21 + 2;
_2 = g_2[_1][g_4.3_21];
_3 = (int) _2;
g_5_lsm.7_16 = _3;
g_4_lsm.8_17 = _22;
g_5 = g_5_lsm.7_16;
g_4 = g_4_lsm.8_17;
```
Then we figure out _22 is 0.
And replace it:
_22 = 0;
And then we figure out g_4.3_21 is 1 and try to replace it. And we remove the
phi before we start replacing.
So things go down here from there.
```
<bb 4> [local count: 105119324]:
_22 = 0;
_1 = g_4.3_21 + 2;
_2 = g_2[_1][1]; // We try to fold this and we already removed the PHI
_3 = (int) _2;
g_5_lsm.7_16 = _3;
g_4_lsm.8_17 = 0;
g_5 = g_5_lsm.7_16;
g_4 = g_4_lsm.8_17;
```
This looks like a latent bug in SCCP in the order of things before r16-4739.