https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94893

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-04-26
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Note the original code does have one slight undefined case, when x is INT_MIN
but that can be fixed by casting to unsigned before doing the negate of x.
That is:
inline int sign(int x)
{
    return (x >> 31) | (-(unsigned)x >> 31);
}

---- CUT ----
Matching this:
  _1 = x_5(D) >> 31;
  x.0_2 = (unsigned int) x_5(D);
  _3 = -x.0_2;
  _4 = _3 >> 31;
  _8 = (int) _4;
  _6 = _1 | _8;

Into:
t = (int)(x > 0);
result = x < 0 ? - 1 : t;
Might not be the best thing.

Reply via email to