diff options
author | Chad Rosier <mcrosier@codeaurora.org> | 2016-04-21 14:04:54 +0000 |
---|---|---|
committer | Chad Rosier <mcrosier@codeaurora.org> | 2016-04-21 14:04:54 +0000 |
commit | af83e40dee4270cf5a3b34229b981e6d7a5d07da (patch) | |
tree | a97484326d63a4bd521897e08c013d7c40b58186 /llvm/lib/IR/Instructions.cpp | |
parent | 1978f7fe2999171a43a2a577bc3e771f29abd9ea (diff) | |
download | llvm-af83e40dee4270cf5a3b34229b981e6d7a5d07da.zip llvm-af83e40dee4270cf5a3b34229b981e6d7a5d07da.tar.gz llvm-af83e40dee4270cf5a3b34229b981e6d7a5d07da.tar.bz2 |
Refactor implied condition logic from ValueTracking directly into CmpInst. NFC.
Differential Revision: http://reviews.llvm.org/D19330
llvm-svn: 266987
Diffstat (limited to 'llvm/lib/IR/Instructions.cpp')
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index ac43eef..02005cf 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -3597,6 +3597,58 @@ bool CmpInst::isFalseWhenEqual(Predicate predicate) { } } +bool CmpInst::isTrueWhenOperandsMatch(Predicate Pred1, Predicate Pred2) { + // If the predicates match, then we know the first condition implies the + // second is true. + if (Pred1 == Pred2) + return true; + + switch (Pred1) { + default: + break; + case ICMP_UGT: // A >u B implies A != B is true. + case ICMP_ULT: // A <u B implies A != B is true. + case ICMP_SGT: // A >s B implies A != B is true. + case ICMP_SLT: // A <s B implies A != B is true. + return Pred2 == ICMP_NE; + } + return false; +} + +bool CmpInst::isFalseWhenOperandsMatch(Predicate Pred1, Predicate Pred2) { + // If an inverted Pred1 matches Pred2, we can infer the second condition is + // false. + if (getInversePredicate(Pred1) == Pred2) + return true; + + // If a swapped Pred1 matches Pred2, we can infer the second condition is + // false in many cases. + if (getSwappedPredicate(Pred1) == Pred2) { + switch (Pred1) { + default: + break; + case ICMP_UGT: // A >u B implies A <u B is false. + case ICMP_ULT: // A <u B implies A >u B is false. + case ICMP_SGT: // A >s B implies A <s B is false. + case ICMP_SLT: // A <s B implies A >s B is false. + return true; + } + } + // A == B implies A > B and A < B are false. + if (Pred1 == ICMP_EQ && isFalseWhenEqual(Pred2)) + return true; + + switch (Pred1) { + default: + break; + case ICMP_UGT: // A >u B implies A == B is false. + case ICMP_ULT: // A <u B implies A == B is false. + case ICMP_SGT: // A >s B implies A == B is false. + case ICMP_SLT: // A <s B implies A == B is false. + return Pred2 == ICMP_EQ; + } + return false; +} //===----------------------------------------------------------------------===// // SwitchInst Implementation |