forked from OSchip/llvm-project
				
			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:
		
							parent
							
								
									a3b2ef6fa9
								
							
						
					
					
						commit
						b37b6e7e96
					
				| 
						 | 
					@ -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) {
 | 
					static bool PredicatesFoldable(ICmpInst::Predicate p1, ICmpInst::Predicate p2) {
 | 
				
			||||||
  return (ICmpInst::isSignedPredicate(p1) == ICmpInst::isSignedPredicate(p2)) ||
 | 
					  return (ICmpInst::isSignedPredicate(p1) == ICmpInst::isSignedPredicate(p2)) ||
 | 
				
			||||||
    (ICmpInst::isSignedPredicate(p1) && 
 | 
					         (ICmpInst::isSignedPredicate(p1) && ICmpInst::isEquality(p2)) ||
 | 
				
			||||||
     (p2 == ICmpInst::ICMP_EQ || p2 == ICmpInst::ICMP_NE)) ||
 | 
					         (ICmpInst::isSignedPredicate(p2) && ICmpInst::isEquality(p1));
 | 
				
			||||||
    (ICmpInst::isSignedPredicate(p2) && 
 | 
					 | 
				
			||||||
     (p1 == ICmpInst::ICMP_EQ || p1 == ICmpInst::ICMP_NE));
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace { 
 | 
					namespace { 
 | 
				
			||||||
| 
						 | 
					@ -3793,18 +3792,18 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
 | 
				
			||||||
    Value *Val;
 | 
					    Value *Val;
 | 
				
			||||||
    ConstantInt *LHSCst, *RHSCst;
 | 
					    ConstantInt *LHSCst, *RHSCst;
 | 
				
			||||||
    ICmpInst::Predicate LHSCC, RHSCC;
 | 
					    ICmpInst::Predicate LHSCC, RHSCC;
 | 
				
			||||||
    if (match(Op0, m_ICmp(LHSCC, m_Value(Val), m_ConstantInt(LHSCst))))
 | 
					    // (icmp1 A, C1) & (icmp2 A, C2) --> something simpler.
 | 
				
			||||||
      if (match(RHS, m_ICmp(RHSCC, m_Specific(Val), m_ConstantInt(RHSCst))))
 | 
					    if (match(Op0, m_ICmp(LHSCC, m_Value(Val), m_ConstantInt(LHSCst))) &&
 | 
				
			||||||
        // ICMP_[GL]E X, CST is folded to ICMP_[GL]T elsewhere.
 | 
					        match(RHS, m_ICmp(RHSCC, m_Specific(Val), m_ConstantInt(RHSCst))) &&
 | 
				
			||||||
        if (LHSCC != ICmpInst::ICMP_UGE && LHSCC != ICmpInst::ICMP_ULE &&
 | 
					        
 | 
				
			||||||
 | 
					        // 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 &&
 | 
					        RHSCC != ICmpInst::ICMP_UGE && RHSCC != ICmpInst::ICMP_ULE &&
 | 
				
			||||||
        LHSCC != ICmpInst::ICMP_SGE && LHSCC != ICmpInst::ICMP_SLE &&
 | 
					        LHSCC != ICmpInst::ICMP_SGE && LHSCC != ICmpInst::ICMP_SLE &&
 | 
				
			||||||
        RHSCC != ICmpInst::ICMP_SGE && RHSCC != ICmpInst::ICMP_SLE &&
 | 
					        RHSCC != ICmpInst::ICMP_SGE && RHSCC != ICmpInst::ICMP_SLE &&
 | 
				
			||||||
          
 | 
					          
 | 
				
			||||||
            // Don't try to fold ICMP_SLT + ICMP_ULT.
 | 
					        // We can't fold (ugt x, C) & (sgt x, C2).
 | 
				
			||||||
            (ICmpInst::isEquality(LHSCC) || ICmpInst::isEquality(RHSCC) ||
 | 
					        PredicatesFoldable(LHSCC, RHSCC)) {
 | 
				
			||||||
             ICmpInst::isSignedPredicate(LHSCC) == 
 | 
					 | 
				
			||||||
                 ICmpInst::isSignedPredicate(RHSCC))) {
 | 
					 | 
				
			||||||
      // Ensure that the larger constant is on the RHS.
 | 
					      // Ensure that the larger constant is on the RHS.
 | 
				
			||||||
      ICmpInst::Predicate GT;
 | 
					      ICmpInst::Predicate GT;
 | 
				
			||||||
      if (ICmpInst::isSignedPredicate(LHSCC) ||
 | 
					      if (ICmpInst::isSignedPredicate(LHSCC) ||
 | 
				
			||||||
| 
						 | 
					@ -3914,8 +3913,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
 | 
				
			||||||
            return new ICmpInst(LHSCC, Val, RHSCst);
 | 
					            return new ICmpInst(LHSCC, Val, RHSCst);
 | 
				
			||||||
          break;                        // (X u> 13 & X != 15) -> no change
 | 
					          break;                        // (X u> 13 & X != 15) -> no change
 | 
				
			||||||
        case ICmpInst::ICMP_ULT:        // (X u> 13 & X u< 15) ->(X-14) <u 1
 | 
					        case ICmpInst::ICMP_ULT:        // (X u> 13 & X u< 15) ->(X-14) <u 1
 | 
				
			||||||
              return InsertRangeTest(Val, AddOne(LHSCst), RHSCst, false, 
 | 
					          return InsertRangeTest(Val, AddOne(LHSCst), RHSCst, false, true, I);
 | 
				
			||||||
                                     true, I);
 | 
					 | 
				
			||||||
        case ICmpInst::ICMP_SLT:        // (X u> 13 & X s< 15) -> no change
 | 
					        case ICmpInst::ICMP_SLT:        // (X u> 13 & X s< 15) -> no change
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -4427,13 +4425,16 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
 | 
				
			||||||
    Value *Val;
 | 
					    Value *Val;
 | 
				
			||||||
    ConstantInt *LHSCst, *RHSCst;
 | 
					    ConstantInt *LHSCst, *RHSCst;
 | 
				
			||||||
    ICmpInst::Predicate LHSCC, RHSCC;
 | 
					    ICmpInst::Predicate LHSCC, RHSCC;
 | 
				
			||||||
    if (match(Op0, m_ICmp(LHSCC, m_Value(Val), m_ConstantInt(LHSCst))))
 | 
					    // (icmp1 A, C1) | (icmp2 A, C2) --> something simpler.
 | 
				
			||||||
      if (match(RHS, m_ICmp(RHSCC, m_Specific(Val), m_ConstantInt(RHSCst))))
 | 
					    if (match(Op0, m_ICmp(LHSCC, m_Value(Val), m_ConstantInt(LHSCst))) &&
 | 
				
			||||||
        // icmp [us][gl]e x, cst is folded to icmp [us][gl]t elsewhere.
 | 
					        match(RHS, m_ICmp(RHSCC, m_Specific(Val), m_ConstantInt(RHSCst))) &&
 | 
				
			||||||
        if (LHSCC != ICmpInst::ICMP_UGE && LHSCC != ICmpInst::ICMP_ULE &&
 | 
					        
 | 
				
			||||||
 | 
					        // 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 &&
 | 
					        RHSCC != ICmpInst::ICMP_UGE && RHSCC != ICmpInst::ICMP_ULE &&
 | 
				
			||||||
        LHSCC != ICmpInst::ICMP_SGE && LHSCC != ICmpInst::ICMP_SLE &&
 | 
					        LHSCC != ICmpInst::ICMP_SGE && LHSCC != ICmpInst::ICMP_SLE &&
 | 
				
			||||||
        RHSCC != ICmpInst::ICMP_SGE && RHSCC != ICmpInst::ICMP_SLE &&
 | 
					        RHSCC != ICmpInst::ICMP_SGE && RHSCC != ICmpInst::ICMP_SLE &&
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        // We can't fold (ugt x, C) | (sgt x, C2).
 | 
					        // We can't fold (ugt x, C) | (sgt x, C2).
 | 
				
			||||||
        PredicatesFoldable(LHSCC, RHSCC)) {
 | 
					        PredicatesFoldable(LHSCC, RHSCC)) {
 | 
				
			||||||
      // Ensure that the larger constant is on the RHS.
 | 
					      // Ensure that the larger constant is on the RHS.
 | 
				
			||||||
| 
						 | 
					@ -4506,8 +4507,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
 | 
				
			||||||
          // this can cause overflow.
 | 
					          // this can cause overflow.
 | 
				
			||||||
          if (RHSCst->isMaxValue(false))
 | 
					          if (RHSCst->isMaxValue(false))
 | 
				
			||||||
            return ReplaceInstUsesWith(I, LHS);
 | 
					            return ReplaceInstUsesWith(I, LHS);
 | 
				
			||||||
              return InsertRangeTest(Val, LHSCst, AddOne(RHSCst), false, 
 | 
					          return InsertRangeTest(Val, LHSCst, AddOne(RHSCst), false, false, I);
 | 
				
			||||||
                                     false, I);
 | 
					 | 
				
			||||||
        case ICmpInst::ICMP_SGT:        // (X u< 13 | X s> 15) -> no change
 | 
					        case ICmpInst::ICMP_SGT:        // (X u< 13 | X s> 15) -> no change
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        case ICmpInst::ICMP_NE:         // (X u< 13 | X != 15) -> X != 15
 | 
					        case ICmpInst::ICMP_NE:         // (X u< 13 | X != 15) -> X != 15
 | 
				
			||||||
| 
						 | 
					@ -4527,8 +4527,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
 | 
				
			||||||
          // this can cause overflow.
 | 
					          // this can cause overflow.
 | 
				
			||||||
          if (RHSCst->isMaxValue(true))
 | 
					          if (RHSCst->isMaxValue(true))
 | 
				
			||||||
            return ReplaceInstUsesWith(I, LHS);
 | 
					            return ReplaceInstUsesWith(I, LHS);
 | 
				
			||||||
              return InsertRangeTest(Val, LHSCst, AddOne(RHSCst), true, 
 | 
					          return InsertRangeTest(Val, LHSCst, AddOne(RHSCst), true, false, I);
 | 
				
			||||||
                                     false, I);
 | 
					 | 
				
			||||||
        case ICmpInst::ICMP_UGT:        // (X s< 13 | X u> 15) -> no change
 | 
					        case ICmpInst::ICMP_UGT:        // (X s< 13 | X u> 15) -> no change
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        case ICmpInst::ICMP_NE:         // (X s< 13 | X != 15) -> X != 15
 | 
					        case ICmpInst::ICMP_NE:         // (X s< 13 | X != 15) -> X != 15
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue