[llvm] [InstCombine] smin(smax(X, -1), 1) -> scmp(X, 0) and smax(smin(X, 1), -1) -> scmp(X, 0) (PR #145736)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 27 05:17:36 PDT 2025


================
@@ -1972,6 +1972,22 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
       return BinaryOperator::CreateOr(I0, I1);
     }
 
+    // smin(smax(X, -1), 1) -> scmp(X, 0)
+    // smax(smin(X, 1), -1) -> scmp(X, 0)
+    // At this point, smax(smin(X, 1), -1) is changed to smin(smax(X, -1)
+    // And i1's have been changed to and/ors
+    // So we only need to check for smin
+    if (IID == Intrinsic::smin) {
+      if (match(I0, m_OneUse(m_Intrinsic<Intrinsic::smax>(m_Value(X),
----------------
AZero13 wrote:

Thank you!

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


More information about the llvm-commits mailing list