[ValueTracking] Improve isImpliedCondition when the dominating cond is false.

llvm-svn: 267430
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 5ada78a..a9b8af1 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3962,8 +3962,8 @@
 }
 
 Optional<bool> llvm::isImpliedCondition(Value *LHS, Value *RHS,
-                                        const DataLayout &DL, unsigned Depth,
-                                        AssumptionCache *AC,
+                                        const DataLayout &DL, bool InvertAPred,
+                                        unsigned Depth, AssumptionCache *AC,
                                         const Instruction *CxtI,
                                         const DominatorTree *DT) {
   assert(LHS->getType() == RHS->getType() && "mismatched type");
@@ -3971,7 +3971,7 @@
   assert(OpTy->getScalarType()->isIntegerTy(1));
 
   // LHS ==> RHS by definition
-  if (LHS == RHS)
+  if (!InvertAPred && LHS == RHS)
     return true;
 
   if (OpTy->isVectorTy())
@@ -3987,6 +3987,9 @@
       !match(RHS, m_ICmp(BPred, m_Value(BLHS), m_Value(BRHS))))
     return None;
 
+  if (InvertAPred)
+    APred = CmpInst::getInversePredicate(APred);
+
   Optional<bool> Implication =
       isImpliedCondMatchingOperands(APred, ALHS, ARHS, BPred, BLHS, BRHS);
   if (Implication)