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

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 1 09:52:40 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)
----------------
RKSimon wrote:

In most cases we'd want to avoid the mask load if we can perform an immediate shift.

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


More information about the llvm-commits mailing list