Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

__sync_fetch_and_or with power-of-two argument should generate "lock bts" code #19163

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR19164
Status NEW
Importance P normal
Reported by Hans Wennborg (hans@chromium.org)
Reported on 2014-03-17 12:48:47 -0700
Last modified on 2017-05-26 15:17:19 -0700
Version trunk
Hardware PC All
CC llvm-bugs@lists.llvm.org, rnk@google.com, spatel+llvm@rotateright.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
For

unsigned f(unsigned *addr) {
  return __sync_fetch_and_or(addr, 1 << 7) & (1 << 7);
}

We currently generate:

f:
        movl    (%rdi), %eax
.LBB0_1:
        movl    $128, %ecx
        orl     %eax, %ecx
        lock
        cmpxchgl        %ecx, (%rdi)
        jne     .LBB0_1
        andl    $128, %eax
        retq

It would be cool if we could recognize that the read-modify-write we're doing
here is actually bit-test-and-set, which can be done with the bts instruction.
Quuxplusone commented 7 years ago

_Bug 32566 has been marked as a duplicate of this bug._