From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 106D1385840D; Tue, 15 Feb 2022 08:59:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 106D1385840D From: "wwwhhhyyy333 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/103069] cmpxchg isn't optimized Date: Tue, 15 Feb 2022 08:59:44 +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: wwwhhhyyy333 at gmail dot com X-Bugzilla-Status: NEW 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: 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: Tue, 15 Feb 2022 08:59:45 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103069 --- Comment #11 from Hongyu Wang --- For the case with atomic_compare_exchange_weak_release, it can be expanded = as loop: mov %eax,%r8d and $0xfff80000,%r8d mov (%r8),%rsi <--- load lock first cmp %rsi,%rax <--- compare with expected input jne .L2 <--- lock ne expected lock cmpxchg %r8d,(%rdi) mov %rsi,%rax <--- perform the behavior of failed cmpxchg jne loop But this is not suitable for atomic_compare_exchange_strong, as the document said Unlike atomic_compare_exchange_weak, this strong version is required to alw= ays return true when expected indeed compares equal to the contained object, not allowing spurious failures. If we expand cmpxchg as above, it would result = in spurious failure since the load is not atomic.=20 So for do pd->nextevent =3D __nptl_last_event; while (atomic_compare_and_exchange_bool_acq (&__nptl_last_event, pd, pd->nextevent)); who invokes atomic_compare_exchange_strong we may not simply adjust the expander. It is better to know the call is in loop condition and relax it accordingly.=