https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94893
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot
gnu.org
Status|NEW |ASSIGNED
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> Note we also don't optimize:
>
> inline int sign1(int x)
> {
> return (x < 0 ? -1 : 0) | (x > 0 ? 1 : 0);
> }
> bool f1(int x)
> {
> return sign1(x) < 1;
> }
>
> To be just `x <= 0`
That is because forwprop leaves assignments that are not used anywhere still.
after dce7:
```
if (x_2(D) < 0)
goto <bb 4>; [41.00%]
else
goto <bb 3>; [59.00%]
<bb 3> [local count: 633507680]:
_7 = x_2(D) != 0;
_8 = (int) _7;
_5 = _8 ^ 1;
_10 = (bool) _5;
<bb 4> [local count: 1073741824]:
# prephitmp_11 = PHI <1(2), _10(3)>
```
After frowprop4:
```
if (x_2(D) < 0)
goto <bb 4>; [41.00%]
else
goto <bb 3>; [59.00%]
<bb 3> [local count: 633507680]:
_7 = x_2(D) != 0;
_8 = (int) _7;
_3 = x_2(D) == 0;
_5 = (int) _3;
<bb 4> [local count: 1073741824]:
# prephitmp_11 = PHI <1(2), _3(3)>
```
If those statements were removed then phiopt4 would be able to optimize
prephitmp_11 to: `(x_2(D) < 0) | (x_2(D) == 0)` which simplifies to `x_2(D) <=
0` .
Let me look into the forwprop issue here.
As for the original issue:
x.0_5 = (unsigned int) x_2(D);
_6 = -x.0_5;
_7 = _6 >> 31;
_8 = (int) _7;
We have a pattern for basically this:
/* Fold (-x >> C) into -(x > 0) where C = precision(type) - 1. */
But only for !TYPE_UNSIGNED here. we can do it for unsigned where we just get x
> 0 instead.