[llvm] [SelectionDAG] Lowering usub.sat(a, 1) to a - (a != 0) (PR #170076)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 2 21:28:04 PST 2025
================
@@ -10867,6 +10867,16 @@ SDValue TargetLowering::expandAddSubSat(SDNode *Node, SelectionDAG &DAG) const {
assert(VT == RHS.getValueType() && "Expected operands to be the same type");
assert(VT.isInteger() && "Expected operands to be integers");
+ // usub.sat(a, 1) -> a - zext(a != 0)
+ if (Opcode == ISD::USUBSAT && !VT.isVector() && isOneConstant(RHS)) {
+ SDValue Zero = DAG.getConstant(0, dl, VT);
+ EVT BoolVT =
+ getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
+ SDValue IsNonZero = DAG.getSetCC(dl, BoolVT, LHS, Zero, ISD::SETNE);
+ SDValue Subtrahend = DAG.getBoolExtOrTrunc(IsNonZero, dl, VT, BoolVT);
----------------
topperc wrote:
Isn't `Subtrahend` the word for the right hand side of a subtraction?
https://github.com/llvm/llvm-project/pull/170076
More information about the llvm-commits
mailing list