[InstCombine] update tests for logic folds to exercise commuted patterns; NFC

This was the intent for D88551.
I also varied the types a bit for extra coverage
and tried to make better test/value names.
This commit is contained in:
Sanjay Patel 2020-10-15 14:35:39 -04:00
parent 224fd6ff48
commit 77fb8cbd60
1 changed files with 52 additions and 58 deletions

View File

@ -1172,76 +1172,70 @@ define i8 @not_ashr_wrong_const(i8 %x) {
ret i8 %r ret i8 %r
} }
; (~A & B) ^ A --> (A | B) ; (~A & B) ^ A --> A | B
; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
define i32 @test52(i32 %p1, i32 %p2) { define <2 x i32> @xor_andn_commute1(<2 x i32> %a, <2 x i32> %b) {
; CHECK-LABEL: @test52( ; CHECK-LABEL: @xor_andn_commute1(
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]] ; CHECK-NEXT: [[NOTA:%.*]] = xor <2 x i32> [[A:%.*]], <i32 -1, i32 -1>
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]] ; CHECK-NEXT: [[R:%.*]] = and <2 x i32> [[NOTA]], [[B:%.*]]
; CHECK-NEXT: [[O:%.*]] = xor i32 [[A]], -1 ; CHECK-NEXT: [[Z:%.*]] = xor <2 x i32> [[R]], [[A]]
; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[O]] ; CHECK-NEXT: ret <2 x i32> [[Z]]
; CHECK-NEXT: [[Z:%.*]] = xor i32 [[R]], [[A]]
; CHECK-NEXT: ret i32 [[Z]]
; ;
%a = udiv i32 42, %p1 %nota = xor <2 x i32> %a, <i32 -1, i32 -1>
%b = udiv i32 42, %p2 %r = and <2 x i32> %nota, %b
%o = xor i32 %a, -1 %z = xor <2 x i32> %r, %a
%r = and i32 %o, %b ret <2 x i32> %z
%z = xor i32 %r, %a
ret i32 %z
} }
; (~B & A) ^ B --> (A | B) ; (B & ~A) ^ A --> A | B
; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
define i32 @test53(i32 %p1, i32 %p2) { define i33 @xor_andn_commute2(i33 %a, i33 %pb) {
; CHECK-LABEL: @test53( ; CHECK-LABEL: @xor_andn_commute2(
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]] ; CHECK-NEXT: [[B:%.*]] = udiv i33 42, [[PB:%.*]]
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]] ; CHECK-NEXT: [[NOTA:%.*]] = xor i33 [[A:%.*]], -1
; CHECK-NEXT: [[O:%.*]] = xor i32 [[B]], -1 ; CHECK-NEXT: [[R:%.*]] = and i33 [[B]], [[NOTA]]
; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], [[O]] ; CHECK-NEXT: [[Z:%.*]] = xor i33 [[R]], [[A]]
; CHECK-NEXT: [[Z:%.*]] = xor i32 [[R]], [[B]] ; CHECK-NEXT: ret i33 [[Z]]
; CHECK-NEXT: ret i32 [[Z]]
; ;
%a = udiv i32 42, %p1 %b = udiv i33 42, %pb ; thwart complexity-based canonicalization
%b = udiv i32 42, %p2 %nota = xor i33 %a, -1
%o = xor i32 %b, -1 %r = and i33 %b, %nota
%r = and i32 %o, %a %z = xor i33 %r, %a
%z = xor i32 %r, %b ret i33 %z
ret i32 %z
} }
define i32 @test54(i32 %p1, i32 %p2) { ; A ^ (~A & B) --> A | B
; CHECK-LABEL: @test54(
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
; CHECK-NEXT: [[O:%.*]] = xor i32 [[A]], -1
; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[O]]
; CHECK-NEXT: [[Z:%.*]] = xor i32 [[R]], [[A]]
; CHECK-NEXT: ret i32 [[Z]]
;
%a = udiv i32 42, %p1
%b = udiv i32 42, %p2
%o = xor i32 %a, -1
%r = and i32 %b, %o
%z = xor i32 %r, %a
ret i32 %z
}
define i32 @test55(i32 %p1, i32 %p2) { define i32 @xor_andn_commute3(i32 %pa, i32 %b) {
; CHECK-LABEL: @test55( ; CHECK-LABEL: @xor_andn_commute3(
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]] ; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[PA:%.*]]
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]] ; CHECK-NEXT: [[NOTA:%.*]] = xor i32 [[A]], -1
; CHECK-NEXT: [[O:%.*]] = xor i32 [[A]], -1 ; CHECK-NEXT: [[R:%.*]] = and i32 [[NOTA]], [[B:%.*]]
; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[O]]
; CHECK-NEXT: [[Z:%.*]] = xor i32 [[A]], [[R]] ; CHECK-NEXT: [[Z:%.*]] = xor i32 [[A]], [[R]]
; CHECK-NEXT: ret i32 [[Z]] ; CHECK-NEXT: ret i32 [[Z]]
; ;
%a = udiv i32 42, %p1 %a = udiv i32 42, %pa ; thwart complexity-based canonicalization
%b = udiv i32 42, %p2 %nota = xor i32 %a, -1
%o = xor i32 %a, -1 %r = and i32 %nota, %b
%r = and i32 %o, %b %z = xor i32 %a, %r
ret i32 %z
}
; A ^ (B & ~A) --> A | B
define i32 @xor_andn_commute4(i32 %pa, i32 %pb) {
; CHECK-LABEL: @xor_andn_commute4(
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[PA:%.*]]
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[PB:%.*]]
; CHECK-NEXT: [[NOTA:%.*]] = xor i32 [[A]], -1
; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[NOTA]]
; CHECK-NEXT: [[Z:%.*]] = xor i32 [[A]], [[R]]
; CHECK-NEXT: ret i32 [[Z]]
;
%a = udiv i32 42, %pa ; thwart complexity-based canonicalization
%b = udiv i32 42, %pb ; thwart complexity-based canonicalization
%nota = xor i32 %a, -1
%r = and i32 %b, %nota
%z = xor i32 %a, %r %z = xor i32 %a, %r
ret i32 %z ret i32 %z
} }