Skip to content

Commit

Permalink
[X86] Combine ADC(ADD(X,Y),0,Carry) -> ADC(X,Y,Carry)
Browse files Browse the repository at this point in the history
Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D120435
  • Loading branch information
chfast committed Feb 25, 2022
1 parent a5ee433 commit eb1ff70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 7 additions & 0 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52150,6 +52150,13 @@ static SDValue combineADC(SDNode *N, SelectionDAG &DAG,
return DAG.getNode(X86ISD::ADC, SDLoc(N), VTs, LHS, RHS, Flags);
}

// Fold ADC(ADD(X,Y),0,Carry) -> ADC(X,Y,Carry)
// iff the flag result is dead.
if (LHS.getOpcode() == ISD::ADD && isNullConstant(RHS) &&
!N->hasAnyUseOfValue(1))
return DAG.getNode(X86ISD::ADC, SDLoc(N), N->getVTList(), LHS.getOperand(0),
LHS.getOperand(1), CarryIn);

return SDValue();
}

Expand Down
12 changes: 4 additions & 8 deletions llvm/test/CodeGen/X86/addcarry.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1366,11 +1366,9 @@ define void @add_U256_without_i128_or_recursive(%uint256* sret(%uint256) %0, %ui
define i32 @addcarry_ult(i32 %a, i32 %b, i32 %x, i32 %y) {
; CHECK-LABEL: addcarry_ult:
; CHECK: # %bb.0:
; CHECK-NEXT: # kill: def $esi killed $esi def $rsi
; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
; CHECK-NEXT: leal (%rdi,%rsi), %eax
; CHECK-NEXT: movl %edi, %eax
; CHECK-NEXT: cmpl %ecx, %edx
; CHECK-NEXT: adcl $0, %eax
; CHECK-NEXT: adcl %esi, %eax
; CHECK-NEXT: retq
%s = add i32 %a, %b
%k = icmp ult i32 %x, %y
Expand All @@ -1382,11 +1380,9 @@ define i32 @addcarry_ult(i32 %a, i32 %b, i32 %x, i32 %y) {
define i32 @addcarry_ugt(i32 %a, i32 %b, i32 %x, i32 %y) {
; CHECK-LABEL: addcarry_ugt:
; CHECK: # %bb.0:
; CHECK-NEXT: # kill: def $esi killed $esi def $rsi
; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
; CHECK-NEXT: leal (%rdi,%rsi), %eax
; CHECK-NEXT: movl %edi, %eax
; CHECK-NEXT: cmpl %edx, %ecx
; CHECK-NEXT: adcl $0, %eax
; CHECK-NEXT: adcl %esi, %eax
; CHECK-NEXT: retq
%s = add i32 %a, %b
%k = icmp ugt i32 %x, %y
Expand Down

0 comments on commit eb1ff70

Please sign in to comment.