This is a patch to X86TargetLowering::LowerToBT() which was hashed over on the Developers list with Intel concurring. I'm finally figuring out Phabricator and I expect a few more problems there.
bt_pat generates the BT instruction for X86 bit testing in cases where code size is important. It checks whether the -Oz (optimize for size) flag is set or whether the containing function's PGO cold attribute is set. If either are true it emits BT for tests of bits 8-31 instead of TEST. Previously, TEST was always used for bits 0-31 and BT was always used for bits 32-63.
Since the BT instruction is 16b smaller than TEST for the bits 8-31 case, 32b vs 48b, and not irredeemably slower, it makes sense to use BT in cases where size matters.
Similar logic is possible for BTC and BTS. However, LowerToBTC and LowerToBTS would need to be written and used and that's a larger patch.