@@ -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
}
@@ -25479,6 +25470,24 @@ static SDValue performCSELCombine(SDNode *N,
25479
25470
}
25480
25471
}
25481
25472
25473
+ // CSEL a, b, cc, SUBS(SUB(x,y), 0) -> CSEL a, b, cc, SUBS(x,y) if cc doesn't
25474
+ // use overflow flags to avoid the comparison with zero.
25475
+ if (Cond.getOpcode() == AArch64ISD::SUBS &&
25476
+ isNullConstant(Cond.getOperand(1))) {
25477
+ SDValue Sub = Cond.getOperand(0);
25478
+ AArch64CC::CondCode CC =
25479
+ static_cast<AArch64CC::CondCode>(N->getConstantOperandVal(2));
25480
+ if (Sub.getOpcode() == ISD::SUB &&
25481
+ (CC == AArch64CC::EQ || CC == AArch64CC::NE || CC == AArch64CC::MI ||
25482
+ CC == AArch64CC::PL)) {
25483
+ SDLoc DL(N);
25484
+ SDValue Subs = DAG.getNode(AArch64ISD::SUBS, DL, Cond->getVTList(),
25485
+ Sub.getOperand(0), Sub.getOperand(1));
25486
+ return DAG.getNode(AArch64ISD::CSEL, DL, N->getVTList(), N->getOperand(0),
25487
+ N->getOperand(1), N->getOperand(2), Subs.getValue(1));
25488
+ }
25489
+ }
25490
+
25482
25491
// CSEL (LASTB P, Z), X, NE(ANY P) -> CLASTB P, X, Z
25483
25492
if (SDValue CondLast = foldCSELofLASTB(N, DAG))
25484
25493
return CondLast;
0 commit comments