[llvm] 56ae4f2 - [InstCombine] add tests for logical and/or with not ops; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 14 09:55:47 PDT 2021


Author: Sanjay Patel
Date: 2021-06-14T12:54:35-04:00
New Revision: 56ae4f23b227897361d2a7c84364a6df81f3c327

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

LOG: [InstCombine] add tests for logical and/or with not ops; NFC

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/not.ll
    llvm/test/Transforms/InstCombine/select-and-or.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/not.ll b/llvm/test/Transforms/InstCombine/not.ll
index 146fea71cd1c6..f84bd844b2abb 100644
--- a/llvm/test/Transforms/InstCombine/not.ll
+++ b/llvm/test/Transforms/InstCombine/not.ll
@@ -467,3 +467,60 @@ define i8 @not_or_neg_use2(i8 %x, i8 %y)  {
   %not = xor i8 %o, -1
   ret i8 %not
 }
+
+define i1 @not_select_bool(i1 %x, i1 %y, i1 %z) {
+; CHECK-LABEL: @not_select_bool(
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 [[Z:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = xor i1 [[SEL]], true
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %sel = select i1 %x, i1 %y, i1 %z
+  %r = xor i1 %sel, true
+  ret i1 %r
+}
+
+define i1 @not_select_bool_const1(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_select_bool_const1(
+; CHECK-NEXT:    [[NOT_X:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[NOT_X]], i1 true, i1 [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = xor i1 [[SEL]], true
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %sel = select i1 %x, i1 %y, i1 true
+  %r = xor i1 %sel, true
+  ret i1 %r
+}
+
+define i1 @not_select_bool_const2(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_select_bool_const2(
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false
+; CHECK-NEXT:    [[R:%.*]] = xor i1 [[SEL]], true
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %sel = select i1 %x, i1 %y, i1 false
+  %r = xor i1 %sel, true
+  ret i1 %r
+}
+
+define i1 @not_select_bool_const3(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_select_bool_const3(
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = xor i1 [[SEL]], true
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %sel = select i1 %x, i1 true, i1 %y
+  %r = xor i1 %sel, true
+  ret i1 %r
+}
+
+define i1 @not_select_bool_const4(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_select_bool_const4(
+; CHECK-NEXT:    [[NOT_X:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[NOT_X]], i1 [[Y:%.*]], i1 false
+; CHECK-NEXT:    [[R:%.*]] = xor i1 [[SEL]], true
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %sel = select i1 %x, i1 false, i1 %y
+  %r = xor i1 %sel, true
+  ret i1 %r
+}

diff  --git a/llvm/test/Transforms/InstCombine/select-and-or.ll b/llvm/test/Transforms/InstCombine/select-and-or.ll
index 25fb9d0d9b37a..9146f12f51cad 100644
--- a/llvm/test/Transforms/InstCombine/select-and-or.ll
+++ b/llvm/test/Transforms/InstCombine/select-and-or.ll
@@ -1,6 +1,8 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -S -instcombine < %s | FileCheck %s
 
+declare void @use(i1)
+
 ; Should not be converted to "and", which has 
diff erent poison semantics.
 define i1 @logical_and(i1 %a, i1 %b) {
 ; CHECK-LABEL: @logical_and(
@@ -176,3 +178,239 @@ define i1 @logical_and_noundef_b(i1 %a, i1 noundef %b) {
   %res = select i1 %a, i1 %b, i1 false
   ret i1 %res
 }
+
+define i1 @not_not_true(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_not_true(
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[NOTY]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  %noty = xor i1 %y, true
+  %r = select i1 %notx, i1 %noty, i1 true
+  ret i1 %r
+}
+
+define i1 @not_not_false(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_not_false(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[NOTX]], i1 [[NOTY]], i1 false
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  %noty = xor i1 %y, true
+  %r = select i1 %notx, i1 %noty, i1 false
+  ret i1 %r
+}
+
+define i1 @not_true_not(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_true_not(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[NOTX]], i1 true, i1 [[NOTY]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  %noty = xor i1 %y, true
+  %r = select i1 %notx, i1 true, i1 %noty
+  ret i1 %r
+}
+
+define i1 @not_false_not(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_false_not(
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[X:%.*]], i1 [[NOTY]], i1 false
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  %noty = xor i1 %y, true
+  %r = select i1 %notx, i1 false, i1 %noty
+  ret i1 %r
+}
+
+define i1 @not_not_true_use1(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_not_true_use1(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTX]])
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[X]], i1 true, i1 [[NOTY]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  call void @use(i1 %notx)
+  %noty = xor i1 %y, true
+  %r = select i1 %notx, i1 %noty, i1 true
+  ret i1 %r
+}
+
+define i1 @not_not_false_use1(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_not_false_use1(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTX]])
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[NOTX]], i1 [[NOTY]], i1 false
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  call void @use(i1 %notx)
+  %noty = xor i1 %y, true
+  %r = select i1 %notx, i1 %noty, i1 false
+  ret i1 %r
+}
+
+define i1 @not_true_not_use1(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_true_not_use1(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTX]])
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[NOTX]], i1 true, i1 [[NOTY]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  call void @use(i1 %notx)
+  %noty = xor i1 %y, true
+  %r = select i1 %notx, i1 true, i1 %noty
+  ret i1 %r
+}
+
+define i1 @not_false_not_use1(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_false_not_use1(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTX]])
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[X]], i1 [[NOTY]], i1 false
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  call void @use(i1 %notx)
+  %noty = xor i1 %y, true
+  %r = select i1 %notx, i1 false, i1 %noty
+  ret i1 %r
+}
+
+define i1 @not_not_true_use2(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_not_true_use2(
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTY]])
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[NOTY]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  %noty = xor i1 %y, true
+  call void @use(i1 %noty)
+  %r = select i1 %notx, i1 %noty, i1 true
+  ret i1 %r
+}
+
+define i1 @not_not_false_use2(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_not_false_use2(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTY]])
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[NOTX]], i1 [[NOTY]], i1 false
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  %noty = xor i1 %y, true
+  call void @use(i1 %noty)
+  %r = select i1 %notx, i1 %noty, i1 false
+  ret i1 %r
+}
+
+define i1 @not_true_not_use2(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_true_not_use2(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTY]])
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[NOTX]], i1 true, i1 [[NOTY]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  %noty = xor i1 %y, true
+  call void @use(i1 %noty)
+  %r = select i1 %notx, i1 true, i1 %noty
+  ret i1 %r
+}
+
+define i1 @not_false_not_use2(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_false_not_use2(
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTY]])
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[X:%.*]], i1 [[NOTY]], i1 false
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  %noty = xor i1 %y, true
+  call void @use(i1 %noty)
+  %r = select i1 %notx, i1 false, i1 %noty
+  ret i1 %r
+}
+
+define i1 @not_not_true_use3(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_not_true_use3(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTX]])
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTY]])
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[X]], i1 true, i1 [[NOTY]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  call void @use(i1 %notx)
+  %noty = xor i1 %y, true
+  call void @use(i1 %noty)
+  %r = select i1 %notx, i1 %noty, i1 true
+  ret i1 %r
+}
+
+define i1 @not_not_false_use3(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_not_false_use3(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTX]])
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTY]])
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[NOTX]], i1 [[NOTY]], i1 false
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  call void @use(i1 %notx)
+  %noty = xor i1 %y, true
+  call void @use(i1 %noty)
+  %r = select i1 %notx, i1 %noty, i1 false
+  ret i1 %r
+}
+
+define i1 @not_true_not_use3(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_true_not_use3(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTX]])
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTY]])
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[NOTX]], i1 true, i1 [[NOTY]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  call void @use(i1 %notx)
+  %noty = xor i1 %y, true
+  call void @use(i1 %noty)
+  %r = select i1 %notx, i1 true, i1 %noty
+  ret i1 %r
+}
+
+define i1 @not_false_not_use3(i1 %x, i1 %y) {
+; CHECK-LABEL: @not_false_not_use3(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTX]])
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTY]])
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[X]], i1 [[NOTY]], i1 false
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i1 %x, true
+  call void @use(i1 %notx)
+  %noty = xor i1 %y, true
+  call void @use(i1 %noty)
+  %r = select i1 %notx, i1 false, i1 %noty
+  ret i1 %r
+}


        


More information about the llvm-commits mailing list