simplify the conditions on two gigantic if's, decreasing indentation

a bit.  Next step is to factor out into their own helper functions.

llvm-svn: 59397
This commit is contained in:
Chris Lattner 2008-11-16 04:55:20 +00:00
parent a3b2ef6fa9
commit b37b6e7e96
1 changed files with 286 additions and 287 deletions

View File

@ -3240,13 +3240,12 @@ static Value *getFCmpValue(bool isordered, unsigned code,
}
}
/// PredicatesFoldable - Return true if both predicates match sign or if at
/// least one of them is an equality comparison (which is signless).
static bool PredicatesFoldable(ICmpInst::Predicate p1, ICmpInst::Predicate p2) {
return (ICmpInst::isSignedPredicate(p1) == ICmpInst::isSignedPredicate(p2)) ||
(ICmpInst::isSignedPredicate(p1) &&
(p2 == ICmpInst::ICMP_EQ || p2 == ICmpInst::ICMP_NE)) ||
(ICmpInst::isSignedPredicate(p2) &&
(p1 == ICmpInst::ICMP_EQ || p1 == ICmpInst::ICMP_NE));
(ICmpInst::isSignedPredicate(p1) && ICmpInst::isEquality(p2)) ||
(ICmpInst::isSignedPredicate(p2) && ICmpInst::isEquality(p1));
}
namespace {
@ -3793,18 +3792,18 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
Value *Val;
ConstantInt *LHSCst, *RHSCst;
ICmpInst::Predicate LHSCC, RHSCC;
if (match(Op0, m_ICmp(LHSCC, m_Value(Val), m_ConstantInt(LHSCst))))
if (match(RHS, m_ICmp(RHSCC, m_Specific(Val), m_ConstantInt(RHSCst))))
// ICMP_[GL]E X, CST is folded to ICMP_[GL]T elsewhere.
if (LHSCC != ICmpInst::ICMP_UGE && LHSCC != ICmpInst::ICMP_ULE &&
// (icmp1 A, C1) & (icmp2 A, C2) --> something simpler.
if (match(Op0, m_ICmp(LHSCC, m_Value(Val), m_ConstantInt(LHSCst))) &&
match(RHS, m_ICmp(RHSCC, m_Specific(Val), m_ConstantInt(RHSCst))) &&
// ICMP_[US][GL]E X, CST is folded to ICMP_[US][GL]T elsewhere.
LHSCC != ICmpInst::ICMP_UGE && LHSCC != ICmpInst::ICMP_ULE &&
RHSCC != ICmpInst::ICMP_UGE && RHSCC != ICmpInst::ICMP_ULE &&
LHSCC != ICmpInst::ICMP_SGE && LHSCC != ICmpInst::ICMP_SLE &&
RHSCC != ICmpInst::ICMP_SGE && RHSCC != ICmpInst::ICMP_SLE &&
// Don't try to fold ICMP_SLT + ICMP_ULT.
(ICmpInst::isEquality(LHSCC) || ICmpInst::isEquality(RHSCC) ||
ICmpInst::isSignedPredicate(LHSCC) ==
ICmpInst::isSignedPredicate(RHSCC))) {
// We can't fold (ugt x, C) & (sgt x, C2).
PredicatesFoldable(LHSCC, RHSCC)) {
// Ensure that the larger constant is on the RHS.
ICmpInst::Predicate GT;
if (ICmpInst::isSignedPredicate(LHSCC) ||
@ -3914,8 +3913,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
return new ICmpInst(LHSCC, Val, RHSCst);
break; // (X u> 13 & X != 15) -> no change
case ICmpInst::ICMP_ULT: // (X u> 13 & X u< 15) ->(X-14) <u 1
return InsertRangeTest(Val, AddOne(LHSCst), RHSCst, false,
true, I);
return InsertRangeTest(Val, AddOne(LHSCst), RHSCst, false, true, I);
case ICmpInst::ICMP_SLT: // (X u> 13 & X s< 15) -> no change
break;
}
@ -4427,13 +4425,16 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
Value *Val;
ConstantInt *LHSCst, *RHSCst;
ICmpInst::Predicate LHSCC, RHSCC;
if (match(Op0, m_ICmp(LHSCC, m_Value(Val), m_ConstantInt(LHSCst))))
if (match(RHS, m_ICmp(RHSCC, m_Specific(Val), m_ConstantInt(RHSCst))))
// icmp [us][gl]e x, cst is folded to icmp [us][gl]t elsewhere.
if (LHSCC != ICmpInst::ICMP_UGE && LHSCC != ICmpInst::ICMP_ULE &&
// (icmp1 A, C1) | (icmp2 A, C2) --> something simpler.
if (match(Op0, m_ICmp(LHSCC, m_Value(Val), m_ConstantInt(LHSCst))) &&
match(RHS, m_ICmp(RHSCC, m_Specific(Val), m_ConstantInt(RHSCst))) &&
// ICMP_[US][GL]E X, CST is folded to ICMP_[US][GL]T elsewhere.
LHSCC != ICmpInst::ICMP_UGE && LHSCC != ICmpInst::ICMP_ULE &&
RHSCC != ICmpInst::ICMP_UGE && RHSCC != ICmpInst::ICMP_ULE &&
LHSCC != ICmpInst::ICMP_SGE && LHSCC != ICmpInst::ICMP_SLE &&
RHSCC != ICmpInst::ICMP_SGE && RHSCC != ICmpInst::ICMP_SLE &&
// We can't fold (ugt x, C) | (sgt x, C2).
PredicatesFoldable(LHSCC, RHSCC)) {
// Ensure that the larger constant is on the RHS.
@ -4506,8 +4507,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
// this can cause overflow.
if (RHSCst->isMaxValue(false))
return ReplaceInstUsesWith(I, LHS);
return InsertRangeTest(Val, LHSCst, AddOne(RHSCst), false,
false, I);
return InsertRangeTest(Val, LHSCst, AddOne(RHSCst), false, false, I);
case ICmpInst::ICMP_SGT: // (X u< 13 | X s> 15) -> no change
break;
case ICmpInst::ICMP_NE: // (X u< 13 | X != 15) -> X != 15
@ -4527,8 +4527,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
// this can cause overflow.
if (RHSCst->isMaxValue(true))
return ReplaceInstUsesWith(I, LHS);
return InsertRangeTest(Val, LHSCst, AddOne(RHSCst), true,
false, I);
return InsertRangeTest(Val, LHSCst, AddOne(RHSCst), true, false, I);
case ICmpInst::ICMP_UGT: // (X s< 13 | X u> 15) -> no change
break;
case ICmpInst::ICMP_NE: // (X s< 13 | X != 15) -> X != 15