Skip to content

Commit

Permalink
[InstSimplify] fold and/or of compares with equality to min/max constant
Browse files Browse the repository at this point in the history
I found 12 (6 if we compress the DeMorganized forms) patterns for logic-of-compares
with a min/max constant while looking at PR45510:
https://bugs.llvm.org/show_bug.cgi?id=45510

The variations on those forms multiply the test cases by 8 (unsigned/signed, swapped
compare operands, commuted logic operands).
We have partial logic to deal with these for the unsigned min (zero) case, but
missed everything else.

We are deferring the majority of these patterns to InstCombine to allow more general
handling (see D78582).

We could use ConstantRange instead of predicate+constant matching here. I don't
expect there's any noticeable compile-time impact for either form.

Here's an abuse of Alive2 to show the 12 basic signed variants of the patterns in
one function:
http://volta.cs.utah.edu:8080/z/5Vpiyg

declare void @use(i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1)
define void @src(i8 %x, i8 %y)  {
  %m1 = icmp eq i8 %x, 127
  %c1 = icmp slt i8 %x, %y
  %r1 = and i1 %m1, %c1   ; (X == MAX) && (X < Y) --> false

  %m2 = icmp ne i8 %x, 127
  %c2 = icmp sge i8 %x, %y
  %r2 = or i1 %m2, %c2    ; (X != MAX) || (X >= Y) --> true

  %m3 = icmp eq i8 %x, -128
  %c3 = icmp sgt i8 %x, %y
  %r3 = and i1 %m3, %c3   ; (X == MIN) && (X > Y) --> false

  %m4 = icmp ne i8 %x, -128
  %c4 = icmp sle i8 %x, %y
  %r4 = or i1 %m4, %c4    ; (X != MIN) || (X <= Y) --> true

  %m5 = icmp eq i8 %x, 127
  %c5 = icmp sge i8 %x, %y
  %r5 = and i1 %m5, %c5   ; (X == MAX) && (X >= Y) --> X == MAX

  %m6 = icmp ne i8 %x, 127
  %c6 = icmp slt i8 %x, %y
  %r6 = or i1 %m6, %c6   ; (X != MAX) || (X < Y) --> X != MAX

  %m7 = icmp eq i8 %x, -128
  %c7 = icmp sle i8 %x, %y
  %r7 = and i1 %m7, %c7   ; (X == MIN) && (X <= Y) --> X == MIN

  %m8 = icmp ne i8 %x, -128
  %c8 = icmp sgt i8 %x, %y
  %r8 = or i1 %m8, %c8   ; (X != MIN) || (X > Y) --> X != MIN

  %m9 = icmp ne i8 %x, 127
  %c9 = icmp slt i8 %x, %y
  %r9 = and i1 %m9, %c9    ; (X != MAX) && (X < Y) --> X < Y

  %m10 = icmp eq i8 %x, 127
  %c10 = icmp sge i8 %x, %y
  %r10 = or i1 %m10, %c10    ; (X == MAX) || (X >= Y) --> X >= Y

  %m11 = icmp ne i8 %x, -128
  %c11 = icmp sgt i8 %x, %y
  %r11 = and i1 %m11, %c11    ; (X != MIN) && (X > Y) --> X > Y

  %m12 = icmp eq i8 %x, -128
  %c12 = icmp sle i8 %x, %y
  %r12 = or i1 %m12, %c12    ; (X == MIN) || (X <= Y) --> X <= Y

  call void @use(i1 %r1, i1 %r2, i1 %r3, i1 %r4, i1 %r5, i1 %r6, i1 %r7, i1 %r8, i1 %r9, i1 %r10, i1 %r11, i1 %r12)
  ret void
}

define void @tgt(i8 %x, i8 %y)  {
  %m5 = icmp eq i8 %x, 127
  %m6 = icmp ne i8 %x, 127
  %m7 = icmp eq i8 %x, -128
  %m8 = icmp ne i8 %x, -128
  %c9 = icmp slt i8 %x, %y
  %c10 = icmp sge i8 %x, %y
  %c11 = icmp sgt i8 %x, %y
  %c12 = icmp sle i8 %x, %y
  call void @use(i1 0, i1 1, i1 0, i1 1, i1 %m5, i1 %m6, i1 %m7, i1 %m8, i1 %c9, i1 %c10, i1 %c11, i1 %c12)
  ret void
}

