aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorRamkumar Ramachandra <ramkumar.ramachandra@codasip.com>2025-01-13 16:20:00 +0000
committerGitHub <noreply@github.com>2025-01-13 16:20:00 +0000
commitf1632d25db47629221b8a25d79b7993b397f6886 (patch)
tree7e80004a453ac24e08199af7cae3a77f1e9de42b /llvm/lib/Analysis/ValueTracking.cpp
parent658ec8593b25f2bd05874deab4582b6759e92e40 (diff)
downloadllvm-f1632d25db47629221b8a25d79b7993b397f6886.zip
llvm-f1632d25db47629221b8a25d79b7993b397f6886.tar.gz
llvm-f1632d25db47629221b8a25d79b7993b397f6886.tar.bz2
IR: introduce ICmpInst::isImpliedByMatchingCmp (#122597)
Create an abstraction over isImplied{True,False}ByMatchingCmp to faithfully communicate the result of both functions, cleaning up code in callsites. While at it, fix a bug in the implied-false version of the function, which was inadvertedenly dropping samesign information.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp19
1 files changed, 3 insertions, 16 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 0e50fc6..d03e6f5 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -9384,19 +9384,6 @@ isImpliedCondOperands(CmpInst::Predicate Pred, const Value *ALHS,
}
}
-/// Return true if "icmp1 LPred X, Y" implies "icmp2 RPred X, Y" is true.
-/// Return false if "icmp1 LPred X, Y" implies "icmp2 RPred X, Y" is false.
-/// Otherwise, return std::nullopt if we can't infer anything.
-static std::optional<bool> isImpliedCondMatchingOperands(CmpPredicate LPred,
- CmpPredicate RPred) {
- if (ICmpInst::isImpliedTrueByMatchingCmp(LPred, RPred))
- return true;
- if (ICmpInst::isImpliedFalseByMatchingCmp(LPred, RPred))
- return false;
-
- return std::nullopt;
-}
-
/// Return true if "icmp LPred X, LCR" implies "icmp RPred X, RCR" is true.
/// Return false if "icmp LPred X, LCR" implies "icmp RPred X, RCR" is false.
/// Otherwise, return std::nullopt if we can't infer anything.
@@ -9489,7 +9476,7 @@ isImpliedCondICmps(const ICmpInst *LHS, CmpPredicate RPred, const Value *R0,
// Can we infer anything when the two compares have matching operands?
if (L0 == R0 && L1 == R1)
- return isImpliedCondMatchingOperands(LPred, RPred);
+ return ICmpInst::isImpliedByMatchingCmp(LPred, RPred);
// It only really makes sense in the context of signed comparison for "X - Y
// must be positive if X >= Y and no overflow".
@@ -9499,7 +9486,7 @@ isImpliedCondICmps(const ICmpInst *LHS, CmpPredicate RPred, const Value *R0,
CmpPredicate::getMatching(LPred, ICmpInst::ICMP_SGE)) &&
match(R0, m_NSWSub(m_Specific(L0), m_Specific(L1)))) {
if (match(R1, m_NonPositive()) &&
- isImpliedCondMatchingOperands(LPred, RPred) == false)
+ ICmpInst::isImpliedByMatchingCmp(LPred, RPred) == false)
return false;
}
@@ -9509,7 +9496,7 @@ isImpliedCondICmps(const ICmpInst *LHS, CmpPredicate RPred, const Value *R0,
CmpPredicate::getMatching(LPred, ICmpInst::ICMP_SLE)) &&
match(R0, m_NSWSub(m_Specific(L0), m_Specific(L1)))) {
if (match(R1, m_NonNegative()) &&
- isImpliedCondMatchingOperands(LPred, RPred) == true)
+ ICmpInst::isImpliedByMatchingCmp(LPred, RPred) == true)
return true;
}