From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1D9363858004; Mon, 24 Jan 2022 23:49:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D9363858004 From: "hjl.tools at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/103069] cmpxchg isn't optimized Date: Mon, 24 Jan 2022 23:49:39 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hjl.tools at gmail dot com X-Bugzilla-Status: REOPENED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status everconfirmed resolution cf_reconfirmed_on Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jan 2022 23:49:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103069 H.J. Lu changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Ever confirmed|0 |1 Resolution|FIXED |--- Last reconfirmed| |2022-01-24 --- Comment #6 from H.J. Lu --- nptl/pthread_rwlock_common.c in glibc has: unsigned int r =3D 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) =3D=3D 0 ? 0 : PTHREAD_RWLOCK_WRPHASE)))) { /* TODO Back-off. */ }=20=20=20 -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)=20=20=20=20= =20=20=20 92422: 75 ea jne 9240e <__pthread_rwlock_unlock@GL IBC_2.2.5+0x10e>=