[llvm-bugs] [Bug 37974] New: Opportunity to use BTS instruction instead of cmpxchg
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jun 28 01:55:33 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=37974
Bug ID: 37974
Summary: Opportunity to use BTS instruction instead of cmpxchg
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: david.bolvansky at gmail.com
CC: llvm-bugs at lists.llvm.org
Hello,
Code:
bool foo(int *n, int bit) {
unsigned mask = (1u << bit);
return (__sync_fetch_and_or (n, mask) & mask) != 0;
}
Clang -O3:
foo(int*, int):
mov edx, 1
mov ecx, esi
shl edx, cl
mov eax, dword ptr [rdi]
.LBB0_1:
mov ecx, eax
or ecx, edx
lock cmpxchg dword ptr [rdi], ecx
jne .LBB0_1
test eax, edx
setne al
ret
GCC 7+ generates code using BTS instruction:
foo(int*, int):
lock bts DWORD PTR [rdi], esi
setc al
ret
For more code examples see link:
https://godbolt.org/g/28nkRu
--
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/20180628/a8c0fd28/attachment.html>
More information about the llvm-bugs
mailing list