[llvm] 64d4bd0 - [InstCombine][InstSimplify] Add baseline tests for icmp bool with not on LHS; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 8 05:48:09 PST 2021


Author: Hasyimi Bahrudin
Date: 2021-12-08T08:48:03-05:00
New Revision: 64d4bd02dc3f8741043806c82a87f81aff7bc8d9

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

LOG: [InstCombine][InstSimplify] Add baseline tests for icmp bool with not on LHS; NFC

See D114666 for proposed code change to instsimplify.

The difference between the CHECK result of these 2 tests
highlights missed folds in instsimplify
(e.g. (icmp eq (xor X, true), false) -> X) that are
already being handled by instcombine.

The tests are based on:
llvm/test/Transforms/InstSimplify/icmp-bool-constant.ll

Differential Revision: https://reviews.llvm.org/D115209

Added: 
    llvm/test/Transforms/InstCombine/icmp-not-bool-constant.ll
    llvm/test/Transforms/InstSimplify/icmp-not-bool-constant.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/icmp-not-bool-constant.ll b/llvm/test/Transforms/InstCombine/icmp-not-bool-constant.ll
new file mode 100644
index 0000000000000..e9782f8471d45
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/icmp-not-bool-constant.ll
@@ -0,0 +1,192 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; Test all integer predicates with bool types and true/false constants,
+; with not on LHS (icmp pred (xor X, true), true|false).
+; Use vectors to provide test coverage that is not duplicated in other folds.
+
+define <2 x i1> @eq_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @eq_t_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[NOT]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp eq <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @eq_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @eq_f_not(
+; CHECK-NEXT:    ret <2 x i1> [[A:%.*]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp eq <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ne_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @ne_t_not(
+; CHECK-NEXT:    ret <2 x i1> [[A:%.*]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ne <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ne_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @ne_f_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[NOT]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ne <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ugt_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @ugt_t_not(
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ugt <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ugt_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @ugt_f_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[NOT]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ugt <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ult_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @ult_t_not(
+; CHECK-NEXT:    ret <2 x i1> [[A:%.*]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ult <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ult_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @ult_f_not(
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ult <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @sgt_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @sgt_t_not(
+; CHECK-NEXT:    ret <2 x i1> [[A:%.*]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp sgt <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @sgt_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @sgt_f_not(
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp sgt <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @slt_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @slt_t_not(
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp slt <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @slt_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @slt_f_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[NOT]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp slt <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @uge_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @uge_t_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[NOT]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp uge <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @uge_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @uge_f_not(
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp uge <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ule_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @ule_t_not(
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ule <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ule_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @ule_f_not(
+; CHECK-NEXT:    ret <2 x i1> [[A:%.*]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ule <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @sge_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @sge_t_not(
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp sge <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @sge_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @sge_f_not(
+; CHECK-NEXT:    ret <2 x i1> [[A:%.*]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp sge <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @sle_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @sle_t_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[NOT]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp sle <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @sle_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @sle_f_not(
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp sle <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}

diff  --git a/llvm/test/Transforms/InstSimplify/icmp-not-bool-constant.ll b/llvm/test/Transforms/InstSimplify/icmp-not-bool-constant.ll
new file mode 100644
index 0000000000000..b631c6bb5c895
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/icmp-not-bool-constant.ll
@@ -0,0 +1,204 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+; Test all integer predicates with bool types and true/false constants,
+; with not on LHS (icmp pred (xor X, true), true|false).
+; Use vectors to provide test coverage that is not duplicated in other folds.
+
+define <2 x i1> @eq_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @eq_t_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[NOT]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp eq <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @eq_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @eq_f_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    [[R:%.*]] = icmp eq <2 x i1> [[NOT]], zeroinitializer
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp eq <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ne_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @ne_t_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    [[R:%.*]] = icmp ne <2 x i1> [[NOT]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ne <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ne_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @ne_f_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[NOT]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ne <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ugt_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @ugt_t_not(
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ugt <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ugt_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @ugt_f_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[NOT]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ugt <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ult_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @ult_t_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    [[R:%.*]] = icmp ult <2 x i1> [[NOT]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ult <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ult_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @ult_f_not(
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ult <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @sgt_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @sgt_t_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    [[R:%.*]] = icmp sgt <2 x i1> [[NOT]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp sgt <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @sgt_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @sgt_f_not(
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp sgt <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @slt_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @slt_t_not(
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp slt <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @slt_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @slt_f_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[NOT]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp slt <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @uge_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @uge_t_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[NOT]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp uge <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @uge_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @uge_f_not(
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp uge <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ule_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @ule_t_not(
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ule <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @ule_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @ule_f_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    [[R:%.*]] = icmp ule <2 x i1> [[NOT]], zeroinitializer
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp ule <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @sge_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @sge_t_not(
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp sge <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @sge_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @sge_f_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    [[R:%.*]] = icmp sge <2 x i1> [[NOT]], zeroinitializer
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp sge <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @sle_t_not(<2 x i1> %a) {
+; CHECK-LABEL: @sle_t_not(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    ret <2 x i1> [[NOT]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp sle <2 x i1> %not, <i1 true, i1 true>
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @sle_f_not(<2 x i1> %a) {
+; CHECK-LABEL: @sle_f_not(
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %r = icmp sle <2 x i1> %not, <i1 false, i1 false>
+  ret <2 x i1> %r
+}


        


More information about the llvm-commits mailing list