Skip to content

Commit

Permalink
[InstSimplify] Remove redundant simplifyAndOrOfICmpsWithZero() fold (…
Browse files Browse the repository at this point in the history
…NFCI)

This has been subsumed by simplifyAndOrWithICmpEq().
  • Loading branch information
nikic committed Nov 7, 2023
1 parent 013d1ca commit 0c6a77b
Showing 1 changed file with 0 additions and 43 deletions.
43 changes: 0 additions & 43 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1674,43 +1674,6 @@ static Value *simplifyAndOrOfICmpsWithConstants(ICmpInst *Cmp0, ICmpInst *Cmp1,
return nullptr;
}

static Value *simplifyAndOrOfICmpsWithZero(ICmpInst *Cmp0, ICmpInst *Cmp1,
bool IsAnd) {
ICmpInst::Predicate P0 = Cmp0->getPredicate(), P1 = Cmp1->getPredicate();
if (!match(Cmp0->getOperand(1), m_Zero()) ||
!match(Cmp1->getOperand(1), m_Zero()) || P0 != P1)
return nullptr;

if ((IsAnd && P0 != ICmpInst::ICMP_NE) || (!IsAnd && P1 != ICmpInst::ICMP_EQ))
return nullptr;

// We have either "(X == 0 || Y == 0)" or "(X != 0 && Y != 0)".
Value *X = Cmp0->getOperand(0);
Value *Y = Cmp1->getOperand(0);

// If one of the compares is a masked version of a (not) null check, then
// that compare implies the other, so we eliminate the other. Optionally, look
// through a pointer-to-int cast to match a null check of a pointer type.

// (X == 0) || (([ptrtoint] X & ?) == 0) --> ([ptrtoint] X & ?) == 0
// (X == 0) || ((? & [ptrtoint] X) == 0) --> (? & [ptrtoint] X) == 0
// (X != 0) && (([ptrtoint] X & ?) != 0) --> ([ptrtoint] X & ?) != 0
// (X != 0) && ((? & [ptrtoint] X) != 0) --> (? & [ptrtoint] X) != 0
if (match(Y, m_c_And(m_Specific(X), m_Value())) ||
match(Y, m_c_And(m_PtrToInt(m_Specific(X)), m_Value())))
return Cmp1;

// (([ptrtoint] Y & ?) == 0) || (Y == 0) --> ([ptrtoint] Y & ?) == 0
// ((? & [ptrtoint] Y) == 0) || (Y == 0) --> (? & [ptrtoint] Y) == 0
// (([ptrtoint] Y & ?) != 0) && (Y != 0) --> ([ptrtoint] Y & ?) != 0
// ((? & [ptrtoint] Y) != 0) && (Y != 0) --> (? & [ptrtoint] Y) != 0
if (match(X, m_c_And(m_Specific(Y), m_Value())) ||
match(X, m_c_And(m_PtrToInt(m_Specific(Y)), m_Value())))
return Cmp0;

return nullptr;
}

static Value *simplifyAndOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1,
const InstrInfoQuery &IIQ) {
// (icmp (add V, C0), C1) & (icmp V, C0)
Expand Down Expand Up @@ -1789,9 +1752,6 @@ static Value *simplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1,
if (Value *X = simplifyAndOrOfICmpsWithConstants(Op0, Op1, true))
return X;

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

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

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

if (Value *X = simplifyAndOrOfICmpsWithCtpop(Op0, Op1, false))
return X;
if (Value *X = simplifyAndOrOfICmpsWithCtpop(Op1, Op0, false))
Expand Down

0 comments on commit 0c6a77b

Please sign in to comment.