[llvm] [ValueTracking] Infer relationship for the select with ICmp (PR #66668)

via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 9 08:18:22 PST 2024


================
@@ -8332,6 +8332,18 @@ static std::optional<bool> isImpliedCondICmps(const ICmpInst *LHS,
   if (areMatchingOperands(L0, L1, R0, R1, AreSwappedOps))
     return isImpliedCondMatchingOperands(LPred, RPred, AreSwappedOps);
 
+  // Take SGT as an example:  x > y and C <= 0 ==> x -nsw y < C is false
+  Value *X, *Y;
+  if (((LPred == ICmpInst::ICMP_SGT || LPred == ICmpInst::ICMP_SGE) &&
+       match(R0, m_NSWSub(m_Value(X), m_Value(Y)))) ||
+      ((LPred == ICmpInst::ICMP_UGT || LPred == ICmpInst::ICMP_UGE) &&
+       match(R0, m_NUWSub(m_Value(X), m_Value(Y))))) {
+    if (match(R1, m_NonPositive()) &&
----------------
goldsteinn wrote:

Just based on the comment, I would have expected `R1` to be non-negative?

https://github.com/llvm/llvm-project/pull/66668


More information about the llvm-commits mailing list