Index: X86TargetTransformInfo.cpp =================================================================== --- X86TargetTransformInfo.cpp +++ X86TargetTransformInfo.cpp @@ -1037,9 +1037,14 @@ if (BitSize > 128) return TCC_Free; - if (Imm == 0) + // Don't hoist imm8 + if (Imm.isSignedIntN(8)) return TCC_Free; + // Don't hoist 1 bit masks. They'll probably be used for BT, BTS, BTC. + if (Imm.isPowerOf2()) + return TCC_Free; + // Sign-extend all constants to a multiple of 64-bit. APInt ImmVal = Imm; if (BitSize & 0x3f)