[llvm] [TargetLowering] Optimize scmp with 0 using (x ashr 31) | (-x shr 31) (PR #205398)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 30 04:37:44 PDT 2026
================
@@ -12563,11 +12563,25 @@ SDValue TargetLowering::expandCMP(SDNode *Node, SelectionDAG &DAG) const {
unsigned Opcode = Node->getOpcode();
SDValue LHS = Node->getOperand(0);
SDValue RHS = Node->getOperand(1);
+
EVT VT = LHS.getValueType();
EVT ResVT = Node->getValueType(0);
- EVT BoolVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
SDLoc dl(Node);
+ if (Opcode == ISD::SCMP && isNullConstant(RHS) && preferBitwiseSignum()) {
+ LHS = DAG.getFreeze(LHS);
+ unsigned BitWidth = VT.getScalarSizeInBits();
+ SDValue ShiftAmount = DAG.getShiftAmountConstant(BitWidth - 1, VT, dl);
+ SDValue SignShift = DAG.getNode(ISD::SRA, dl, VT, LHS, ShiftAmount);
+ SDValue NegX =
+ DAG.getNode(ISD::SUB, dl, VT, DAG.getConstant(0, dl, VT), LHS);
----------------
RKSimon wrote:
SDValue NegX = getNegative(LHS, dl, VT);
https://github.com/llvm/llvm-project/pull/205398
More information about the llvm-commits
mailing list