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: [email protected]
          Reporter: [email protected]
                CC: [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to