https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122734
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Version|16.0 |unknown
Priority|P2 |P3
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
here is a C testcase:
```
int foo1(int **as, int **ae, int **is, int **ie)
{
int sum = 0;
for (long i = 0;
i < ({
long t = (*ie-*is);
if (t<0)__builtin_unreachable();
t;
});
i++) {
long s_a = *ae-*as;
if (s_a < 0) __builtin_unreachable();
int t = (*is)[i];
if (t >= s_a) __builtin_trap();
sum += (*as)[t];
}
return sum;
}
```
One issue is ch didn't copy this header also.
```
<bb 9> [local count: 1073312329]:
# _36 = PHI <_12(7), 0(2)>
# _37 = PHI <_14(7), _33(2)>
# sum_38 = PHI <sum_26(7), 0(2)>
# i_39 = PHI <i_27(7), 0(2)>
# t_40 = PHI <t_21(7), t_35(2)>
if (_36 < t_40)
goto <bb 3>; [97.25%]
else
goto <bb 10>; [2.75%]
```
Instead it just copied the `if (t<0)__builtin_unreachable();` part of the
header.
That is it is not duplicating all of this:
```
<bb 6> [local count: 1073741824]:
# sum_15 = PHI <0(2), sum_24(5)>
# i_16 = PHI <0(2), i_25(5)>
_11 = (long int) i_16;
_12 = *ie_18(D);
_13 = *is_19(D);
_14 = _12 - _13;
t_20 = _14 /[ex] 4;
if (_14 < 0)
goto <bb 7>; [0.04%]
else
goto <bb 8>; [99.96%]
<bb 7> [local count: 429496]:
__builtin_unreachable ();
<bb 8> [local count: 1073312328]:
if (_11 < t_20)
goto <bb 3>; [96.34%]
else
goto <bb 9>; [3.66%]
```
Only bb 6 here. Even though 6->7 might be an exit edge of the loop, it will be
removed later on and only 8->9 edge is what matters here.
I Thought there is code in copy header that is supposed to handle this but I
can't find it.