@@ -3372,9 +3372,10 @@ static bool isLegalArithImmed(uint64_t C) {
3372
3372
// So, finally, the only LLVM-native comparisons that don't mention C and V
3373
3373
// are SETEQ and SETNE. They're the only ones we can safely use CMN for in
3374
3374
// the absence of information about op2.
3375
- static bool isCMN(SDValue Op, ISD::CondCode CC) {
3375
+ static bool isCMN(SDValue Op, ISD::CondCode CC, SelectionDAG &DAG ) {
3376
3376
return Op.getOpcode() == ISD::SUB && isNullConstant(Op.getOperand(0)) &&
3377
- (CC == ISD::SETEQ || CC == ISD::SETNE);
3377
+ (CC == ISD::SETEQ || CC == ISD::SETNE ||
3378
+ DAG.isKnownNeverZero(Op.getOperand(1)));
3378
3379
}
3379
3380
3380
3381
static SDValue emitStrictFPComparison(SDValue LHS, SDValue RHS, const SDLoc &dl,
@@ -3419,11 +3420,11 @@ static SDValue emitComparison(SDValue LHS, SDValue RHS, ISD::CondCode CC,
3419
3420
// register to WZR/XZR if it ends up being unused.
3420
3421
unsigned Opcode = AArch64ISD::SUBS;
3421
3422
3422
- if (isCMN(RHS, CC)) {
3423
+ if (isCMN(RHS, CC, DAG )) {
3423
3424
// Can we combine a (CMP op1, (sub 0, op2) into a CMN instruction ?
3424
3425
Opcode = AArch64ISD::ADDS;
3425
3426
RHS = RHS.getOperand(1);
3426
- } else if (isCMN(LHS, CC)) {
3427
+ } else if (isCMN(LHS, CC, DAG )) {
3427
3428
// As we are looking for EQ/NE compares, the operands can be commuted ; can
3428
3429
// we combine a (CMP (sub 0, op1), op2) into a CMN instruction ?
3429
3430
Opcode = AArch64ISD::ADDS;
@@ -3527,7 +3528,8 @@ static SDValue emitConditionalComparison(SDValue LHS, SDValue RHS,
3527
3528
}
3528
3529
} else if (RHS.getOpcode() == ISD::SUB) {
3529
3530
SDValue SubOp0 = RHS.getOperand(0);
3530
- if (isNullConstant(SubOp0) && (CC == ISD::SETEQ || CC == ISD::SETNE)) {
3531
+ if (isNullConstant(SubOp0) && (CC == ISD::SETEQ || CC == ISD::SETNE ||
3532
+ DAG.isKnownNeverZero(RHS.getOperand(1)))) {
3531
3533
// See emitComparison() on why we can only do this for SETEQ and SETNE.
3532
3534
Opcode = AArch64ISD::CCMN;
3533
3535
RHS = RHS.getOperand(1);
@@ -3848,7 +3850,7 @@ static SDValue getAArch64Cmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
3848
3850
// can be turned into:
3849
3851
// cmp w12, w11, lsl #1
3850
3852
if (!isa<ConstantSDNode>(RHS) || !isLegalArithImmed(RHS->getAsZExtVal())) {
3851
- SDValue TheLHS = isCMN(LHS, CC) ? LHS.getOperand(1) : LHS;
3853
+ SDValue TheLHS = isCMN(LHS, CC, DAG ) ? LHS.getOperand(1) : LHS;
3852
3854
3853
3855
if (getCmpOperandFoldingProfit(TheLHS) > getCmpOperandFoldingProfit(RHS)) {
3854
3856
std::swap(LHS, RHS);
0 commit comments