[NFC][InstCombine] Add test for `a & ~(a ^ b)` pattern

... which is a variation of `a & (a ^ ~b)` --> a & b`.
A follow-up patch exposes this missing fold, so we need to fix it first.
This commit is contained in:
Roman Lebedev 2020-12-24 13:48:07 +03:00
parent da4c7e15df
commit 1fda23367d
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
1 changed files with 47 additions and 0 deletions

View File

@ -96,6 +96,53 @@ define i32 @and_xor_not_common_op(i32 %a, i32 %b) {
ret i32 %t4
}
; a & (a ^ ~b) --> a & b
define i32 @and_xor_not_common_op_extrause(i32 %a, i32 %b, i32* %dst) {
; CHECK-LABEL: @and_xor_not_common_op_extrause(
; CHECK-NEXT: [[B2:%.*]] = xor i32 [[B:%.*]], -1
; CHECK-NEXT: store i32 [[B2]], i32* [[DST:%.*]], align 4
; CHECK-NEXT: [[T4:%.*]] = and i32 [[A:%.*]], [[B]]
; CHECK-NEXT: ret i32 [[T4]]
;
%b2 = xor i32 %b, -1
store i32 %b2, i32* %dst
%t2 = xor i32 %a, %b2
%t4 = and i32 %t2, %a
ret i32 %t4
}
; a & ~(a ^ b) --> a & b
define i32 @and_not_xor_common_op(i32 %a, i32 %b) {
; CHECK-LABEL: @and_not_xor_common_op(
; CHECK-NEXT: [[B2:%.*]] = xor i32 [[B:%.*]], [[A:%.*]]
; CHECK-NEXT: [[T2:%.*]] = xor i32 [[B2]], -1
; CHECK-NEXT: [[T4:%.*]] = and i32 [[T2]], [[A]]
; CHECK-NEXT: ret i32 [[T4]]
;
%b2 = xor i32 %b, %a
%t2 = xor i32 %b2, -1
%t4 = and i32 %t2, %a
ret i32 %t4
}
declare i32 @gen32()
define i32 @and_not_xor_common_op_commutative(i32 %b) {
; CHECK-LABEL: @and_not_xor_common_op_commutative(
; CHECK-NEXT: [[A:%.*]] = call i32 @gen32()
; CHECK-NEXT: [[B2:%.*]] = xor i32 [[A]], [[B:%.*]]
; CHECK-NEXT: [[T2:%.*]] = xor i32 [[B2]], -1
; CHECK-NEXT: [[T4:%.*]] = and i32 [[A]], [[T2]]
; CHECK-NEXT: ret i32 [[T4]]
;
%a = call i32 @gen32()
%b2 = xor i32 %a, %b ; swapped order
%t2 = xor i32 %b2, -1
%t4 = and i32 %a, %t2 ; swapped order
ret i32 %t4
}
; rdar://10770603
; (x & y) | (x ^ y) -> x | y