Skip to content

Commit 168f43e

Browse files
committed
[SelectionDAG] Prevent combination on inconsistent type in combineCarryDiamond
1 parent bf7f62a commit 168f43e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3442,6 +3442,9 @@ static SDValue combineCarryDiamond(SelectionDAG &DAG, const TargetLowering &TLI,
34423442
return SDValue();
34433443
if (Opcode != ISD::UADDO && Opcode != ISD::USUBO)
34443444
return SDValue();
3445+
// Guarantee identical type of CarryOut
3446+
if (N->getValueType(0) != Carry0.getValue(1).getValueType())
3447+
return SDValue();
34453448

34463449
// Canonicalize the add/sub of A and B (the top node in the above ASCII art)
34473450
// as Carry0 and the add/sub of the carry in as Carry1 (the middle node).

llvm/test/CodeGen/X86/addcarry.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,3 +1490,26 @@ define { i64, i64 } @addcarry_commutative_2(i64 %x0, i64 %x1, i64 %y0, i64 %y1)
14901490
%r1 = insertvalue { i64, i64 } %r0, i64 %b1s, 1
14911491
ret { i64, i64 } %r1
14921492
}
1493+
1494+
define i1 @pr84831(i64 %0) {
1495+
; CHECK-LABEL: pr84831:
1496+
; CHECK: # %bb.0:
1497+
; CHECK-NEXT: testq %rdi, %rdi
1498+
; CHECK-NEXT: setne %al
1499+
; CHECK-NEXT: xorl %ecx, %ecx
1500+
; CHECK-NEXT: addb $-1, %al
1501+
; CHECK-NEXT: adcq $1, %rcx
1502+
; CHECK-NEXT: setb %al
1503+
; CHECK-NEXT: retq
1504+
%2 = icmp ult i64 0, %0
1505+
%3 = add i64 0, 1
1506+
%4 = icmp ult i64 %3, 0
1507+
%5 = zext i1 %2 to i64
1508+
%6 = add i64 %3, %5
1509+
%7 = icmp ult i64 %6, %3
1510+
%8 = zext i1 %4 to i63
1511+
%9 = zext i1 %7 to i63
1512+
%new0 = or i63 %8, %9
1513+
%last = trunc i63 %new0 to i1
1514+
ret i1 %last
1515+
}

0 commit comments

Comments
 (0)