[llvm] [X86] Convert lshr(x, BW-1) -> and(x, 1) iff x is allsignbits (PR #83596)

via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 1 09:32:43 PST 2024


================
@@ -29006,6 +29007,12 @@ static SDValue LowerShiftByScalarImmediate(SDValue Op, SelectionDAG &DAG,
       Op.getOpcode() == ISD::SRA)
     return ArithmeticShiftRight64(ShiftAmt);
 
+  // If we're right logical shifting the MSB to LSB of an all-signbits value
+  // then we can just perform as a mask.
+  if (Op.getOpcode() == ISD::SRL && ShiftAmt == (EltSizeInBits - 1))
+    if (DAG.ComputeNumSignBits(R) == EltSizeInBits)
----------------
goldsteinn wrote:

We could handle any shift amount, because we are essentially just extracting a mask. How about drop the `ShiftAmt` check and return:
`DAG.getNode(ISD::AND, ..., DAG.getConstant(APInt::getLowBitsSet(bitwidth, bitwidth-ShiftAmount)))`?

https://github.com/llvm/llvm-project/pull/83596


More information about the llvm-commits mailing list