https://bugs.llvm.org/show_bug.cgi?id=47577
Bug ID: 47577
Summary: Atomic operation emits an __atomic_* call rather than
an instruction for trivial structure
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangb...@nondot.org
Reporter: antosh...@gmail.com
CC: blitzrak...@gmail.com, dgre...@apple.com,
erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
richard-l...@metafoo.co.uk
Consider the example:
#include <atomic>
struct SleepState {
unsigned short flags;
unsigned short epoch;
};
void test(std::atomic<SleepState>& i) {
SleepState ss{2, 4};
i.compare_exchange_weak(ss, SleepState{4,2});
}
Function test() could be compiled to the following:
test(std::atomic<SleepState>&):
mov eax, 262146
mov edx, 131076
mov DWORD PTR [rsp-4], 262146
lock cmpxchg DWORD PTR [rdi], edx
ret
However clang calls __atomic_compare_exchange when libstdc++ is used:
test(std::atomic<SleepState>&)
push rax
mov rsi, rdi
mov dword ptr [rsp], 262146
mov dword ptr [rsp + 4], 131076
mov rdx, rsp
lea rcx, [rsp + 4]
mov edi, 4
mov r8d, 5
mov r9d, 5
call __atomic_compare_exchange
pop rax
ret
Godbolt playground: https://godbolt.org/z/Eajn57
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs