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: unassignedb...@nondot.org
Reporter: david.bolvan...@gmail.com
CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs