[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 04:59:19 PDT 2025
================
@@ -2719,6 +2719,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))) &&
+ match(Op1, m_c_SMin(m_Value(X), m_Value(Y))) &&
----------------
dtcxzyw wrote:
> Is it possible that I misunderstood, and you meant a test to swap the min arguments?
No. Just a negative test for `min(X+1, Y) - min(X, Z)`.
https://github.com/llvm/llvm-project/pull/157782
More information about the llvm-commits
mailing list