[llvm] [InstSimplify] Simplify the select with integer comparison relationship (PR #66668)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 00:50:46 PDT 2023


================
@@ -8285,6 +8285,15 @@ static std::optional<bool> isImpliedCondICmps(const ICmpInst *LHS,
   if (areMatchingOperands(L0, L1, R0, R1, AreSwappedOps))
     return isImpliedCondMatchingOperands(LPred, RPred, AreSwappedOps);
 
+  if (RPred == ICmpInst::ICMP_SLT) {
+    Value *X;
+    Value *Y;
+    // x -nsw y is non-negative when x >= y or negative when x < y
+    if (match(R0, m_NSWSub(m_Value(X), m_Value(Y))) && match(R1, m_AllOnes()) &&
+        areMatchingOperands(L0, L1, X, Y, AreSwappedOps))
+      return isImpliedCondMatchingOperands(LPred, RPred, AreSwappedOps);
----------------
vfdff wrote:

Oh, you are right. 
I missed the big premise, and valuetracking can be used except `abs`, so `X -nsw Y <s -1` and `X -nsw Y <=s -1` is unequivalent.

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


More information about the llvm-commits mailing list