From 14d743457c3d5c8154644375bac1094481ab4eaf Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 23 Nov 2021 12:10:03 -0500 Subject: [PATCH] [InstSimplify] add tests for xor logic fold; NFC --- llvm/test/Transforms/InstSimplify/xor.ll | 165 +++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) diff --git a/llvm/test/Transforms/InstSimplify/xor.ll b/llvm/test/Transforms/InstSimplify/xor.ll index 322d948..9202489 100644 --- a/llvm/test/Transforms/InstSimplify/xor.ll +++ b/llvm/test/Transforms/InstSimplify/xor.ll @@ -8,3 +8,168 @@ define i32 @poison(i32 %x) { %v = xor i32 %x, poison ret i32 %v } + +define i4 @xor_and_or_not_commute0(i4 %a, i4 %b) { +; CHECK-LABEL: @xor_and_or_not_commute0( +; CHECK-NEXT: [[AND:%.*]] = and i4 [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor i4 [[A]], -1 +; CHECK-NEXT: [[OR:%.*]] = or i4 [[NOT]], [[B]] +; CHECK-NEXT: [[R:%.*]] = xor i4 [[AND]], [[OR]] +; CHECK-NEXT: ret i4 [[R]] +; + %and = and i4 %a, %b + %not = xor i4 %a, -1 + %or = or i4 %not, %b + %r = xor i4 %and, %or + ret i4 %r +} + +define <2 x i4> @xor_and_or_not_commute1(<2 x i4> %a, <2 x i4> %b) { +; CHECK-LABEL: @xor_and_or_not_commute1( +; CHECK-NEXT: [[AND:%.*]] = and <2 x i4> [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i4> [[A]], +; CHECK-NEXT: [[OR:%.*]] = or <2 x i4> [[NOT]], [[B]] +; CHECK-NEXT: [[R:%.*]] = xor <2 x i4> [[OR]], [[AND]] +; CHECK-NEXT: ret <2 x i4> [[R]] +; + %and = and <2 x i4> %a, %b + %not = xor <2 x i4> %a, + %or = or <2 x i4> %not, %b + %r = xor <2 x i4> %or, %and + ret <2 x i4> %r +} + +define i74 @xor_and_or_not_commute2(i74 %a, i74 %b) { +; CHECK-LABEL: @xor_and_or_not_commute2( +; CHECK-NEXT: [[AND:%.*]] = and i74 [[B:%.*]], [[A:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor i74 [[A]], -1 +; CHECK-NEXT: [[OR:%.*]] = or i74 [[NOT]], [[B]] +; CHECK-NEXT: [[R:%.*]] = xor i74 [[AND]], [[OR]] +; CHECK-NEXT: ret i74 [[R]] +; + %and = and i74 %b, %a + %not = xor i74 %a, -1 + %or = or i74 %not, %b + %r = xor i74 %and, %or + ret i74 %r +} + +define <2 x i4> @xor_and_or_not_commute3(<2 x i4> %a, <2 x i4> %b) { +; CHECK-LABEL: @xor_and_or_not_commute3( +; CHECK-NEXT: [[AND:%.*]] = and <2 x i4> [[B:%.*]], [[A:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i4> [[A]], +; CHECK-NEXT: [[OR:%.*]] = or <2 x i4> [[NOT]], [[B]] +; CHECK-NEXT: [[R:%.*]] = xor <2 x i4> [[OR]], [[AND]] +; CHECK-NEXT: ret <2 x i4> [[R]] +; + %and = and <2 x i4> %b, %a + %not = xor <2 x i4> %a, + %or = or <2 x i4> %not, %b + %r = xor <2 x i4> %or, %and + ret <2 x i4> %r +} + +define i8 @xor_and_or_not_commute4(i8 %a, i8 %b) { +; CHECK-LABEL: @xor_and_or_not_commute4( +; CHECK-NEXT: [[AND:%.*]] = and i8 [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[A]], -1 +; CHECK-NEXT: [[OR:%.*]] = or i8 [[B]], [[NOT]] +; CHECK-NEXT: [[R:%.*]] = xor i8 [[AND]], [[OR]] +; CHECK-NEXT: ret i8 [[R]] +; + %and = and i8 %a, %b + %not = xor i8 %a, -1 + %or = or i8 %b, %not + %r = xor i8 %and, %or + ret i8 %r +} + +define i8 @xor_and_or_not_commute5(i8 %a, i8 %b) { +; CHECK-LABEL: @xor_and_or_not_commute5( +; CHECK-NEXT: [[AND:%.*]] = and i8 [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[A]], -1 +; CHECK-NEXT: [[OR:%.*]] = or i8 [[B]], [[NOT]] +; CHECK-NEXT: [[R:%.*]] = xor i8 [[OR]], [[AND]] +; CHECK-NEXT: ret i8 [[R]] +; + %and = and i8 %a, %b + %not = xor i8 %a, -1 + %or = or i8 %b, %not + %r = xor i8 %or, %and + ret i8 %r +} + +define i8 @xor_and_or_not_commute6(i8 %a, i8 %b) { +; CHECK-LABEL: @xor_and_or_not_commute6( +; CHECK-NEXT: [[AND:%.*]] = and i8 [[B:%.*]], [[A:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[A]], -1 +; CHECK-NEXT: [[OR:%.*]] = or i8 [[B]], [[NOT]] +; CHECK-NEXT: [[R:%.*]] = xor i8 [[AND]], [[OR]] +; CHECK-NEXT: ret i8 [[R]] +; + %and = and i8 %b, %a + %not = xor i8 %a, -1 + %or = or i8 %b, %not + %r = xor i8 %and, %or + ret i8 %r +} + +define i8 @xor_and_or_not_commute7(i8 %a, i8 %b) { +; CHECK-LABEL: @xor_and_or_not_commute7( +; CHECK-NEXT: [[AND:%.*]] = and i8 [[B:%.*]], [[A:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[A]], -1 +; CHECK-NEXT: [[OR:%.*]] = or i8 [[B]], [[NOT]] +; CHECK-NEXT: [[R:%.*]] = xor i8 [[OR]], [[AND]] +; CHECK-NEXT: ret i8 [[R]] +; + %and = and i8 %b, %a + %not = xor i8 %a, -1 + %or = or i8 %b, %not + %r = xor i8 %or, %and + ret i8 %r +} + +define i4 @xor_and_or_not_wrong_val1(i4 %a, i4 %b, i4 %c) { +; CHECK-LABEL: @xor_and_or_not_wrong_val1( +; CHECK-NEXT: [[AND:%.*]] = and i4 [[A:%.*]], [[C:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor i4 [[A]], -1 +; CHECK-NEXT: [[OR:%.*]] = or i4 [[NOT]], [[B:%.*]] +; CHECK-NEXT: [[R:%.*]] = xor i4 [[AND]], [[OR]] +; CHECK-NEXT: ret i4 [[R]] +; + %and = and i4 %a, %c + %not = xor i4 %a, -1 + %or = or i4 %not, %b + %r = xor i4 %and, %or + ret i4 %r +} + +define i4 @xor_and_or_not_wrong_val2(i4 %a, i4 %b, i4 %c) { +; CHECK-LABEL: @xor_and_or_not_wrong_val2( +; CHECK-NEXT: [[AND:%.*]] = and i4 [[C:%.*]], [[B:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor i4 [[A:%.*]], -1 +; CHECK-NEXT: [[OR:%.*]] = or i4 [[NOT]], [[B]] +; CHECK-NEXT: [[R:%.*]] = xor i4 [[AND]], [[OR]] +; CHECK-NEXT: ret i4 [[R]] +; + %and = and i4 %c, %b + %not = xor i4 %a, -1 + %or = or i4 %not, %b + %r = xor i4 %and, %or + ret i4 %r +} + +define <2 x i4> @xor_and_or_not_undef_elt(<2 x i4> %a, <2 x i4> %b) { +; CHECK-LABEL: @xor_and_or_not_undef_elt( +; CHECK-NEXT: [[AND:%.*]] = and <2 x i4> [[B:%.*]], [[A:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i4> [[A]], +; CHECK-NEXT: [[OR:%.*]] = or <2 x i4> [[NOT]], [[B]] +; CHECK-NEXT: [[R:%.*]] = xor <2 x i4> [[OR]], [[AND]] +; CHECK-NEXT: ret <2 x i4> [[R]] +; + %and = and <2 x i4> %b, %a + %not = xor <2 x i4> %a, + %or = or <2 x i4> %not, %b + %r = xor <2 x i4> %or, %and + ret <2 x i4> %r +} -- 2.7.4