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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-12-15
             Status|UNCONFIRMED                 |NEW
          Component|target                      |tree-optimization
           Severity|normal                      |enhancement

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Testcase:

  inline int sign(int x)
  {
    return (x >> 31) | ((unsigned)-x >> 31);
  }
bool f1(int x)
{
    return sign(x) > -1;
}
bool f3(int x)
{
    return (x>>31)+1;
}

  void f1(void);
  void f2(void);
  void f(int x)
  {
    if (sign(x) > -1)
      f1();
    else
      f2();
  }
  void f0(int x)
  {
    if (f3(x))
      f1();
    else
      f2();
  }
  void fn1(int x)
  {
    if (x>0)
      f1();
    else
      f2();
  }



f, f0 and fn1 should all produce the same result on the gimple level but don't.

(x >> 31) | ((unsigned)-x >> 31) is the same as x == 0 ? 0 : -(x < 0) really.
Which we should simplify into.
Though COND_EXPR is not as well handled by the rest of GCC really.

Reply via email to