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

via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 9 08:21:08 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()) &&
+        areMatchingOperands(L0, L1, X, Y, AreSwappedOps) &&
+        isImpliedCondMatchingOperands(LPred, RPred, AreSwappedOps) == false)
+      return false;
----------------
goldsteinn wrote:

you could handle `SLT`/`SLE`/`ULT`/`ULE` as `true` here no?

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


More information about the llvm-commits mailing list