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

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 15 03:13:38 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);
----------------
dtcxzyw wrote:

It is incorrect that `X <s Y` implies `X -nsw Y <s -1`.


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


More information about the llvm-commits mailing list