@@ -7118,21 +7118,12 @@ SDValue AArch64TargetLowering::LowerABS(SDValue Op, SelectionDAG &DAG) const {
7118
7118
return LowerToPredicatedOp(Op, DAG, AArch64ISD::ABS_MERGE_PASSTHRU);
7119
7119
7120
7120
SDLoc DL(Op);
7121
- SDValue Val = Op.getOperand(0);
7122
- SDValue Neg = DAG.getNegative(Val, DL, VT);
7123
- SDValue Cmp;
7124
-
7125
- // For abs(sub(lhs, rhs)), we can compare lhs and rhs directly. This allows
7126
- // reusing the subs operation for the calculation and comparison.
7127
- if (Val.getOpcode() == ISD::SUB)
7128
- Cmp = DAG.getNode(AArch64ISD::SUBS, DL, DAG.getVTList(VT, FlagsVT),
7129
- Val.getOperand(0), Val.getOperand(1));
7130
- else
7131
- // Otherwise, compare with zero.
7132
- Cmp = DAG.getNode(AArch64ISD::SUBS, DL, DAG.getVTList(VT, FlagsVT), Val,
7133
- DAG.getConstant(0, DL, VT));
7134
-
7135
- return DAG.getNode(AArch64ISD::CSEL, DL, VT, Val, Neg,
7121
+ SDValue Neg = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT),
7122
+ Op.getOperand(0));
7123
+ // Generate SUBS & CSEL.
7124
+ SDValue Cmp = DAG.getNode(AArch64ISD::SUBS, DL, DAG.getVTList(VT, FlagsVT),
7125
+ Op.getOperand(0), DAG.getConstant(0, DL, VT));
7126
+ return DAG.getNode(AArch64ISD::CSEL, DL, VT, Op.getOperand(0), Neg,
7136
7127
DAG.getConstant(AArch64CC::PL, DL, MVT::i32),
7137
7128
Cmp.getValue(1));
7138
7129
}
@@ -25399,6 +25390,24 @@ static SDValue performCSELCombine(SDNode *N,
25399
25390
}
25400
25391
}
25401
25392
25393
+ // CSEL a, b, cc, SUBS(SUB(x,y), 0) -> CSEL a, b, cc, SUBS(x,y) if cc doesn't
25394
+ // use overflow flags to avoid the comparison with zero.
25395
+ if (Cond.getOpcode() == AArch64ISD::SUBS &&
25396
+ isNullConstant(Cond.getOperand(1))) {
25397
+ SDValue Sub = Cond.getOperand(0);
25398
+ AArch64CC::CondCode CC =
25399
+ static_cast<AArch64CC::CondCode>(N->getConstantOperandVal(2));
25400
+ if (Sub.getOpcode() == ISD::SUB &&
25401
+ (CC == AArch64CC::EQ || CC == AArch64CC::NE || CC == AArch64CC::MI ||
25402
+ CC == AArch64CC::PL)) {
25403
+ SDLoc DL(N);
25404
+ SDValue Subs = DAG.getNode(AArch64ISD::SUBS, DL, Cond->getVTList(),
25405
+ Sub.getOperand(0), Sub.getOperand(1));
25406
+ return DAG.getNode(AArch64ISD::CSEL, DL, N->getVTList(), N->getOperand(0),
25407
+ N->getOperand(1), N->getOperand(2), Subs.getValue(1));
25408
+ }
25409
+ }
25410
+
25402
25411
// CSEL (LASTB P, Z), X, NE(ANY P) -> CLASTB P, X, Z
25403
25412
if (SDValue CondLast = foldCSELofLASTB(N, DAG))
25404
25413
return CondLast;
0 commit comments