From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4A06E3858C3A; Sun, 3 Oct 2021 13:06:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A06E3858C3A From: "hjl.tools at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/102566] [i386] GCC should emit LOCK BTS for simple bit-test-and-set operations with std::atomic Date: Sun, 03 Oct 2021 13:06:07 +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: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: hjl.tools 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: --- 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: Sun, 03 Oct 2021 13:06:07 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102566 --- Comment #2 from H.J. Lu --- This works: [hjl@gnu-cfl-2 pr102566]$ cat y.c=20 #include _Atomic int v; unsigned int foo () { return atomic_fetch_or_explicit (&v, 1, memory_order_relaxed) & 1; } [hjl@gnu-cfl-2 pr102566]$ make y.s /export/build/gnu/tools-build/gcc-gitlab-debug/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/tools-build/gcc-gitlab-debug/build-x86_64-linux/gcc/ -O= 2 -S y.c [hjl@gnu-cfl-2 pr102566]$ cat y.s .file "y.c" .text .p2align 4 .globl foo .type foo, @function foo: .LFB0: .cfi_startproc xorl %eax, %eax lock btsl $0, v(%rip) setc %al ret .cfi_endproc .LFE0: .size foo, .-foo .globl v .bss .align 4 .type v, @object .size v, 4 v: .zero 4 .ident "GCC: (GNU) 12.0.0 20211003 (experimental)" .section .note.GNU-stack,"",@progbits [hjl@gnu-cfl-2 pr102566]$=