[llvm-bugs] [Bug 37557] New: Suboptimal atomic_fetch_add
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue May 22 19:48:03 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=37557
Bug ID: 37557
Summary: Suboptimal atomic_fetch_add
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: C
Assignee: unassignedbugs at nondot.org
Reporter: nruslan_devel at yahoo.com
CC: llvm-bugs at lists.llvm.org
Consider the following example:
#include <stdatomic.h>
int func(_Atomic(unsigned long) * obj, unsigned long a)
{
return atomic_fetch_add(obj, a) == -a;
}
Basically, it suffices to use 'lock add' and check whether ZF flag is set.
However, the following code (that uses xadd) is generated (-O2):
func: # @func
.cfi_startproc
# %bb.0:
movq %rsi, %rcx
lock xaddq %rcx, (%rdi)
xorl %eax, %eax
addq %rsi, %rcx
sete %al
retq
--
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/20180523/f2868a87/attachment.html>
More information about the llvm-bugs
mailing list