[InstCombine] add tests for DeMorgan with reassociation; NFC

These are direct mutations of the tests added for D112108 -
we should handle the sibling folds for 'or'.
This commit is contained in:
Sanjay Patel 2021-10-21 10:07:01 -04:00
parent 88303693ce
commit 6b560a8e23
1 changed files with 95 additions and 1 deletions

View File

@ -1,6 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
declare void @use(i32)
; a & (a ^ b) --> a & ~b
define i32 @and_xor_common_op(i32 %pa, i32 %pb) {
@ -569,7 +571,6 @@ define i32 @not_and_and_not_commute1(i32 %a, i32 %b, i32 %c) {
; ~c & (a & ~b) --> a & ~(b | c)
declare void @use(i32)
define i32 @not_and_and_not_commute2_extra_not_use(i32 %a0, i32 %b, i32 %c) {
; CHECK-LABEL: @not_and_and_not_commute2_extra_not_use(
; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]]
@ -607,3 +608,96 @@ define i32 @not_and_and_not_extra_and1_use(i32 %a0, i32 %b, i32 %c) {
call void @use(i32 %and1)
ret i32 %and2
}
; (a | ~b) | ~c --> a | ~(b & c)
define i32 @not_or_or_not(i32 %a0, i32 %b, i32 %c) {
; CHECK-LABEL: @not_or_or_not(
; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]]
; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[B:%.*]], -1
; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[C:%.*]], -1
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[A]], [[NOT1]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[NOT2]]
; CHECK-NEXT: ret i32 [[OR2]]
;
%a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization
%not1 = xor i32 %b, -1
%not2 = xor i32 %c, -1
%or1 = or i32 %a, %not1
%or2 = or i32 %or1, %not2
ret i32 %or2
}
define <2 x i6> @not_or_or_not_2i6(<2 x i6> %a0, <2 x i6> %b, <2 x i6> %c) {
; CHECK-LABEL: @not_or_or_not_2i6(
; CHECK-NEXT: [[A:%.*]] = sdiv <2 x i6> <i6 3, i6 3>, [[A0:%.*]]
; CHECK-NEXT: [[NOT1:%.*]] = xor <2 x i6> [[B:%.*]], <i6 -1, i6 -1>
; CHECK-NEXT: [[NOT2:%.*]] = xor <2 x i6> [[C:%.*]], <i6 -1, i6 undef>
; CHECK-NEXT: [[OR1:%.*]] = or <2 x i6> [[A]], [[NOT1]]
; CHECK-NEXT: [[OR2:%.*]] = or <2 x i6> [[OR1]], [[NOT2]]
; CHECK-NEXT: ret <2 x i6> [[OR2]]
;
%a = sdiv <2 x i6> <i6 3, i6 3>, %a0 ; thwart complexity-based canonicalization
%not1 = xor <2 x i6> %b, <i6 -1, i6 -1>
%not2 = xor <2 x i6> %c, <i6 -1, i6 undef>
%or1 = or <2 x i6> %a, %not1
%or2 = or <2 x i6> %or1, %not2
ret <2 x i6> %or2
}
; (~b | a) | ~c --> a | ~(b & c)
define i32 @not_or_or_not_commute1(i32 %a, i32 %b, i32 %c) {
; CHECK-LABEL: @not_or_or_not_commute1(
; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[B:%.*]], -1
; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[C:%.*]], -1
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[NOT1]], [[A:%.*]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[NOT2]]
; CHECK-NEXT: ret i32 [[OR2]]
;
%not1 = xor i32 %b, -1
%not2 = xor i32 %c, -1
%or1 = or i32 %not1, %a
%or2 = or i32 %or1, %not2
ret i32 %or2
}
; ~c | (a | ~b) --> a | ~(b & c)
define i32 @not_or_or_not_commute2_extra_not_use(i32 %a0, i32 %b, i32 %c) {
; CHECK-LABEL: @not_or_or_not_commute2_extra_not_use(
; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]]
; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[B:%.*]], -1
; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[C:%.*]], -1
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[A]], [[NOT1]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[NOT2]]
; CHECK-NEXT: call void @use(i32 [[NOT2]])
; CHECK-NEXT: ret i32 [[OR2]]
;
%a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization
%not1 = xor i32 %b, -1
%not2 = xor i32 %c, -1
%or1 = or i32 %a, %not1
%or2 = or i32 %not2, %or1
call void @use(i32 %not2)
ret i32 %or2
}
define i32 @not_or_or_not_extra_or1_use(i32 %a0, i32 %b, i32 %c) {
; CHECK-LABEL: @not_or_or_not_extra_or1_use(
; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]]
; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[B:%.*]], -1
; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[C:%.*]], -1
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[A]], [[NOT1]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[NOT2]]
; CHECK-NEXT: call void @use(i32 [[OR1]])
; CHECK-NEXT: ret i32 [[OR2]]
;
%a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization
%not1 = xor i32 %b, -1
%not2 = xor i32 %c, -1
%or1 = or i32 %a, %not1
%or2 = or i32 %or1, %not2
call void @use(i32 %or1)
ret i32 %or2
}