From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 124183858C52; Fri, 3 Feb 2023 16:14:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 124183858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675440895; bh=vU02V7Iv5YUbU4S6d3sEHrMlyvJZXRbhHiwIQ0lYzNk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=w8LpXDjKAExNGo5lIhkrXg6FCDuyyk4kQhHe0+GPo4IrLWfgi9qmA/CloYfLPiJAe +AKuhaZCHwBIvPCM3Ut094R2z6FkH+337JR7McxTYaNxHOxwz7sgHb4jFeScFt1rWO iw+bQZtXrzkRDbBOeLICvarmct2q6/nJlM6oRsx8= From: "ktkachov at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/108659] Suboptimal 128 bit atomics codegen on AArch64 and x64 Date: Fri, 03 Feb 2023 16:14:54 +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.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ktkachov at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108659 ktkachov at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ktkachov at gcc dot gnu.org --- Comment #2 from ktkachov at gcc dot gnu.org --- (In reply to Niall Douglas from comment #0) > Related: > - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D80878 > - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94649 > - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104688 >=20 > I got bitten by this again, latest GCC still does not emit single > instruction 128 bit atomics, even when the -march is easily new enough. H= ere > is a godbolt comparing latest MSVC, latest GCC and latest clang for the > skylake-avx512 architecture, which unquestionably supports cmpxchg16b. On= ly > clang emits the single instruction atomic: >=20 > https://godbolt.org/z/EnbeeW4az >=20 > I'm gathering from the issue comments and from the comments at > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104688 that you're going to > wait for AMD to guarantee atomicity of SSE instructions before changing t= he > codegen here, which makes sense. However I also wanted to raise potential= ly > suboptimal 128 bit atomic codegen by GCC for AArch64 as compared to clang: >=20 > https://godbolt.org/z/oKv4o81nv >=20 > GCC emits `dmb` to force a global memory fence, whereas clang does not. >=20 > I think clang is in the right here, the seq_cst atomic semantics are not > supposed to globally memory fence. FWIW, the GCC codegen for aarch64 is at https://godbolt.org/z/qvx9484nY (arm and aarch64 are different targets). It emits a call to libatomic, which for= GCC 13 will use a lockless implementation when possible at runtime, see g:d1288d850944f69a795e4ff444a427eba3fec11b=