diff options
author | Nikita Popov <npopov@redhat.com> | 2022-05-13 16:35:43 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2022-05-16 16:30:26 +0200 |
commit | 356d47ccb9b5f69b8b984d37a8b3c8813a84413b (patch) | |
tree | b50553ad0af0c4fbf4f3f732a1191e14276ea4c6 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | b7315ffc3c92d2408780b5748cbac1c651128079 (diff) | |
download | llvm-356d47ccb9b5f69b8b984d37a8b3c8813a84413b.zip llvm-356d47ccb9b5f69b8b984d37a8b3c8813a84413b.tar.gz llvm-356d47ccb9b5f69b8b984d37a8b3c8813a84413b.tar.bz2 |
[ValueTracking] Handle and/or on RHS of isImpliedCondition()
isImpliedCondition() currently handles and/or on the LHS, but not
on the RHS, resulting in asymmetric behavior. This patch adds two
new implication rules:
* LHS ==> (RHS1 || RHS2) if LHS ==> RHS1 or LHS ==> RHS2
* LHS ==> !(RHS1 && RHS2) if LHS ==> !RHS1 or LHS ==> !RHS2
Differential Revision: https://reviews.llvm.org/D125551
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index ed196b1..a326335 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -6653,11 +6653,38 @@ Optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS, if (LHS == RHS) return LHSIsTrue; - const ICmpInst *RHSCmp = dyn_cast<ICmpInst>(RHS); - if (RHSCmp) + if (const ICmpInst *RHSCmp = dyn_cast<ICmpInst>(RHS)) return isImpliedCondition(LHS, RHSCmp->getPredicate(), RHSCmp->getOperand(0), RHSCmp->getOperand(1), DL, LHSIsTrue, Depth); + + if (Depth == MaxAnalysisRecursionDepth) + return None; + + // LHS ==> (RHS1 || RHS2) if LHS ==> RHS1 or LHS ==> RHS2 + // LHS ==> !(RHS1 && RHS2) if LHS ==> !RHS1 or LHS ==> !RHS2 + const Value *RHS1, *RHS2; + if (match(RHS, m_LogicalOr(m_Value(RHS1), m_Value(RHS2)))) { + if (Optional<bool> Imp = + isImpliedCondition(LHS, RHS1, DL, LHSIsTrue, Depth + 1)) + if (*Imp == true) + return true; + if (Optional<bool> Imp = + isImpliedCondition(LHS, RHS2, DL, LHSIsTrue, Depth + 1)) + if (*Imp == true) + return true; + } + if (match(RHS, m_LogicalAnd(m_Value(RHS1), m_Value(RHS2)))) { + if (Optional<bool> Imp = + isImpliedCondition(LHS, RHS1, DL, LHSIsTrue, Depth + 1)) + if (*Imp == false) + return false; + if (Optional<bool> Imp = + isImpliedCondition(LHS, RHS2, DL, LHSIsTrue, Depth + 1)) + if (*Imp == false) + return false; + } + return None; } |