[llvm-bugs] [Bug 47577] New: Atomic operation emits an __atomic_* call rather than an instruction for trivial structure
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Sep 18 04:29:05 PDT 2020
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: unassignedclangbugs at nondot.org
Reporter: antoshkka at gmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200918/67b90286/attachment.html>
More information about the llvm-bugs
mailing list