Transform AtomicRMW logic operations to BT{R|C|S} if only changing/testing a single...
authorNoah Goldstein <goldstein.w.n@gmail.com>
Tue, 17 Jan 2023 02:51:08 +0000 (18:51 -0800)
committerNoah Goldstein <goldstein.w.n@gmail.com>
Tue, 17 Jan 2023 06:05:47 +0000 (22:05 -0800)
commit0b74e34938ba6cb89cbd197835219a6970ebaf39
treea0b0134e4f54a2f9ad426b89a9e46d2ad571ae17
parent282d5a5b063e09d059591778dd56ab351130e4d7
Transform AtomicRMW logic operations to BT{R|C|S} if only changing/testing a single bit.

This is essentially expanding on the optimizations added on: D120199
but applies the optimization to cases where the bit being changed /
tested is not am IMM but is a provable power of 2.

The only case currently added for cases like:
`__atomic_fetch_xor(p, 1 << c, __ATOMIC_RELAXED) & (1 << c)`

Which instead of using a `cmpxchg` loop can be done with `btcl; setcc; shl`.

There are still a variety of missed cases that could/should be
addressed in the future. This commit documents many of those
cases with Todos.

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D140939
llvm/include/llvm/IR/IntrinsicsX86.td
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86ISelLowering.h
llvm/lib/Target/X86/X86InstrCompiler.td
llvm/test/CodeGen/X86/atomic-rm-bit-test-64.ll
llvm/test/CodeGen/X86/atomic-rm-bit-test.ll