[DAGCombine] Add tests for D57317

Add two tests for D57317: Deduplicate addcarry node using commutativity.
https://reviews.llvm.org/D57317
This commit is contained in:
Paweł Bylica 2022-10-01 14:42:30 +00:00 committed by Paweł Bylica
parent 7c0ff64b0f
commit e399c58778
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
1 changed files with 58 additions and 0 deletions

View File

@ -1393,3 +1393,61 @@ define i32 @addcarry_uge(i32 %a, i32 %b, i32 %x, i32 %y) nounwind {
%r = add i32 %s, %z
ret i32 %r
}
define { i64, i64 } @addcarry_commutative_1(i64 %x0, i64 %x1, i64 %y0, i64 %y1) nounwind {
; CHECK-LABEL: addcarry_commutative_1:
; CHECK: # %bb.0:
; CHECK-NEXT: movq %rdi, %rax
; CHECK-NEXT: addq %rdx, %rax
; CHECK-NEXT: movq %rsi, %rax
; CHECK-NEXT: adcq %rcx, %rax
; CHECK-NEXT: addq %rdx, %rdi
; CHECK-NEXT: adcq %rcx, %rsi
; CHECK-NEXT: movq %rsi, %rdx
; CHECK-NEXT: retq
%z0 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %x0, i64 %y0)
%k0 = extractvalue { i64, i1 } %z0, 1
%k0z = zext i1 %k0 to i64
%t1s = add i64 %x1, %y1
%z1s = add i64 %t1s, %k0z
; same as the above, but args swapped
%a1s = add i64 %y1, %x1
%b1s = add i64 %a1s, %k0z
%r0 = insertvalue { i64, i64 } poison, i64 %z1s, 0
%r1 = insertvalue { i64, i64 } %r0, i64 %b1s, 1
ret { i64, i64 } %r1
}
define { i64, i64 } @addcarry_commutative_2(i64 %x0, i64 %x1, i64 %y0, i64 %y1) nounwind {
; CHECK-LABEL: addcarry_commutative_2:
; CHECK: # %bb.0:
; CHECK-NEXT: movq %rdi, %rax
; CHECK-NEXT: addq %rdx, %rax
; CHECK-NEXT: movq %rsi, %rax
; CHECK-NEXT: adcq %rcx, %rax
; CHECK-NEXT: addq %rdx, %rdi
; CHECK-NEXT: adcq %rcx, %rsi
; CHECK-NEXT: movq %rsi, %rdx
; CHECK-NEXT: retq
%z0 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %x0, i64 %y0)
%k0 = extractvalue { i64, i1 } %z0, 1
%k0z = zext i1 %k0 to i64
%t1 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %x1, i64 %y1)
%t1s = extractvalue { i64, i1 } %t1, 0
%z1 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %t1s, i64 %k0z)
%z1s = extractvalue { i64, i1 } %z1, 0
; same as the above, but args swapped
%a1 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %y1, i64 %x1)
%a1s = extractvalue { i64, i1 } %a1, 0
%b1 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %a1s, i64 %k0z)
%b1s = extractvalue { i64, i1 } %b1, 0
%r0 = insertvalue { i64, i64 } poison, i64 %z1s, 0
%r1 = insertvalue { i64, i64 } %r0, i64 %b1s, 1
ret { i64, i64 } %r1
}