[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:59:13 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:

It seems to me most of the benefit comes from the improved analysis.
Maybe doing it generally here and undoing in `X86ISelDAGToDAG` if the constant is single use (although I know we don't do a great job tracking that at the moment) would be ideal?

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


More information about the llvm-commits mailing list