Skip to content

Commit 38678a9

Browse files
authored
[DAG] getCarry - always succeed if we encounter a i1 type during trunc/ext peeling (#169777)
If we are force reconstructing a carry from a raw MVT::i1 type, make sure we don't miss any cases while peeling through trunc/ext chains - check for i1 types at the start of the while loop Fixes #169691
1 parent 76d5dd5 commit 38678a9

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3288,6 +3288,9 @@ static SDValue getAsCarry(const TargetLowering &TLI, SDValue V,
32883288

32893289
// First, peel away TRUNCATE/ZERO_EXTEND/AND nodes due to legalization.
32903290
while (true) {
3291+
if (ForceCarryReconstruction && V.getValueType() == MVT::i1)
3292+
return V;
3293+
32913294
if (V.getOpcode() == ISD::TRUNCATE || V.getOpcode() == ISD::ZERO_EXTEND) {
32923295
V = V.getOperand(0);
32933296
continue;
@@ -3302,9 +3305,6 @@ static SDValue getAsCarry(const TargetLowering &TLI, SDValue V,
33023305
continue;
33033306
}
33043307

3305-
if (ForceCarryReconstruction && V.getValueType() == MVT::i1)
3306-
return V;
3307-
33083308
break;
33093309
}
33103310

llvm/test/CodeGen/X86/addcarry.ll

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,18 +1517,9 @@ define i1 @pr84831(i64 %arg) {
15171517
define void @pr169691(ptr %p0, i64 %implicit, i1 zeroext %carry) {
15181518
; CHECK-LABEL: pr169691:
15191519
; CHECK: # %bb.0:
1520-
; CHECK-NEXT: movq (%rdi), %rax
1521-
; CHECK-NEXT: addq %rsi, %rax
1522-
; CHECK-NEXT: setb %cl
1523-
; CHECK-NEXT: movl %edx, %edx
1524-
; CHECK-NEXT: addq %rax, %rdx
1525-
; CHECK-NEXT: setb %al
1526-
; CHECK-NEXT: orb %cl, %al
1527-
; CHECK-NEXT: movq %rdx, (%rdi)
1528-
; CHECK-NEXT: addq 8(%rdi), %rsi
1529-
; CHECK-NEXT: movzbl %al, %eax
1530-
; CHECK-NEXT: addq %rsi, %rax
1531-
; CHECK-NEXT: movq %rax, 8(%rdi)
1520+
; CHECK-NEXT: addb $-1, %dl
1521+
; CHECK-NEXT: adcq %rsi, (%rdi)
1522+
; CHECK-NEXT: adcq %rsi, 8(%rdi)
15321523
; CHECK-NEXT: retq
15331524
%a0 = load i64, ptr %p0, align 8
15341525
%uaddo0 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %a0, i64 %implicit)

0 commit comments

Comments
 (0)