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

--- Comment #32 from Hongtao.liu <crazylht at gmail dot com> ---
(In reply to Marko Mäkelä from comment #31)
> Much of this seems to work in GCC 12.2.0 as well as in clang++-15. For clang
> there is a related ticket https://github.com/llvm/llvm-project/issues/37322
> 
> I noticed a missed optimization in both g++-12 and clang++-15: Some
> operations involving bit 31 degrade to loops around lock cmpxchg. I compiled
31 is sign bit, and  c = a & 1U << 31; c == 0 is optimized to (sign int)a >= 0.
The optimization we did in optimize_atomic_bit_test_and is supposed to match a
& 1U << 31, and it failed. I guess it could be extend to match (sign int)a >= 0
when mask is 1U << 31.

 7  <D.2055>:
 8  <D.2054>:
 9  _1 = __atomic_fetch_or_4 (v, 2147483648, 0);
10  _2 = (signed int) _1;
11  if (_2 >= 0) goto <D.2055>; else goto <D.2053>;
12  <D.2053>:
13  return;
14}
15

Reply via email to