[Bug target/103069] cmpxchg isn't optimized
hjl.tools at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Jan 24 23:49:39 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103069
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Ever confirmed|0 |1
Resolution|FIXED |---
Last reconfirmed| |2022-01-24
--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> ---
nptl/pthread_rwlock_common.c in glibc has:
unsigned int r = atomic_load_relaxed (&rwlock->__data.__readers);
/* Release MO so that subsequent readers or writers synchronize with us. */
while (!atomic_compare_exchange_weak_release
(&rwlock->__data.__readers, &r,
((r ^ PTHREAD_RWLOCK_WRLOCKED)
^ ((r >> PTHREAD_RWLOCK_READER_SHIFT) == 0 ? 0
: PTHREAD_RWLOCK_WRPHASE))))
{
/* TODO Back-off. */
}
-mrelax-cmpxchg-loop -O2 generates:
9240e: 89 c1 mov %eax,%ecx
92410: 31 d2 xor %edx,%edx
92412: c1 e9 03 shr $0x3,%ecx
92415: 0f 95 c2 setne %dl
92418: 31 c2 xor %eax,%edx
9241a: 83 f2 02 xor $0x2,%edx
9241d: f0 41 0f b1 10 lock cmpxchg %edx,(%r8)
92422: 75 ea jne 9240e
<__pthread_rwlock_unlock@GL
IBC_2.2.5+0x10e>
More information about the Gcc-bugs
mailing list