@@ -3394,9 +3394,10 @@ static bool isLegalArithImmed(uint64_t C) {
3394
3394
// So, finally, the only LLVM-native comparisons that don't mention C and V
3395
3395
// are SETEQ and SETNE. They're the only ones we can safely use CMN for in
3396
3396
// the absence of information about op2.
3397
- static bool isCMN(SDValue Op, ISD::CondCode CC) {
3397
+ static bool isCMN(SDValue Op, ISD::CondCode CC, SelectionDAG &DAG ) {
3398
3398
return Op.getOpcode() == ISD::SUB && isNullConstant(Op.getOperand(0)) &&
3399
- (CC == ISD::SETEQ || CC == ISD::SETNE);
3399
+ (CC == ISD::SETEQ || CC == ISD::SETNE ||
3400
+ DAG.isKnownNeverZero(Op.getOperand(1)));
3400
3401
}
3401
3402
3402
3403
static SDValue emitStrictFPComparison(SDValue LHS, SDValue RHS, const SDLoc &dl,
@@ -3441,11 +3442,11 @@ static SDValue emitComparison(SDValue LHS, SDValue RHS, ISD::CondCode CC,
3441
3442
// register to WZR/XZR if it ends up being unused.
3442
3443
unsigned Opcode = AArch64ISD::SUBS;
3443
3444
3444
- if (isCMN(RHS, CC)) {
3445
+ if (isCMN(RHS, CC, DAG )) {
3445
3446
// Can we combine a (CMP op1, (sub 0, op2) into a CMN instruction ?
3446
3447
Opcode = AArch64ISD::ADDS;
3447
3448
RHS = RHS.getOperand(1);
3448
- } else if (isCMN(LHS, CC)) {
3449
+ } else if (isCMN(LHS, CC, DAG )) {
3449
3450
// As we are looking for EQ/NE compares, the operands can be commuted ; can
3450
3451
// we combine a (CMP (sub 0, op1), op2) into a CMN instruction ?
3451
3452
Opcode = AArch64ISD::ADDS;
@@ -3549,7 +3550,8 @@ static SDValue emitConditionalComparison(SDValue LHS, SDValue RHS,
3549
3550
}
3550
3551
} else if (RHS.getOpcode() == ISD::SUB) {
3551
3552
SDValue SubOp0 = RHS.getOperand(0);
3552
- if (isNullConstant(SubOp0) && (CC == ISD::SETEQ || CC == ISD::SETNE)) {
3553
+ if (isNullConstant(SubOp0) && (CC == ISD::SETEQ || CC == ISD::SETNE ||
3554
+ DAG.isKnownNeverZero(RHS.getOperand(1)))) {
3553
3555
// See emitComparison() on why we can only do this for SETEQ and SETNE.
3554
3556
Opcode = AArch64ISD::CCMN;
3555
3557
RHS = RHS.getOperand(1);
@@ -3870,7 +3872,7 @@ static SDValue getAArch64Cmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
3870
3872
// can be turned into:
3871
3873
// cmp w12, w11, lsl #1
3872
3874
if (!isa<ConstantSDNode>(RHS) || !isLegalArithImmed(RHS->getAsZExtVal())) {
3873
- SDValue TheLHS = isCMN(LHS, CC) ? LHS.getOperand(1) : LHS;
3875
+ SDValue TheLHS = isCMN(LHS, CC, DAG ) ? LHS.getOperand(1) : LHS;
3874
3876
3875
3877
if (getCmpOperandFoldingProfit(TheLHS) > getCmpOperandFoldingProfit(RHS)) {
3876
3878
std::swap(LHS, RHS);
0 commit comments