[llvm] [InstCombine] Fold `min(X+1, Y) - min(X, Y) --> zext X < Y` (PR #157782)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 11 11:48:04 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))) &&
----------------
benwu25 wrote:
Updated to use `m_NSWAddLike` and added a test.
https://github.com/llvm/llvm-project/pull/157782
More information about the llvm-commits
mailing list