[llvm-bugs] [Bug 28498] New: Passing 0 to __atomic_fetch_add generates mfence instead of lock xadd
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jul 11 03:48:53 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=28498
Bug ID: 28498
Summary: Passing 0 to __atomic_fetch_add generates mfence
instead of lock xadd
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangbugs at nondot.org
Reporter: pierregousseau14 at gmail.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Using clang 3.9 on trunk at r273567
Target: x86_64-unknown-linux-gnu
When passing a '0' constant to '__atomic_fetch_add', an mfence instruction is
generated instead of the usual 'lock xadd' which seems less efficient.
---
#include <stdint.h>
int64_t * g_ptr;
int foo() {
return __atomic_fetch_add(g_ptr, 0, __ATOMIC_RELAXED);
}
---
clang -O3 -S test.c
Generates:
movq %rdi, -8(%rsp)
movq g_ptr(%rip), %rax
mfence
movq (%rax), %rax
retq
Using gcc:
movq g_ptr(%rip), %rdx
movq %rdi, -8(%rsp)
xorl %eax, %eax
lock xaddq %rax, (%rdx)
ret
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160711/c9a20b0e/attachment.html>
More information about the llvm-bugs
mailing list