Remove unnecessary intermediate lambda. NFC
[oota-llvm.git] / lib / Analysis / InstructionSimplify.cpp
index 13812b1175fb7b4caeb2a35075bd9c4eb8c6b08c..0bd18c1a35cd447d4cb7c0e78b12955b89c4169f 100644 (file)
@@ -2090,8 +2090,7 @@ static Constant *computePointerICmp(const DataLayout &DL,
 
     // Is the set of underlying objects all noalias calls?
     auto IsNAC = [](SmallVectorImpl<Value *> &Objects) {
-      return std::all_of(Objects.begin(), Objects.end(),
-                         [](Value *V){ return isNoAliasCall(V); });
+      return std::all_of(Objects.begin(), Objects.end(), isNoAliasCall);
     };
 
     // Is the set of underlying objects all things which must be disjoint from
@@ -2128,54 +2127,6 @@ static Constant *computePointerICmp(const DataLayout &DL,
   return nullptr;
 }
 
-/// Return true if B is known to be implied by A.  A & B must be i1 (boolean)
-/// values or a vector of such values. Note that the truth table for
-/// implication is the same as <=u on i1 values (but not <=s!).  The truth
-/// table for both is: 
-///    | T | F (B)
-///  T | T | F
-///  F | T | T
-/// (A)
-static bool implies(Value *A, Value *B) {
-  assert(A->getType() == B->getType() && "mismatched type");
-  Type *OpTy = A->getType();
-  assert(OpTy->getScalarType()->isIntegerTy(1));
-  
-  // A ==> A by definition
-  if (A == B) return true;
-
-  if (OpTy->isVectorTy())
-    // TODO: extending the code below to handle vectors
-    return false;
-  assert(OpTy->isIntegerTy(1) && "implied by above");
-
-  ICmpInst::Predicate APred, BPred;
-  Value *I;
-  Value *L;
-  ConstantInt *CI;
-  // i +_{nsw} C_{>0} <s L ==> i <s L
-  if (match(A, m_ICmp(APred,
-                      m_NSWAdd(m_Value(I), m_ConstantInt(CI)),
-                      m_Value(L))) &&
-      APred == ICmpInst::ICMP_SLT &&
-      !CI->isNegative() &&
-      match(B, m_ICmp(BPred, m_Specific(I), m_Specific(L))) &&
-      BPred == ICmpInst::ICMP_SLT)
-    return true;
-
-  // i +_{nuw} C_{>0} <u L ==> i <u L
-  if (match(A, m_ICmp(APred,
-                      m_NUWAdd(m_Value(I), m_ConstantInt(CI)),
-                      m_Value(L))) &&
-      APred == ICmpInst::ICMP_ULT &&
-      !CI->isNegative() &&
-      match(B, m_ICmp(BPred, m_Specific(I), m_Specific(L))) &&
-      BPred == ICmpInst::ICMP_ULT)
-    return true;
-
-  return false;
-}
-
 /// SimplifyICmpInst - Given operands for an ICmpInst, see if we can
 /// fold the result.  If not, this returns null.
 static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
@@ -2224,7 +2175,18 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
       // X >=u 1 -> X
       if (match(RHS, m_One()))
         return LHS;
-      if (implies(RHS, LHS))
+      if (isImpliedCondition(RHS, LHS, Q.DL))
+        return getTrue(ITy);
+      break;
+    case ICmpInst::ICMP_SGE:
+      /// For signed comparison, the values for an i1 are 0 and -1 
+      /// respectively. This maps into a truth table of:
+      /// LHS | RHS | LHS >=s RHS   | LHS implies RHS
+      ///  0  |  0  |  1 (0 >= 0)   |  1
+      ///  0  |  1  |  1 (0 >= -1)  |  1
+      ///  1  |  0  |  0 (-1 >= 0)  |  0
+      ///  1  |  1  |  1 (-1 >= -1) |  1
+      if (isImpliedCondition(LHS, RHS, Q.DL))
         return getTrue(ITy);
       break;
     case ICmpInst::ICMP_SLT:
@@ -2238,7 +2200,7 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
         return LHS;
       break;
     case ICmpInst::ICMP_ULE:
-      if (implies(LHS, RHS))
+      if (isImpliedCondition(LHS, RHS, Q.DL))
         return getTrue(ITy);
       break;
     }