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

via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 1 10:47:09 PDT 2024


================
@@ -8883,6 +8883,29 @@ static std::optional<bool> isImpliedCondICmps(const ICmpInst *LHS,
   if (L0 == R0 && L1 == R1)
     return isImpliedCondMatchingOperands(LPred, RPred);
 
+  // Take SGT as an example:  L0:x > L1:y and C >= 0
+  //                      ==> R0:(x -nsw y) < R1:(-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()) && (L0 == X && L1 == Y) &&
+        isImpliedCondMatchingOperands(LPred, RPred) == false)
+      return false;
+  }
+
+  // Take SLT as an example:  L0:x < L1:y and C <= 0
+  //                      ==> R0:(x -nsw y) < R1:(-C) is true
+  if (((LPred == ICmpInst::ICMP_SLT || LPred == ICmpInst::ICMP_SLE) &&
+       match(R0, m_NSWSub(m_Value(X), m_Value(Y)))) ||
+      ((LPred == ICmpInst::ICMP_ULT || LPred == ICmpInst::ICMP_ULE) &&
+       match(R0, m_NUWSub(m_Value(X), m_Value(Y))))) {
+    if (match(R1, m_NonNegative()) && (L0 == X && L1 == Y) &&
+        isImpliedCondMatchingOperands(LPred, RPred) == true)
+      return true;
+  }
----------------
goldsteinn wrote:

Both here and above, instead of m_Value(X)/m_Value(Y), how about m_Specific(L0)/m_Specific(L1)?

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


More information about the llvm-commits mailing list