Skip to content

Commit fb01f68

Browse files
committed
[InstSimplify] Remove redundant simplifyAndOrOfICmpsWithLimitConst() fold (NFCI)
This fold has been subsumed by simplifyAndOrWithICmpEq().
1 parent 429098c commit fb01f68

File tree

1 file changed

+0
-66
lines changed

1 file changed

+0
-66
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,66 +1758,6 @@ static Value *simplifyAndOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1,
17581758
return nullptr;
17591759
}
17601760

1761-
/// Try to eliminate compares with signed or unsigned min/max constants.
1762-
static Value *simplifyAndOrOfICmpsWithLimitConst(ICmpInst *Cmp0, ICmpInst *Cmp1,
1763-
bool IsAnd) {
1764-
// Canonicalize an equality compare as Cmp0.
1765-
if (Cmp1->isEquality())
1766-
std::swap(Cmp0, Cmp1);
1767-
if (!Cmp0->isEquality())
1768-
return nullptr;
1769-
1770-
// The non-equality compare must include a common operand (X). Canonicalize
1771-
// the common operand as operand 0 (the predicate is swapped if the common
1772-
// operand was operand 1).
1773-
ICmpInst::Predicate Pred0 = Cmp0->getPredicate();
1774-
Value *X = Cmp0->getOperand(0);
1775-
ICmpInst::Predicate Pred1;
1776-
bool HasNotOp = match(Cmp1, m_c_ICmp(Pred1, m_Not(m_Specific(X)), m_Value()));
1777-
if (!HasNotOp && !match(Cmp1, m_c_ICmp(Pred1, m_Specific(X), m_Value())))
1778-
return nullptr;
1779-
if (ICmpInst::isEquality(Pred1))
1780-
return nullptr;
1781-
1782-
// The equality compare must be against a constant. Flip bits if we matched
1783-
// a bitwise not. Convert a null pointer constant to an integer zero value.
1784-
APInt MinMaxC;
1785-
const APInt *C;
1786-
if (match(Cmp0->getOperand(1), m_APInt(C)))
1787-
MinMaxC = HasNotOp ? ~*C : *C;
1788-
else if (isa<ConstantPointerNull>(Cmp0->getOperand(1)))
1789-
MinMaxC = APInt::getZero(8);
1790-
else
1791-
return nullptr;
1792-
1793-
// DeMorganize if this is 'or': P0 || P1 --> !P0 && !P1.
1794-
if (!IsAnd) {
1795-
Pred0 = ICmpInst::getInversePredicate(Pred0);
1796-
Pred1 = ICmpInst::getInversePredicate(Pred1);
1797-
}
1798-
1799-
// Normalize to unsigned compare and unsigned min/max value.
1800-
// Example for 8-bit: -128 + 128 -> 0; 127 + 128 -> 255
1801-
if (ICmpInst::isSigned(Pred1)) {
1802-
Pred1 = ICmpInst::getUnsignedPredicate(Pred1);
1803-
MinMaxC += APInt::getSignedMinValue(MinMaxC.getBitWidth());
1804-
}
1805-
1806-
// (X != MAX) && (X < Y) --> X < Y
1807-
// (X == MAX) || (X >= Y) --> X >= Y
1808-
if (MinMaxC.isMaxValue())
1809-
if (Pred0 == ICmpInst::ICMP_NE && Pred1 == ICmpInst::ICMP_ULT)
1810-
return Cmp1;
1811-
1812-
// (X != MIN) && (X > Y) --> X > Y
1813-
// (X == MIN) || (X <= Y) --> X <= Y
1814-
if (MinMaxC.isMinValue())
1815-
if (Pred0 == ICmpInst::ICMP_NE && Pred1 == ICmpInst::ICMP_UGT)
1816-
return Cmp1;
1817-
1818-
return nullptr;
1819-
}
1820-
18211761
/// Try to simplify and/or of icmp with ctpop intrinsic.
18221762
static Value *simplifyAndOrOfICmpsWithCtpop(ICmpInst *Cmp0, ICmpInst *Cmp1,
18231763
bool IsAnd) {
@@ -1849,9 +1789,6 @@ static Value *simplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1,
18491789
if (Value *X = simplifyAndOrOfICmpsWithConstants(Op0, Op1, true))
18501790
return X;
18511791

1852-
if (Value *X = simplifyAndOrOfICmpsWithLimitConst(Op0, Op1, true))
1853-
return X;
1854-
18551792
if (Value *X = simplifyAndOrOfICmpsWithZero(Op0, Op1, true))
18561793
return X;
18571794

@@ -1925,9 +1862,6 @@ static Value *simplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1,
19251862
if (Value *X = simplifyAndOrOfICmpsWithConstants(Op0, Op1, false))
19261863
return X;
19271864

1928-
if (Value *X = simplifyAndOrOfICmpsWithLimitConst(Op0, Op1, false))
1929-
return X;
1930-
19311865
if (Value *X = simplifyAndOrOfICmpsWithZero(Op0, Op1, false))
19321866
return X;
19331867

0 commit comments

Comments
 (0)