From af83e40dee4270cf5a3b34229b981e6d7a5d07da Mon Sep 17 00:00:00 2001 From: Chad Rosier Date: Thu, 21 Apr 2016 14:04:54 +0000 Subject: Refactor implied condition logic from ValueTracking directly into CmpInst. NFC. Differential Revision: http://reviews.llvm.org/D19330 llvm-svn: 266987 --- llvm/lib/Analysis/ValueTracking.cpp | 54 ++----------------------------------- 1 file changed, 2 insertions(+), 52 deletions(-) (limited to 'llvm/lib/Analysis/ValueTracking.cpp') diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 7053195..0f6b0ec 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -3935,61 +3935,11 @@ static Optional isImpliedCondMatchingOperands(CmpInst::Predicate APred, std::swap(BLHS, BRHS); BPred = ICmpInst::getSwappedPredicate(BPred); } - - // If the predicates match, then we know the first condition implies the - // second is true. - if (APred == BPred) + if (CmpInst::isTrueWhenOperandsMatch(APred, BPred)) return true; - - // If an inverted APred matches BPred, we can infer the second condition is - // false. - if (CmpInst::getInversePredicate(APred) == BPred) + if (CmpInst::isFalseWhenOperandsMatch(APred, BPred)) return false; - // If a swapped APred matches BPred, we can infer the second condition is - // false in many cases. - if (CmpInst::getSwappedPredicate(APred) == BPred) { - switch (APred) { - default: - break; - case CmpInst::ICMP_UGT: // A >u B implies A u B is false. - case CmpInst::ICMP_SGT: // A >s B implies A s B is false. - return false; - } - } - - // The predicates must match sign or at least one of them must be an equality - // comparison (which is signless). - if (ICmpInst::isSigned(APred) != ICmpInst::isSigned(BPred) && - !ICmpInst::isEquality(APred) && !ICmpInst::isEquality(BPred)) - return None; - - switch (APred) { - default: - break; - case CmpInst::ICMP_EQ: - // A == B implies A > B and A < B are false. - if (CmpInst::isFalseWhenEqual(BPred)) - return false; - - break; - case CmpInst::ICMP_UGT: - case CmpInst::ICMP_ULT: - case CmpInst::ICMP_SGT: - case CmpInst::ICMP_SLT: - // A > B implies A == B is false. - // A < B implies A == B is false. - if (BPred == CmpInst::ICMP_EQ) - return false; - - // A > B implies A != B is true. - // A < B implies A != B is true. - if (BPred == CmpInst::ICMP_NE) - return true; - break; - } return None; } -- cgit v1.1