[llvm] b9a6b4e - [InstSimplify] add tests for poison-safe variants of (X || Y) && Y; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 22 07:50:14 PST 2023
Author: Sanjay Patel
Date: 2023-01-22T10:44:44-05:00
New Revision: b9a6b4e3eb61365d59b331cda5c5c58542a3668d
URL: https://github.com/llvm/llvm-project/commit/b9a6b4e3eb61365d59b331cda5c5c58542a3668d
DIFF: https://github.com/llvm/llvm-project/commit/b9a6b4e3eb61365d59b331cda5c5c58542a3668d.diff
LOG: [InstSimplify] add tests for poison-safe variants of (X || Y) && Y; 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 0d019dfb7730..3cb7901a0185 100644
--- a/llvm/test/Transforms/InstSimplify/select-logical.ll
+++ b/llvm/test/Transforms/InstSimplify/select-logical.ll
@@ -586,6 +586,8 @@ define i1 @always_false_same_op(i1 %x) {
ret i1 %r
}
+; (X && Y) || Y --> Y
+
define i1 @or_and_common_op_commute0(i1 %x, i1 %y) {
; CHECK-LABEL: @or_and_common_op_commute0(
; CHECK-NEXT: ret i1 [[Y:%.*]]
@@ -647,3 +649,72 @@ define i1 @or_and_not_common_op(i1 %x, i1 %y, i1 %z) {
%r = select i1 %a, i1 true, i1 %z
ret i1 %r
}
+
+; (X || Y) && Y --> Y
+
+define i1 @and_or_common_op_commute0(i1 %x, i1 %y) {
+; CHECK-LABEL: @and_or_common_op_commute0(
+; CHECK-NEXT: [[O:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[O]], i1 [[Y]], i1 false
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %o = select i1 %x, i1 true, i1 %y
+ %r = select i1 %o, i1 %y, i1 false
+ ret i1 %r
+}
+
+define <2 x i1> @and_or_common_op_commute1(<2 x i1> %x, <2 x i1> %y) {
+; CHECK-LABEL: @and_or_common_op_commute1(
+; CHECK-NEXT: [[O:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i1> <i1 true, i1 true>, <2 x i1> [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[O]], <2 x i1> [[Y]], <2 x i1> zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[R]]
+;
+ %o = select <2 x i1> %y, <2 x i1> <i1 true, i1 true>, <2 x i1> %x
+ %r = select <2 x i1> %o, <2 x i1> %y, <2 x i1> zeroinitializer
+ ret <2 x i1> %r
+}
+
+
+define <2 x i1> @and_or_common_op_commute2(<2 x i1> %x, <2 x i1> %y) {
+; CHECK-LABEL: @and_or_common_op_commute2(
+; CHECK-NEXT: [[O:%.*]] = select <2 x i1> [[X:%.*]], <2 x i1> <i1 true, i1 true>, <2 x i1> [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[Y]], <2 x i1> [[O]], <2 x i1> <i1 false, i1 poison>
+; CHECK-NEXT: ret <2 x i1> [[R]]
+;
+ %o = select <2 x i1> %x, <2 x i1> <i1 true, i1 true>, <2 x i1> %y
+ %r = select <2 x i1> %y, <2 x i1> %o, <2 x i1> <i1 0, i1 poison>
+ ret <2 x i1> %r
+}
+
+define <2 x i1> @and_or_common_op_commute3(<2 x i1> %x, <2 x i1> %y) {
+; CHECK-LABEL: @and_or_common_op_commute3(
+; CHECK-NEXT: [[O:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i1> <i1 true, i1 true>, <2 x i1> [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[Y]], <2 x i1> [[O]], <2 x i1> zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[R]]
+;
+ %o = select <2 x i1> %y, <2 x i1> <i1 true, i1 true>, <2 x i1> %x
+ %r = select <2 x i1> %y, <2 x i1> %o, <2 x i1> zeroinitializer
+ ret <2 x i1> %r
+}
+
+define <2 x i1> @and_or_common_op_commute3_poison(<2 x i1> %x, <2 x i1> %y) {
+; CHECK-LABEL: @and_or_common_op_commute3_poison(
+; CHECK-NEXT: [[O:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i1> <i1 poison, i1 true>, <2 x i1> [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[Y]], <2 x i1> [[O]], <2 x i1> zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[R]]
+;
+ %o = select <2 x i1> %y, <2 x i1> <i1 poison, i1 true>, <2 x i1> %x
+ %r = select <2 x i1> %y, <2 x i1> %o, <2 x i1> zeroinitializer
+ ret <2 x i1> %r
+}
+
+define i1 @and_or_not_common_op(i1 %x, i1 %y, i1 %z) {
+; CHECK-LABEL: @and_or_not_common_op(
+; CHECK-NEXT: [[O:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[Z:%.*]], i1 [[O]], i1 false
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %o = select i1 %x, i1 true, i1 %y
+ %r = select i1 %z, i1 %o, i1 false
+ ret i1 %r
+}
More information about the llvm-commits
mailing list