[llvm] 4666324 - [InstSimplify] add tests for bitwise logic fold of 'and'; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 6 09:33:06 PDT 2021
Author: Sanjay Patel
Date: 2021-10-06T12:31:25-04:00
New Revision: 4666324f2bbd82b5fb218bef3c41121d5494ff4a
URL: https://github.com/llvm/llvm-project/commit/4666324f2bbd82b5fb218bef3c41121d5494ff4a
DIFF: https://github.com/llvm/llvm-project/commit/4666324f2bbd82b5fb218bef3c41121d5494ff4a.diff
LOG: [InstSimplify] add tests for bitwise logic fold of 'and'; NFC
Added:
Modified:
llvm/test/Transforms/InstSimplify/and.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstSimplify/and.ll b/llvm/test/Transforms/InstSimplify/and.ll
index 6fc319d0be92..4b47f398c129 100644
--- a/llvm/test/Transforms/InstSimplify/and.ll
+++ b/llvm/test/Transforms/InstSimplify/and.ll
@@ -8,3 +8,122 @@ define i32 @poison(i32 %x) {
%v = and i32 %x, poison
ret i32 %v
}
+
+define i8 @or_or_not_commute0(i8 %x, i8 %y) {
+; CHECK-LABEL: @or_or_not_commute0(
+; CHECK-NEXT: [[YNOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[XORY:%.*]] = or i8 [[X:%.*]], [[Y]]
+; CHECK-NEXT: [[XORYNOT:%.*]] = or i8 [[X]], [[YNOT]]
+; CHECK-NEXT: [[AND:%.*]] = and i8 [[XORY]], [[XORYNOT]]
+; CHECK-NEXT: ret i8 [[AND]]
+;
+ %ynot = xor i8 %y, -1
+ %xory = or i8 %x, %y
+ %xorynot = or i8 %x, %ynot
+ %and = and i8 %xory, %xorynot
+ ret i8 %and
+}
+
+define <2 x i5> @or_or_not_commute1(<2 x i5> %x, <2 x i5> %y) {
+; CHECK-LABEL: @or_or_not_commute1(
+; CHECK-NEXT: [[YNOT:%.*]] = xor <2 x i5> [[Y:%.*]], <i5 -1, i5 -1>
+; CHECK-NEXT: [[XORY:%.*]] = or <2 x i5> [[X:%.*]], [[Y]]
+; CHECK-NEXT: [[XORYNOT:%.*]] = or <2 x i5> [[X]], [[YNOT]]
+; CHECK-NEXT: [[AND:%.*]] = and <2 x i5> [[XORYNOT]], [[XORY]]
+; CHECK-NEXT: ret <2 x i5> [[AND]]
+;
+ %ynot = xor <2 x i5> %y, <i5 -1, i5 -1>
+ %xory = or <2 x i5> %x, %y
+ %xorynot = or <2 x i5> %x, %ynot
+ %and = and <2 x i5> %xorynot, %xory
+ ret <2 x i5> %and
+}
+
+define <2 x i8> @or_or_not_commute2(<2 x i8> %x, <2 x i8> %y) {
+; CHECK-LABEL: @or_or_not_commute2(
+; CHECK-NEXT: [[YNOT:%.*]] = xor <2 x i8> [[Y:%.*]], <i8 poison, i8 -1>
+; CHECK-NEXT: [[XORY:%.*]] = or <2 x i8> [[X:%.*]], [[Y]]
+; CHECK-NEXT: [[XORYNOT:%.*]] = or <2 x i8> [[YNOT]], [[X]]
+; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[XORY]], [[XORYNOT]]
+; CHECK-NEXT: ret <2 x i8> [[AND]]
+;
+ %ynot = xor <2 x i8> %y, <i8 poison, i8 -1>
+ %xory = or <2 x i8> %x, %y
+ %xorynot = or <2 x i8> %ynot, %x
+ %and = and <2 x i8> %xory, %xorynot
+ ret <2 x i8> %and
+}
+
+define i8 @or_or_not_commute3(i8 %x, i8 %y) {
+; CHECK-LABEL: @or_or_not_commute3(
+; CHECK-NEXT: [[YNOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[XORY:%.*]] = or i8 [[X:%.*]], [[Y]]
+; CHECK-NEXT: [[XORYNOT:%.*]] = or i8 [[YNOT]], [[X]]
+; CHECK-NEXT: [[AND:%.*]] = and i8 [[XORYNOT]], [[XORY]]
+; CHECK-NEXT: ret i8 [[AND]]
+;
+ %ynot = xor i8 %y, -1
+ %xory = or i8 %x, %y
+ %xorynot = or i8 %ynot, %x
+ %and = and i8 %xorynot, %xory
+ ret i8 %and
+}
+define i8 @or_or_not_commute4(i8 %x, i8 %y) {
+; CHECK-LABEL: @or_or_not_commute4(
+; CHECK-NEXT: [[YNOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[XORY:%.*]] = or i8 [[Y]], [[X:%.*]]
+; CHECK-NEXT: [[XORYNOT:%.*]] = or i8 [[X]], [[YNOT]]
+; CHECK-NEXT: [[AND:%.*]] = and i8 [[XORY]], [[XORYNOT]]
+; CHECK-NEXT: ret i8 [[AND]]
+;
+ %ynot = xor i8 %y, -1
+ %xory = or i8 %y, %x
+ %xorynot = or i8 %x, %ynot
+ %and = and i8 %xory, %xorynot
+ ret i8 %and
+}
+
+define i8 @or_or_not_commute5(i8 %x, i8 %y) {
+; CHECK-LABEL: @or_or_not_commute5(
+; CHECK-NEXT: [[YNOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[XORY:%.*]] = or i8 [[Y]], [[X:%.*]]
+; CHECK-NEXT: [[XORYNOT:%.*]] = or i8 [[X]], [[YNOT]]
+; CHECK-NEXT: [[AND:%.*]] = and i8 [[XORYNOT]], [[XORY]]
+; CHECK-NEXT: ret i8 [[AND]]
+;
+ %ynot = xor i8 %y, -1
+ %xory = or i8 %y, %x
+ %xorynot = or i8 %x, %ynot
+ %and = and i8 %xorynot, %xory
+ ret i8 %and
+}
+
+define i8 @or_or_not_commute6(i8 %x, i8 %y) {
+; CHECK-LABEL: @or_or_not_commute6(
+; CHECK-NEXT: [[YNOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[XORY:%.*]] = or i8 [[Y]], [[X:%.*]]
+; CHECK-NEXT: [[XORYNOT:%.*]] = or i8 [[YNOT]], [[X]]
+; CHECK-NEXT: [[AND:%.*]] = and i8 [[XORY]], [[XORYNOT]]
+; CHECK-NEXT: ret i8 [[AND]]
+;
+ %ynot = xor i8 %y, -1
+ %xory = or i8 %y, %x
+ %xorynot = or i8 %ynot, %x
+ %and = and i8 %xory, %xorynot
+ ret i8 %and
+}
+
+define i8 @or_or_not_commute7(i8 %x, i8 %y) {
+; CHECK-LABEL: @or_or_not_commute7(
+; CHECK-NEXT: [[YNOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[XORY:%.*]] = or i8 [[Y]], [[X:%.*]]
+; CHECK-NEXT: [[XORYNOT:%.*]] = or i8 [[YNOT]], [[X]]
+; CHECK-NEXT: [[AND:%.*]] = and i8 [[XORYNOT]], [[XORY]]
+; CHECK-NEXT: ret i8 [[AND]]
+;
+ %ynot = xor i8 %y, -1
+ %xory = or i8 %y, %x
+ %xorynot = or i8 %ynot, %x
+ %and = and i8 %xorynot, %xory
+ ret i8 %and
+}
More information about the llvm-commits
mailing list