Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a0c9845
[X86] Optimized ADD + ADC to ADC
JaydeepChauhan14 Dec 25, 2025
f667556
Merge branch 'main' into optimizeaddwithadc
JaydeepChauhan14 Dec 25, 2025
2a48efd
Addressed the review comments
JaydeepChauhan14 Dec 25, 2025
f68b379
Merge branch 'main' into optimizeaddwithadc
JaydeepChauhan14 Dec 31, 2025
63acd38
Addressed the review comments1
JaydeepChauhan14 Dec 31, 2025
426e499
Updated dyn_cast to cast
JaydeepChauhan14 Jan 1, 2026
f6049c7
Merge branch 'main' into optimizeaddwithadc
JaydeepChauhan14 Jan 2, 2026
fc8e192
Addressed the review comments2
JaydeepChauhan14 Jan 2, 2026
b459a1f
Fixed formatting issue
JaydeepChauhan14 Jan 2, 2026
1572530
Merge branch 'main' into optimizeaddwithadc
JaydeepChauhan14 Jan 3, 2026
e451e86
Addressed the review comments3
JaydeepChauhan14 Jan 3, 2026
d915805
Added precommit tests
JaydeepChauhan14 Feb 11, 2026
c9215c3
Added combine and updated testcase
JaydeepChauhan14 Feb 11, 2026
2bc9500
Merge branch 'main' into optimizeaddwithadc
JaydeepChauhan14 Feb 13, 2026
16de72b
Addressed the review comments3
JaydeepChauhan14 Feb 13, 2026
3c4f127
Merge branch 'main' into optimizeaddwithadc
JaydeepChauhan14 Feb 28, 2026
a7db36b
Addressed the review comments4
JaydeepChauhan14 Feb 28, 2026
5d30f17
Addressed the review comments5
JaydeepChauhan14 Feb 28, 2026
85c8256
Addressed the review comments6
JaydeepChauhan14 Feb 28, 2026
187c4fd
Remove comment
JaydeepChauhan14 Feb 28, 2026
74376bc
Merge branch 'main' into optimizeaddwithadc
JaydeepChauhan14 Mar 10, 2026
e32a1d6
Merge branch 'main' into optimizeaddwithadc
JaydeepChauhan14 Mar 11, 2026
ad98af4
Merge branch 'main' into optimizeaddwithadc
RKSimon Mar 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58164,6 +58164,13 @@ static SDValue combineX86AddSub(SDNode *N, SelectionDAG &DAG,
}
}

// Fold ADD(ADC(Y,0,CF), C) -> ADC(Y, C, CF)
Comment thread
JaydeepChauhan14 marked this conversation as resolved.
Outdated
Comment thread
JaydeepChauhan14 marked this conversation as resolved.
Outdated
Comment thread
JaydeepChauhan14 marked this conversation as resolved.
Outdated
if (!IsSub && LHS.getOpcode() == X86ISD::ADC &&
X86::isZeroNode(LHS.getOperand(1)) && isa<ConstantSDNode>(RHS)) {
Comment thread
JaydeepChauhan14 marked this conversation as resolved.
Outdated
return DAG.getNode(X86ISD::ADC, DL, N->getVTList(), LHS.getOperand(0), RHS,
Comment thread
JaydeepChauhan14 marked this conversation as resolved.
LHS.getOperand(2));
Comment thread
JaydeepChauhan14 marked this conversation as resolved.
}
Comment thread
JaydeepChauhan14 marked this conversation as resolved.

Comment thread
JaydeepChauhan14 marked this conversation as resolved.
Outdated
// TODO: Can we drop the ZeroSecondOpOnly limit? This is to guarantee that the
// EFLAGS result doesn't change.
return combineAddOrSubToADCOrSBB(IsSub, DL, VT, LHS, RHS, DAG,
Expand Down
30 changes: 30 additions & 0 deletions llvm/test/CodeGen/X86/combine-adc.ll
Comment thread
JaydeepChauhan14 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,35 @@ define i32 @adc_merge_sub(i32 %a0) nounwind {
ret i32 %result
}

define i32 @optimize_adc(i32 %0, i32 %1, i32 %2) {
; X86-LABEL: optimize_adc:
; X86: # %bb.0:
; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
; X86-NEXT: cmpl %eax, %ecx
; X86-NEXT: adcl $42, %edx
; X86-NEXT: js .LBB4_2
; X86-NEXT: # %bb.1:
; X86-NEXT: movl %ecx, %eax
; X86-NEXT: .LBB4_2:
; X86-NEXT: retl
;
; X64-LABEL: optimize_adc:
; X64: # %bb.0:
; X64-NEXT: movl %edi, %eax
; X64-NEXT: cmpl %esi, %edi
; X64-NEXT: adcl $42, %edx
; X64-NEXT: cmovsl %esi, %eax
; X64-NEXT: retq
%4 = icmp ult i32 %0, %1
%5 = zext i1 %4 to i32
%6 = add i32 %2, 42
%7 = add i32 %6, %5
%8 = icmp slt i32 %7, 0
%9 = select i1 %8, i32 %1, i32 %0
ret i32 %9
}

declare { i8, i32 } @llvm.x86.addcarry.32(i8, i32, i32)
declare void @use(i8)