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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|108847                      |

--- Comment #14 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually I take back on what is going on those 3. But I will be looking into
it.


  x.0_1 = (signed long) x_4(D);
  _2 = x.0_1 >> 31;
  _3 = (unsigned char) _2;
  _5 = _3 & 1;

That is what is causing arithmetic shift but we only need the first bit in the
end.
If we optimized that to:
  x.0_1 = (unsigned long) x_4(D);
  _2 = x.0_1 >> 31;
  _3 = (unsigned char) _2;
  _5 = _3 & 1;

similar to:
uint8_t cset_32bit31_1 (uint32_t x)
{
    if (x & (1ull<<31))
      return 1;
  return 0;
}

Then there is still an issue. I have some ideas of how to handling the first
case but I might need a few weeks.

Note GCC 14 code generation here is similar now to GCC 4.5.x so that is the
good news that this part is not a regression.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108847
[Bug 108847] unnecessary bitwise AND on boolean types and shifting of the
"sign" bit

Reply via email to