[llvm-bugs] [Bug 37716] New: Poor codegen with atomics
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Jun 6 13:12:33 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=37716
Bug ID: 37716
Summary: Poor codegen with atomics
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: redbeard0531 at gmail.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
https://godbolt.org/g/QcLkce
#include <atomic>
std::atomic<int> progress{-1};
void combine_writes1() {
// These should be reduced to a single store(0,release),
// At least as long as release-sequence includes same-thread
// relaxed stores. If that is removed, this should just be
// a single relaxed store.
progress.store(0, std::memory_order_relaxed);
progress.store(0, std::memory_order_relaxed);
progress.store(0, std::memory_order_release);
progress.store(0, std::memory_order_release);
progress.store(0, std::memory_order_relaxed);
progress.store(0, std::memory_order_relaxed);
}
void combine_writes2() {
// Ditto above, but should store 5.
progress.store(0, std::memory_order_relaxed);
progress.store(1, std::memory_order_relaxed);
progress.store(2, std::memory_order_release);
progress.store(3, std::memory_order_release);
progress.store(4, std::memory_order_relaxed);
progress.store(5, std::memory_order_relaxed);
}
void combine_loads() {
// These should be reduced to either a single acquire-load
// or an acquire fence.
progress.load(std::memory_order_relaxed);
progress.load(std::memory_order_relaxed);
progress.load(std::memory_order_acquire);
progress.load(std::memory_order_acquire);
progress.load(std::memory_order_relaxed);
progress.load(std::memory_order_relaxed);
}
combine_writes1(): # @combine_writes1()
mov dword ptr [rip + progress], 0
mov dword ptr [rip + progress], 0
mov dword ptr [rip + progress], 0
mov dword ptr [rip + progress], 0
mov dword ptr [rip + progress], 0
mov dword ptr [rip + progress], 0
ret
combine_writes2(): # @combine_writes2()
mov dword ptr [rip + progress], 0
mov dword ptr [rip + progress], 1
mov dword ptr [rip + progress], 2
mov dword ptr [rip + progress], 3
mov dword ptr [rip + progress], 4
mov dword ptr [rip + progress], 5
ret
combine_loads(): # @combine_loads()
mov eax, dword ptr [rip + progress]
mov eax, dword ptr [rip + progress]
mov eax, dword ptr [rip + progress]
mov eax, dword ptr [rip + progress]
mov eax, dword ptr [rip + progress]
mov eax, dword ptr [rip + progress]
ret
progress:
.long 4294967295 # 0xffffffff
Possibly related to https://bugs.llvm.org/show_bug.cgi?id=37690
--
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/20180606/3a650510/attachment-0001.html>
More information about the llvm-bugs
mailing list