[llvm] [InstCombine] Fold `min(X+1, Y) - min(X, Y) --> zext X < Y` (PR #157782)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 11 05:09:15 PDT 2025
================
@@ -2731,6 +2731,24 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
return BinaryOperator::CreateSub(X, Not);
}
+ // min(X+1, Y) - min(X, Y) --> zext X < Y
+ // Replacing a sub and at least one min with an icmp
+ // and a zext is a potential improvement.
+ if (match(Op0, m_c_SMin(m_c_NSWAdd(m_Value(X), m_One()), m_Value(Y))) &&
----------------
dtcxzyw wrote:
```suggestion
if (match(Op0, m_c_SMin(m_NSWAddLike(m_Value(X), m_One()), m_Value(Y))) &&
```
Please add a test with `min((or disjoint X, 1), Y)`.
https://github.com/llvm/llvm-project/pull/157782
More information about the llvm-commits
mailing list