From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5980 invoked by alias); 14 Jan 2013 19:06:28 -0000 Received: (qmail 5864 invoked by uid 48); 14 Jan 2013 19:06:02 -0000 From: "andi-gcc at firstfloor dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/55966] __atomic_fetch_* generate wrong code for HLE Date: Mon, 14 Jan 2013 19:06:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: andi-gcc at firstfloor dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2013-01/txt/msg01218.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55966 --- Comment #1 from Andi Kleen 2013-01-14 19:06:02 UTC --- Here's a test case. This requires the libstdc++ HLE patch from http://gcc.gnu.org/ml/gcc-patches/2013-01/msg00673.html g++ -std=gnu++0x #include #define ACQ memory_order_acquire | __memory_order_hle_acquire #define REL memory_order_release | __memory_order_hle_release int main() { using namespace std; atomic_ulong au = ATOMIC_VAR_INIT(0); if (!au.fetch_and(1, ACQ)) au.fetch_and(-1, REL); unsigned lock = 0; __atomic_fetch_and(&lock, 1, __ATOMIC_HLE_ACQUIRE|__ATOMIC_ACQUIRE); return 0; } The first fetch_and generates incorrectly: .L2: movq %rax, %rcx movq %rax, %rdx andl $1, %ecx lock; cmpxchgq %rcx, -24(%rsp) jne .L2 The second generates correctly: lock; .byte 0xf3 andq $-1, -24(%rsp) The __atomic_fetch_and generates correctly: lock; .byte 0xf2 andl $1, -28(%rsp) The first fetch_and should generate the same code sequence.