[llvm] d422f7e - [InstSimplify] add tests for select with common 'and' ops; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 30 12:46:06 PST 2022


Author: Sanjay Patel
Date: 2022-11-30T15:44:48-05:00
New Revision: d422f7e4945cf7c0c200cdde4e3736c67f8dd2fe

URL: https://github.com/llvm/llvm-project/commit/d422f7e4945cf7c0c200cdde4e3736c67f8dd2fe
DIFF: https://github.com/llvm/llvm-project/commit/d422f7e4945cf7c0c200cdde4e3736c67f8dd2fe.diff

LOG: [InstSimplify] add tests for select with common 'and' ops; 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 99b9a082d8eb4..349a39657ed73 100644
--- a/llvm/test/Transforms/InstSimplify/select-logical.ll
+++ b/llvm/test/Transforms/InstSimplify/select-logical.ll
@@ -465,3 +465,100 @@ define i1 @select_or_same_op_negatvie(i1 %x, i1 %y, i1 %z) {
   %r = select i1 %or, i1 %x, i1 %z
   ret i1 %r
 }
+
+; (X && Y) ? X : Y --> Y
+
+define i1 @select_and_same_op(i1 %x, i1 %y) {
+; CHECK-LABEL: @select_and_same_op(
+; CHECK-NEXT:    [[A:%.*]] = and i1 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[A]], i1 [[X]], i1 [[Y]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %a = and i1 %x, %y
+  %r = select i1 %a, i1 %x, i1 %y
+  ret i1 %r
+}
+
+
+define i1 @select_and_same_op_commute(i1 %x, i1 %y) {
+; CHECK-LABEL: @select_and_same_op_commute(
+; CHECK-NEXT:    [[A:%.*]] = and i1 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[A]], i1 [[Y]], i1 [[X]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %a = and i1 %x, %y
+  %r = select i1 %a, i1 %y, i1 %x
+  ret i1 %r
+}
+
+
+define <2 x i1> @select_and_same_op_vector1(<2 x i1> %x, <2 x i1> %y) {
+; CHECK-LABEL: @select_and_same_op_vector1(
+; CHECK-NEXT:    [[A:%.*]] = and <2 x i1> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = select <2 x i1> [[A]], <2 x i1> [[X]], <2 x i1> [[Y]]
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %a = and <2 x i1> %x, %y
+  %r = select <2 x i1> %a, <2 x i1> %x, <2 x i1> %y
+  ret <2 x i1> %r
+}
+
+
+define i1 @select_logic_and1_same_op(i1 %x, i1 %y) {
+; CHECK-LABEL: @select_logic_and1_same_op(
+; CHECK-NEXT:    [[A:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[A]], i1 [[X]], i1 [[Y]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %a = select i1 %x, i1 %y, i1 false
+  %r = select i1 %a, i1 %x, i1 %y
+  ret i1 %r
+}
+
+
+define i1 @select_logic_and2_same_op(i1 %x, i1 %y) {
+; CHECK-LABEL: @select_logic_and2_same_op(
+; CHECK-NEXT:    [[A:%.*]] = select i1 [[Y:%.*]], i1 [[X:%.*]], i1 false
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[A]], i1 [[X]], i1 [[Y]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %a = select i1 %y, i1 %x, i1 false
+  %r = select i1 %a, i1 %x, i1 %y
+  ret i1 %r
+}
+
+
+define <2 x i1> @select_and_same_op_vector2(<2 x i1> %x, <2 x i1> %y) {
+; CHECK-LABEL: @select_and_same_op_vector2(
+; CHECK-NEXT:    [[A:%.*]] = select <2 x i1> [[X:%.*]], <2 x i1> [[Y:%.*]], <2 x i1> zeroinitializer
+; CHECK-NEXT:    [[R:%.*]] = select <2 x i1> [[A]], <2 x i1> [[X]], <2 x i1> [[Y]]
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %a = select <2 x i1> %x, <2 x i1> %y, <2 x i1> zeroinitializer
+  %r = select <2 x i1> %a, <2 x i1> %x, <2 x i1> %y
+  ret <2 x i1> %r
+}
+
+; (X && Y) ? X : Y --> Y
+
+define <2 x i1> @select_and_same_op_vector2_poison(<2 x i1> %x, <2 x i1> %y) {
+; CHECK-LABEL: @select_and_same_op_vector2_poison(
+; CHECK-NEXT:    [[A:%.*]] = select <2 x i1> [[X:%.*]], <2 x i1> [[Y:%.*]], <2 x i1> <i1 false, i1 poison>
+; CHECK-NEXT:    [[R:%.*]] = select <2 x i1> [[A]], <2 x i1> [[X]], <2 x i1> [[Y]]
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %a = select <2 x i1> %x, <2 x i1> %y, <2 x i1> <i1 false, i1 poison>
+  %r = select <2 x i1> %a, <2 x i1> %x, <2 x i1> %y
+  ret <2 x i1> %r
+}
+
+define i1 @select_and_same_op_negatvie(i1 %x, i1 %y, i1 %z) {
+; CHECK-LABEL: @select_and_same_op_negatvie(
+; CHECK-NEXT:    [[A:%.*]] = and i1 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[A]], i1 [[X]], i1 [[Z:%.*]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %a = and i1 %x, %y
+  %r = select i1 %a, i1 %x, i1 %z
+  ret i1 %r
+}


        


More information about the llvm-commits mailing list