[llvm] 7de2add - [InstSimplify] add tests for logic-of-cmps with not op; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 25 08:35:35 PDT 2020


Author: Sanjay Patel
Date: 2020-10-25T11:13:30-04:00
New Revision: 7de2add8296fb26fd49106173c9f140ebd0abedc

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

LOG: [InstSimplify] add tests for logic-of-cmps with not op; NFC

One variant of this is shown in:
https://llvm.org/PR47858

Added: 
    

Modified: 
    llvm/test/Transforms/InstSimplify/and-or-icmp-min-max.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstSimplify/and-or-icmp-min-max.ll b/llvm/test/Transforms/InstSimplify/and-or-icmp-min-max.ll
index 63aa6089ea70..36e86ff32623 100644
--- a/llvm/test/Transforms/InstSimplify/and-or-icmp-min-max.ll
+++ b/llvm/test/Transforms/InstSimplify/and-or-icmp-min-max.ll
@@ -4,8 +4,9 @@
 ; There are 12 basic patterns (or 6 with DeMorganized equivalent) with
 ;    2 (commute logic op) *
 ;    2 (swap compare operands) *
-;    2 (signed/unsigned)
-; variations for a total of 96 tests.
+;    2 (signed/unsigned) *
+;    2 (not of input operand)
+; variations for a total of 192 tests.
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;
@@ -1222,3 +1223,1515 @@ define i1 @ugt_swap_or_not_min_commute(i823 %x, i823 %y)  {
   %r = or i1 %cmpeq, %cmp
   ret i1 %r
 }
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; (X == MIN) && (!X < Y) --> false
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+define i1 @slt_and_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @slt_and_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp slt i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 128
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define <2 x i1> @slt_and_max_commute_not_op(<2 x i8> %x, <2 x i8> %y)  {
+; CHECK-LABEL: @slt_and_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt <2 x i8> [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq <2 x i8> [[X]], <i8 -128, i8 -128>
+; CHECK-NEXT:    [[R:%.*]] = and <2 x i1> [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %notx = xor <2 x i8> %x, <i8 -1, i8 -1>
+  %cmp = icmp slt <2 x i8> %notx, %y
+  %cmpeq = icmp eq <2 x i8> %x, <i8 128, i8 128>
+  %r = and <2 x i1> %cmpeq, %cmp
+  ret <2 x i1> %r
+}
+
+define i1 @slt_swap_and_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @slt_swap_and_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sgt i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 128
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @slt_swap_and_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @slt_swap_and_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sgt i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 128
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ult_and_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ult_and_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ult i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 0
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ult_and_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ult_and_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ult i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 0
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ult_swap_and_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ult_swap_and_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ugt i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 0
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ult_swap_and_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ult_swap_and_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ugt i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 0
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; (X == MAX) && (!X > Y) --> false
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+define i1 @sgt_and_min_not_op(i9 %x, i9 %y)  {
+; CHECK-LABEL: @sgt_and_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i9 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i9 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i9 [[X]], 255
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i9 %x, -1
+  %cmp = icmp sgt i9 %notx, %y
+  %cmpeq = icmp eq i9 %x, 255
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sgt_and_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sgt_and_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sgt i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 127
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @sgt_swap_and_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sgt_swap_and_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp slt i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 127
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sgt_swap_and_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sgt_swap_and_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp slt i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 127
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ugt_and_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ugt_and_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ugt i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 255
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ugt_and_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ugt_and_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ugt i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 255
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ugt_swap_and_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ugt_swap_and_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ult i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 255
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ugt_swap_and_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ugt_swap_and_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ult i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 255
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; (X != MIN) || (!X >= Y) --> true
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+define i1 @sge_or_not_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sge_or_not_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sge i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 128
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sge_or_not_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sge_or_not_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sge i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 128
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @sge_swap_or_not_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sge_swap_or_not_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sle i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 128
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sge_swap_or_not_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sge_swap_or_not_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sle i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 128
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @uge_or_not_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @uge_or_not_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp uge i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp uge i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 0
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @uge_or_not_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @uge_or_not_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp uge i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp uge i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 0
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @uge_swap_or_not_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @uge_swap_or_not_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ule i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ule i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 0
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @uge_swap_or_not_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @uge_swap_or_not_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ule i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ule i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 0
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; (X != MAX) || (!X <= Y) --> true
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+define i1 @sle_or_not_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sle_or_not_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sle i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 127
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sle_or_not_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sle_or_not_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sle i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 127
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @sle_swap_or_not_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sle_swap_or_not_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sge i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 127
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sle_swap_or_not_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sle_swap_or_not_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sge i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 127
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ule_or_not_min_not_op(i427 %x, i427 %y)  {
+; CHECK-LABEL: @ule_or_not_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i427 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ule i427 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i427 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i427 %x, -1
+  %cmp = icmp ule i427 %notx, %y
+  %cmpeq = icmp ne i427 %x, -1
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ule_or_not_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ule_or_not_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ule i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ule i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 255
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ule_swap_or_not_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ule_swap_or_not_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp uge i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp uge i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 255
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ule_swap_or_not_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ule_swap_or_not_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp uge i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp uge i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 255
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; (X == MIN) && (!X >= Y) --> X == MIN
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+define i1 @sge_and_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sge_and_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sge i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 128
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sge_and_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sge_and_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sge i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 128
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @sge_swap_and_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sge_swap_and_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sle i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 128
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sge_swap_and_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sge_swap_and_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sle i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 128
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @uge_and_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @uge_and_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp uge i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp uge i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 0
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @uge_and_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @uge_and_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp uge i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp uge i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 0
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @uge_swap_and_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @uge_swap_and_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ule i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ule i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 0
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @uge_swap_and_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @uge_swap_and_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ule i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ule i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 0
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; (X == MIN) && (!X <= Y) --> X == MIN
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+define i1 @sle_and_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sle_and_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sle i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 128
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sle_and_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sle_and_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sle i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 128
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @sle_swap_and_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sle_swap_and_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sge i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 128
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sle_swap_and_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sle_swap_and_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sge i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 128
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ule_and_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ule_and_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ule i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ule i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 0
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ule_and_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ule_and_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ule i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ule i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 0
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ule_swap_and_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ule_swap_and_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp uge i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp uge i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 0
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ule_swap_and_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ule_swap_and_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp uge i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp uge i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 0
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; (X == MIN) || (!X >= Y) --> !X >= Y
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+define i1 @sge_or_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sge_or_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sge i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 128
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sge_or_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sge_or_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sge i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 128
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @sge_swap_or_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sge_swap_or_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sle i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 128
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sge_swap_or_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sge_swap_or_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sle i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 128
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @uge_or_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @uge_or_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp uge i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp uge i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 0
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @uge_or_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @uge_or_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp uge i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp uge i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 0
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @uge_swap_or_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @uge_swap_or_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ule i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ule i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 0
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @uge_swap_or_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @uge_swap_or_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ule i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ule i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 0
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; (X == MAX) || (!X <= Y) --> !X <= Y
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+define i1 @sle_or_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sle_or_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sle i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 127
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sle_or_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sle_or_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sle i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 127
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @sle_swap_or_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sle_swap_or_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sge i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 127
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sle_swap_or_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sle_swap_or_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sge i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 127
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ule_or_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ule_or_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ule i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ule i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 255
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ule_or_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ule_or_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ule i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ule i8 %notx, %y
+  %cmpeq = icmp eq i8 %x, 255
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ule_swap_or_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ule_swap_or_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp uge i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp uge i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 255
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ule_swap_or_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ule_swap_or_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp uge i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp eq i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp uge i8 %y, %notx
+  %cmpeq = icmp eq i8 %x, 255
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; (X != MIN) && (!X < Y) --> !X < Y
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+define i1 @slt_and_not_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @slt_and_not_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp slt i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 128
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @slt_and_not_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @slt_and_not_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp slt i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 128
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @slt_swap_and_not_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @slt_swap_and_not_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sgt i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 128
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @slt_swap_and_not_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @slt_swap_and_not_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sgt i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 128
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ult_and_not_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ult_and_not_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ult i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 0
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ult_and_not_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ult_and_not_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ult i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 0
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ult_swap_and_not_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ult_swap_and_not_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ugt i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 0
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ult_swap_and_not_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ult_swap_and_not_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ugt i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 0
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; (X != MAX) && (!X > Y) --> !X > Y
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+define i1 @sgt_and_not_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sgt_and_not_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sgt i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 127
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sgt_and_not_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sgt_and_not_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sgt i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 127
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @sgt_swap_and_not_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sgt_swap_and_not_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp slt i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 127
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sgt_swap_and_not_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sgt_swap_and_not_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp slt i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 127
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ugt_and_not_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ugt_and_not_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ugt i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 255
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ugt_and_not_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ugt_and_not_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ugt i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 255
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ugt_swap_and_not_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ugt_swap_and_not_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ult i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 255
+  %r = and i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ugt_swap_and_not_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ugt_swap_and_not_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ult i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 255
+  %r = and i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; (X != MIN) || (!X < Y) --> X != MIN
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+define i1 @slt_or_not_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @slt_or_not_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp slt i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 128
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @slt_or_not_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @slt_or_not_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp slt i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 128
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @slt_swap_or_not_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @slt_swap_or_not_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sgt i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 128
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @slt_swap_or_not_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @slt_swap_or_not_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sgt i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 128
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ult_or_not_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ult_or_not_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ult i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 0
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ult_or_not_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ult_or_not_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ult i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 0
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ult_swap_or_not_max_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ult_swap_or_not_max_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ugt i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 0
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ult_swap_or_not_max_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ult_swap_or_not_max_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ugt i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 0
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; (X != MAX) || (!X > Y) --> X != MAX
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+define i1 @sgt_or_not_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sgt_or_not_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sgt i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 127
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sgt_or_not_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sgt_or_not_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp sgt i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 127
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @sgt_swap_or_not_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sgt_swap_or_not_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp slt i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 127
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @sgt_swap_or_not_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @sgt_swap_or_not_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp slt i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 127
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ugt_or_not_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ugt_or_not_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ugt i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 255
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ugt_or_not_min_commute_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ugt_or_not_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ugt i8 %notx, %y
+  %cmpeq = icmp ne i8 %x, 255
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}
+
+define i1 @ugt_swap_or_not_min_not_op(i8 %x, i8 %y)  {
+; CHECK-LABEL: @ugt_swap_or_not_min_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i8 %x, -1
+  %cmp = icmp ult i8 %y, %notx
+  %cmpeq = icmp ne i8 %x, 255
+  %r = or i1 %cmp, %cmpeq
+  ret i1 %r
+}
+
+define i1 @ugt_swap_or_not_min_commute_not_op(i823 %x, i823 %y)  {
+; CHECK-LABEL: @ugt_swap_or_not_min_commute_not_op(
+; CHECK-NEXT:    [[NOTX:%.*]] = xor i823 [[X:%.*]], -1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i823 [[Y:%.*]], [[NOTX]]
+; CHECK-NEXT:    [[CMPEQ:%.*]] = icmp ne i823 [[X]], 255
+; CHECK-NEXT:    [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %notx = xor i823 %x, -1
+  %cmp = icmp ult i823 %y, %notx
+  %cmpeq = icmp ne i823 %x, 255
+  %r = or i1 %cmpeq, %cmp
+  ret i1 %r
+}


        


More information about the llvm-commits mailing list