llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.05k stars 11.98k forks source link

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

Open zmodem opened 10 years ago

zmodem commented 10 years ago
Bugzilla Link 19164
Version trunk
OS All
CC @rnk,@rotateright

Extended Description

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.

rnk commented 2 years ago

mentioned in issue llvm/llvm-bugzilla-archive#32566

rnk commented 7 years ago

Bug llvm/llvm-bugzilla-archive#32566 has been marked as a duplicate of this bug.