diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -3753,6 +3753,12 @@ return DAG.getNode(ISD::ADD, DL, VT, N1, N0); } + // (sub (subcarry X, 0, Carry), Y) -> (subcarry X, Y, Carry) + if (N0.getOpcode() == ISD::SUBCARRY && isNullConstant(N0.getOperand(1)) && + N0.getResNo() == 0) + return DAG.getNode(ISD::SUBCARRY, DL, N0->getVTList(), + N0.getOperand(0), N1, N0.getOperand(2)); + if (TLI.isOperationLegalOrCustom(ISD::ADDCARRY, VT)) { // (sub Carry, X) -> (addcarry (sub 0, X), 0, Carry) if (SDValue Carry = getAsCarry(TLI, N0)) { diff --git a/llvm/test/CodeGen/X86/pr57576.ll b/llvm/test/CodeGen/X86/pr57576.ll --- a/llvm/test/CodeGen/X86/pr57576.ll +++ b/llvm/test/CodeGen/X86/pr57576.ll @@ -6,8 +6,7 @@ ; CHECK: # %bb.0: ; CHECK-NEXT: movq %rdi, %rax ; CHECK-NEXT: subq %rdx, %rax -; CHECK-NEXT: sbbq $0, %rsi -; CHECK-NEXT: subq %rcx, %rsi +; CHECK-NEXT: sbbq %rcx, %rsi ; CHECK-NEXT: movq %rsi, %rdx ; CHECK-NEXT: retq %5 = zext i64 %1 to i128