[llvm] 081a4e6 - [InstSimplify] add tests for poison-safe logical nand+or; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 29 07:38:23 PST 2023
Author: Sanjay Patel
Date: 2023-01-29T09:43:53-05:00
New Revision: 081a4e6712f465540cbf5e5895ffaf2d51777593
URL: https://github.com/llvm/llvm-project/commit/081a4e6712f465540cbf5e5895ffaf2d51777593
DIFF: https://github.com/llvm/llvm-project/commit/081a4e6712f465540cbf5e5895ffaf2d51777593.diff
LOG: [InstSimplify] add tests for poison-safe logical nand+or; NFC
Added:
Modified:
llvm/test/Transforms/InstSimplify/select-logical.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstSimplify/select-logical.ll b/llvm/test/Transforms/InstSimplify/select-logical.ll
index e2b124ce3df59..796c7db7cedba 100644
--- a/llvm/test/Transforms/InstSimplify/select-logical.ll
+++ b/llvm/test/Transforms/InstSimplify/select-logical.ll
@@ -285,6 +285,83 @@ define i1 @logical_not_or_and_negative1(i1 %x, i1 %y, i1 %z) {
ret i1 %r
}
+define i1 @logical_nand_logical_or_common_op_commute1(i1 %x, i1 %y) {
+; CHECK-LABEL: @logical_nand_logical_or_common_op_commute1(
+; CHECK-NEXT: [[AND:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false
+; CHECK-NEXT: [[NAND:%.*]] = xor i1 [[AND]], true
+; CHECK-NEXT: [[OR:%.*]] = select i1 [[NAND]], i1 true, i1 [[X]]
+; CHECK-NEXT: ret i1 [[OR]]
+;
+ %and = select i1 %x, i1 %y, i1 false
+ %nand = xor i1 %and, -1
+ %or = select i1 %nand, i1 true, i1 %x
+ ret i1 %or
+}
+
+define <2 x i1> @logical_nand_logical_or_common_op_commute2(<2 x i1> %x, <2 x i1> %y) {
+; CHECK-LABEL: @logical_nand_logical_or_common_op_commute2(
+; CHECK-NEXT: [[AND:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i1> [[X:%.*]], <2 x i1> zeroinitializer
+; CHECK-NEXT: [[NAND:%.*]] = xor <2 x i1> [[AND]], <i1 true, i1 true>
+; CHECK-NEXT: [[OR:%.*]] = select <2 x i1> [[NAND]], <2 x i1> <i1 true, i1 true>, <2 x i1> [[X]]
+; CHECK-NEXT: ret <2 x i1> [[OR]]
+;
+ %and = select <2 x i1> %y, <2 x i1> %x, <2 x i1> zeroinitializer
+ %nand = xor <2 x i1> %and, <i1 -1, i1 -1>
+ %or = select <2 x i1> %nand, <2 x i1> <i1 -1, i1 -1>, <2 x i1> %x
+ ret <2 x i1> %or
+}
+
+define <2 x i1> @logical_nand_logical_or_common_op_commute3(<2 x i1> %x, <2 x i1> %y) {
+; CHECK-LABEL: @logical_nand_logical_or_common_op_commute3(
+; CHECK-NEXT: [[AND:%.*]] = select <2 x i1> [[X:%.*]], <2 x i1> [[Y:%.*]], <2 x i1> zeroinitializer
+; CHECK-NEXT: [[NAND:%.*]] = xor <2 x i1> [[AND]], <i1 true, i1 poison>
+; CHECK-NEXT: [[OR:%.*]] = select <2 x i1> [[X]], <2 x i1> <i1 true, i1 poison>, <2 x i1> [[NAND]]
+; CHECK-NEXT: ret <2 x i1> [[OR]]
+;
+ %and = select <2 x i1> %x, <2 x i1> %y, <2 x i1> zeroinitializer
+ %nand = xor <2 x i1> %and, <i1 -1, i1 poison>
+ %or = select <2 x i1> %x, <2 x i1> <i1 -1, i1 poison>, <2 x i1> %nand
+ ret <2 x i1> %or
+}
+
+define i1 @logical_nand_logical_or_common_op_commute4(i1 %x, i1 %y) {
+; CHECK-LABEL: @logical_nand_logical_or_common_op_commute4(
+; CHECK-NEXT: [[AND:%.*]] = select i1 [[Y:%.*]], i1 [[X:%.*]], i1 false
+; CHECK-NEXT: [[NAND:%.*]] = xor i1 [[AND]], true
+; CHECK-NEXT: [[OR:%.*]] = select i1 [[X]], i1 true, i1 [[NAND]]
+; CHECK-NEXT: ret i1 [[OR]]
+;
+ %and = select i1 %y, i1 %x, i1 false
+ %nand = xor i1 %and, -1
+ %or = select i1 %x, i1 true, i1 %nand
+ ret i1 %or
+}
+
+define <2 x i1> @logical_nand_logical_or_common_op_commute4_poison_vec(<2 x i1> %x, <2 x i1> %y) {
+; CHECK-LABEL: @logical_nand_logical_or_common_op_commute4_poison_vec(
+; CHECK-NEXT: [[AND:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i1> [[X:%.*]], <2 x i1> <i1 false, i1 poison>
+; CHECK-NEXT: [[NAND:%.*]] = xor <2 x i1> [[AND]], <i1 true, i1 true>
+; CHECK-NEXT: [[OR:%.*]] = select <2 x i1> [[X]], <2 x i1> <i1 true, i1 true>, <2 x i1> [[NAND]]
+; CHECK-NEXT: ret <2 x i1> [[OR]]
+;
+ %and = select <2 x i1> %y, <2 x i1> %x, <2 x i1> <i1 0, i1 poison>
+ %nand = xor <2 x i1> %and, <i1 -1, i1 -1>
+ %or = select <2 x i1> %x, <2 x i1> <i1 -1, i1 -1>, <2 x i1> %nand
+ ret <2 x i1> %or
+}
+
+define i1 @logical_nand_logical_or(i1 %x, i1 %y, i1 %z) {
+; CHECK-LABEL: @logical_nand_logical_or(
+; CHECK-NEXT: [[AND:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false
+; CHECK-NEXT: [[NAND:%.*]] = xor i1 [[AND]], true
+; CHECK-NEXT: [[OR:%.*]] = select i1 [[NAND]], i1 true, i1 [[Z:%.*]]
+; CHECK-NEXT: ret i1 [[OR]]
+;
+ %and = select i1 %x, i1 %y, i1 false
+ %nand = xor i1 %and, -1
+ %or = select i1 %nand, i1 true, i1 %z
+ ret i1 %or
+}
; (X | Y) ? false : X --> false
More information about the llvm-commits
mailing list