Differential Revision: https://reviews.llvm.org/D78430
  • Loading branch information
rotateright committed Apr 23, 2020
1 parent 6a10560 commit e86eff0
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 154 deletions.
89 changes: 79 additions & 10 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Expand Up @@ -1480,28 +1480,33 @@ static Value *simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp,
else
return nullptr;

// X < Y && Y != 0 --> X < Y
// X < Y || Y != 0 --> Y != 0
if (UnsignedPred == ICmpInst::ICMP_ULT && EqPred == ICmpInst::ICMP_NE)
return IsAnd ? UnsignedICmp : ZeroICmp;
// X > Y && Y == 0 --> Y == 0 iff X != 0
// X > Y || Y == 0 --> X > Y iff X != 0
if (UnsignedPred == ICmpInst::ICMP_UGT && EqPred == ICmpInst::ICMP_EQ &&
isKnownNonZero(X, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
return IsAnd ? ZeroICmp : UnsignedICmp;

// X <= Y && Y != 0 --> X <= Y iff X != 0
// X <= Y || Y != 0 --> Y != 0 iff X != 0
if (UnsignedPred == ICmpInst::ICMP_ULE && EqPred == ICmpInst::ICMP_NE &&
isKnownNonZero(X, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
return IsAnd ? UnsignedICmp : ZeroICmp;

// The transforms below here are expected to be handled more generally with
// simplifyAndOrOfICmpsWithLimitConst() or in InstCombine's
// foldAndOrOfICmpsWithConstEq(). If we are looking to trim optimizer overlap,
// these are candidates for removal.

// X < Y && Y != 0 --> X < Y
// X < Y || Y != 0 --> Y != 0
if (UnsignedPred == ICmpInst::ICMP_ULT && EqPred == ICmpInst::ICMP_NE)
return IsAnd ? UnsignedICmp : ZeroICmp;

// X >= Y && Y == 0 --> Y == 0
// X >= Y || Y == 0 --> X >= Y
if (UnsignedPred == ICmpInst::ICMP_UGE && EqPred == ICmpInst::ICMP_EQ)
return IsAnd ? ZeroICmp : UnsignedICmp;

// X > Y && Y == 0 --> Y == 0 iff X != 0
// X > Y || Y == 0 --> X > Y iff X != 0
if (UnsignedPred == ICmpInst::ICMP_UGT && EqPred == ICmpInst::ICMP_EQ &&
isKnownNonZero(X, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
return IsAnd ? ZeroICmp : UnsignedICmp;

// X < Y && Y == 0 --> false
if (UnsignedPred == ICmpInst::ICMP_ULT && EqPred == ICmpInst::ICMP_EQ &&
IsAnd)
Expand Down Expand Up @@ -1690,6 +1695,64 @@ static Value *simplifyAndOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1,
return nullptr;
}

/// Try to eliminate compares with signed or unsigned min/max constants.
static Value *simplifyAndOrOfICmpsWithLimitConst(ICmpInst *Cmp0, ICmpInst *Cmp1,
bool IsAnd) {
// Canonicalize an equality compare as Cmp0.
if (Cmp1->isEquality())
std::swap(Cmp0, Cmp1);
if (!Cmp0->isEquality())
return nullptr;

// The equality compare must be against a constant. Convert the 'null' pointer
// constant to an integer zero value.
APInt MinMaxC;
const APInt *C;
if (match(Cmp0->getOperand(1), m_APInt(C)))
MinMaxC = *C;
else if (isa<ConstantPointerNull>(Cmp0->getOperand(1)))
MinMaxC = APInt::getNullValue(8);
else
return nullptr;

// The non-equality compare must include a common operand (X). Canonicalize
// the common operand as operand 0 (the predicate is swapped if the common
// operand was operand 1).
ICmpInst::Predicate Pred0 = Cmp0->getPredicate();
Value *X = Cmp0->getOperand(0);
ICmpInst::Predicate Pred1;
if (!match(Cmp1, m_c_ICmp(Pred1, m_Specific(X), m_Value())) ||
ICmpInst::isEquality(Pred1))
return nullptr;

// DeMorganize if this is 'or': P0 || P1 --> !P0 && !P1.
if (!IsAnd) {
Pred0 = ICmpInst::getInversePredicate(Pred0);
Pred1 = ICmpInst::getInversePredicate(Pred1);
}

// Normalize to unsigned compare and unsigned min/max value.
// Example for 8-bit: -128 + 128 -> 0; 127 + 128 -> 255
if (ICmpInst::isSigned(Pred1)) {
Pred1 = ICmpInst::getUnsignedPredicate(Pred1);
MinMaxC += APInt::getSignedMinValue(MinMaxC.getBitWidth());
}

// (X != MAX) && (X < Y) --> X < Y
// (X == MAX) || (X >= Y) --> X >= Y
if (MinMaxC.isMaxValue())
if (Pred0 == ICmpInst::ICMP_NE && Pred1 == ICmpInst::ICMP_ULT)
return Cmp1;

// (X != MIN) && (X > Y) --> X > Y
// (X == MIN) || (X <= Y) --> X <= Y
if (MinMaxC.isMinValue())
if (Pred0 == ICmpInst::ICMP_NE && Pred1 == ICmpInst::ICMP_UGT)
return Cmp1;

return nullptr;
}

static Value *simplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1,
const SimplifyQuery &Q) {
if (Value *X = simplifyUnsignedRangeCheck(Op0, Op1, /*IsAnd=*/true, Q))
Expand All @@ -1705,6 +1768,9 @@ static Value *simplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1,
if (Value *X = simplifyAndOrOfICmpsWithConstants(Op0, Op1, true))
return X;

if (Value *X = simplifyAndOrOfICmpsWithLimitConst(Op0, Op1, true))
return X;

if (Value *X = simplifyAndOrOfICmpsWithZero(Op0, Op1, true))
return X;

Expand Down Expand Up @@ -1778,6 +1844,9 @@ static Value *simplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1,
if (Value *X = simplifyAndOrOfICmpsWithConstants(Op0, Op1, false))
return X;

if (Value *X = simplifyAndOrOfICmpsWithLimitConst(Op0, Op1, false))
return X;

if (Value *X = simplifyAndOrOfICmpsWithZero(Op0, Op1, false))
return X;

Expand Down
96 changes: 24 additions & 72 deletions llvm/test/Transforms/InstCombine/and-or-icmp-min-max.ll
Expand Up @@ -644,9 +644,7 @@ define i1 @ule_swap_and_min_commute(i8 %x, i8 %y) {
define i1 @sge_or_max(i8 %x, i8 %y) {
; CHECK-LABEL: @sge_or_max(
; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X]], 127
; CHECK-NEXT: [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp sge i8 %x, %y
%cmpeq = icmp eq i8 %x, 127
Expand All @@ -657,9 +655,7 @@ define i1 @sge_or_max(i8 %x, i8 %y) {
define i1 @sge_or_max_commute(i8 %x, i8 %y) {
; CHECK-LABEL: @sge_or_max_commute(
; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X]], 127
; CHECK-NEXT: [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp sge i8 %x, %y
%cmpeq = icmp eq i8 %x, 127
Expand All @@ -670,9 +666,7 @@ define i1 @sge_or_max_commute(i8 %x, i8 %y) {
define i1 @sge_swap_or_max(i8 %x, i8 %y) {
; CHECK-LABEL: @sge_swap_or_max(
; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X]], 127
; CHECK-NEXT: [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp sle i8 %y, %x
%cmpeq = icmp eq i8 %x, 127
Expand All @@ -683,9 +677,7 @@ define i1 @sge_swap_or_max(i8 %x, i8 %y) {
define i1 @sge_swap_or_max_commute(i8 %x, i8 %y) {
; CHECK-LABEL: @sge_swap_or_max_commute(
; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X]], 127
; CHECK-NEXT: [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp sle i8 %y, %x
%cmpeq = icmp eq i8 %x, 127
Expand All @@ -696,9 +688,7 @@ define i1 @sge_swap_or_max_commute(i8 %x, i8 %y) {
define i1 @uge_or_max(i8 %x, i8 %y) {
; CHECK-LABEL: @uge_or_max(
; CHECK-NEXT: [[CMP:%.*]] = icmp uge i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X]], -1
; CHECK-NEXT: [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp uge i8 %x, %y
%cmpeq = icmp eq i8 %x, 255
Expand All @@ -709,9 +699,7 @@ define i1 @uge_or_max(i8 %x, i8 %y) {
define i1 @uge_or_max_commute(i8 %x, i8 %y) {
; CHECK-LABEL: @uge_or_max_commute(
; CHECK-NEXT: [[CMP:%.*]] = icmp uge i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X]], -1
; CHECK-NEXT: [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp uge i8 %x, %y
%cmpeq = icmp eq i8 %x, 255
Expand All @@ -722,9 +710,7 @@ define i1 @uge_or_max_commute(i8 %x, i8 %y) {
define i1 @uge_swap_or_max(i8 %x, i8 %y) {
; CHECK-LABEL: @uge_swap_or_max(
; CHECK-NEXT: [[CMP:%.*]] = icmp ule i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X]], -1
; CHECK-NEXT: [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp ule i8 %y, %x
%cmpeq = icmp eq i8 %x, 255
Expand All @@ -735,9 +721,7 @@ define i1 @uge_swap_or_max(i8 %x, i8 %y) {
define i1 @uge_swap_or_max_commute(i8 %x, i8 %y) {
; CHECK-LABEL: @uge_swap_or_max_commute(
; CHECK-NEXT: [[CMP:%.*]] = icmp ule i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X]], -1
; CHECK-NEXT: [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp ule i8 %y, %x
%cmpeq = icmp eq i8 %x, 255
Expand All @@ -754,9 +738,7 @@ define i1 @uge_swap_or_max_commute(i8 %x, i8 %y) {
define i1 @sle_or_min(i8 %x, i8 %y) {
; CHECK-LABEL: @sle_or_min(
; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
; CHECK-NEXT: [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp sle i8 %x, %y
%cmpeq = icmp eq i8 %x, 128
Expand All @@ -767,9 +749,7 @@ define i1 @sle_or_min(i8 %x, i8 %y) {
define i1 @sle_or_min_commute(i8 %x, i8 %y) {
; CHECK-LABEL: @sle_or_min_commute(
; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
; CHECK-NEXT: [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp sle i8 %x, %y
%cmpeq = icmp eq i8 %x, 128
Expand All @@ -780,9 +760,7 @@ define i1 @sle_or_min_commute(i8 %x, i8 %y) {
define i1 @sle_swap_or_min(i8 %x, i8 %y) {
; CHECK-LABEL: @sle_swap_or_min(
; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
; CHECK-NEXT: [[R:%.*]] = or i1 [[CMP]], [[CMPEQ]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp sge i8 %y, %x
%cmpeq = icmp eq i8 %x, 128
Expand All @@ -793,9 +771,7 @@ define i1 @sle_swap_or_min(i8 %x, i8 %y) {
define i1 @sle_swap_or_min_commute(i8 %x, i8 %y) {
; CHECK-LABEL: @sle_swap_or_min_commute(
; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X]], -128
; CHECK-NEXT: [[R:%.*]] = or i1 [[CMPEQ]], [[CMP]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp sge i8 %y, %x
%cmpeq = icmp eq i8 %x, 128
Expand Down Expand Up @@ -856,9 +832,7 @@ define i1 @ule_swap_or_min_commute(i8 %x, i8 %y) {
define i1 @slt_and_not_max(i8 %x, i8 %y) {
; CHECK-LABEL: @slt_and_not_max(
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
; CHECK-NEXT: [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp slt i8 %x, %y
%cmpeq = icmp ne i8 %x, 127
Expand All @@ -869,9 +843,7 @@ define i1 @slt_and_not_max(i8 %x, i8 %y) {
define i1 @slt_and_not_max_commute(i8 %x, i8 %y) {
; CHECK-LABEL: @slt_and_not_max_commute(
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
; CHECK-NEXT: [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp slt i8 %x, %y
%cmpeq = icmp ne i8 %x, 127
Expand All @@ -882,9 +854,7 @@ define i1 @slt_and_not_max_commute(i8 %x, i8 %y) {
define i1 @slt_swap_and_not_max(i8 %x, i8 %y) {
; CHECK-LABEL: @slt_swap_and_not_max(
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
; CHECK-NEXT: [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp sgt i8 %y, %x
%cmpeq = icmp ne i8 %x, 127
Expand All @@ -895,9 +865,7 @@ define i1 @slt_swap_and_not_max(i8 %x, i8 %y) {
define i1 @slt_swap_and_not_max_commute(i8 %x, i8 %y) {
; CHECK-LABEL: @slt_swap_and_not_max_commute(
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne i8 [[X]], 127
; CHECK-NEXT: [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp sgt i8 %y, %x
%cmpeq = icmp ne i8 %x, 127
Expand All @@ -908,9 +876,7 @@ define i1 @slt_swap_and_not_max_commute(i8 %x, i8 %y) {
define i1 @ult_and_not_max(i8 %x, i8 %y) {
; CHECK-LABEL: @ult_and_not_max(
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
; CHECK-NEXT: [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp ult i8 %x, %y
%cmpeq = icmp ne i8 %x, 255
Expand All @@ -921,9 +887,7 @@ define i1 @ult_and_not_max(i8 %x, i8 %y) {
define i1 @ult_and_not_max_commute(i8 %x, i8 %y) {
; CHECK-LABEL: @ult_and_not_max_commute(
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
; CHECK-NEXT: [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp ult i8 %x, %y
%cmpeq = icmp ne i8 %x, 255
Expand All @@ -934,9 +898,7 @@ define i1 @ult_and_not_max_commute(i8 %x, i8 %y) {
define i1 @ult_swap_and_not_max(i8 %x, i8 %y) {
; CHECK-LABEL: @ult_swap_and_not_max(
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
; CHECK-NEXT: [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp ugt i8 %y, %x
%cmpeq = icmp ne i8 %x, 255
Expand All @@ -947,9 +909,7 @@ define i1 @ult_swap_and_not_max(i8 %x, i8 %y) {
define i1 @ult_swap_and_not_max_commute(i8 %x, i8 %y) {
; CHECK-LABEL: @ult_swap_and_not_max_commute(
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne i8 [[X]], -1
; CHECK-NEXT: [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp ugt i8 %y, %x
%cmpeq = icmp ne i8 %x, 255
Expand All @@ -966,9 +926,7 @@ define i1 @ult_swap_and_not_max_commute(i8 %x, i8 %y) {
define i1 @sgt_and_not_min(i8 %x, i8 %y) {
; CHECK-LABEL: @sgt_and_not_min(
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
; CHECK-NEXT: [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp sgt i8 %x, %y
%cmpeq = icmp ne i8 %x, 128
Expand All @@ -979,9 +937,7 @@ define i1 @sgt_and_not_min(i8 %x, i8 %y) {
define i1 @sgt_and_not_min_commute(i8 %x, i8 %y) {
; CHECK-LABEL: @sgt_and_not_min_commute(
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
; CHECK-NEXT: [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp sgt i8 %x, %y
%cmpeq = icmp ne i8 %x, 128
Expand All @@ -992,9 +948,7 @@ define i1 @sgt_and_not_min_commute(i8 %x, i8 %y) {
define i1 @sgt_swap_and_not_min(i8 %x, i8 %y) {
; CHECK-LABEL: @sgt_swap_and_not_min(
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
; CHECK-NEXT: [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp slt i8 %y, %x
%cmpeq = icmp ne i8 %x, 128
Expand All @@ -1005,9 +959,7 @@ define i1 @sgt_swap_and_not_min(i8 %x, i8 %y) {
define i1 @sgt_swap_and_not_min_commute(i8 %x, i8 %y) {
; CHECK-LABEL: @sgt_swap_and_not_min_commute(
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne i8 [[X]], -128
; CHECK-NEXT: [[R:%.*]] = and i1 [[CMPEQ]], [[CMP]]
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%cmp = icmp slt i8 %y, %x
%cmpeq = icmp ne i8 %x, 128
Expand Down

0 comments on commit e86eff0

Please sign in to comment.