[llvm] eb1ff70 - [X86] Combine ADC(ADD(X, Y), 0, Carry) -> ADC(X, Y, Carry)
Paweł Bylica via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 25 05:31:47 PST 2022
Author: Pawe Bylica
Date: 2022-02-25T14:31:20+01:00
New Revision: eb1ff70fc5fc166fa67dc1cfd5854fc6f51e0b17
URL: https://github.com/llvm/llvm-project/commit/eb1ff70fc5fc166fa67dc1cfd5854fc6f51e0b17
DIFF: https://github.com/llvm/llvm-project/commit/eb1ff70fc5fc166fa67dc1cfd5854fc6f51e0b17.diff
LOG: [X86] Combine ADC(ADD(X,Y),0,Carry) -> ADC(X,Y,Carry)
Reviewed By: RKSimon
Differential Revision: https://reviews.llvm.org/D120435
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/addcarry.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index e46c4ec9c69f5..1253e5ad73668 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -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();
}
diff --git a/llvm/test/CodeGen/X86/addcarry.ll b/llvm/test/CodeGen/X86/addcarry.ll
index 3d996619c94ba..74ccb7ee486a0 100644
--- a/llvm/test/CodeGen/X86/addcarry.ll
+++ b/llvm/test/CodeGen/X86/addcarry.ll
@@ -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
@@ -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
More information about the llvm-commits
mailing list