[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


            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


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]
  mov ecx, eax
  or ecx, edx
  lock cmpxchg dword ptr [rdi], ecx
  jne .LBB0_1
  test eax, edx
  setne al

GCC 7+ generates code using BTS instruction:
foo(int*, int):
  lock bts DWORD PTR [rdi], esi
  setc al

For more code examples see link:

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