[llvm] [InstCombine] Missed fold: umax(x, C) > ~x -> x < 0 (PR #189396)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 12 06:27:29 PDT 2026
================
@@ -7785,13 +7785,35 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
if (Instruction *Res = foldICmpWithZero(I))
return Res;
+ Value *X;
+ const APInt *C;
+ if (I.getPredicate() == ICmpInst::ICMP_UGT &&
+ match(Op0, m_UMax(m_Value(X), m_APInt(C))) &&
+ match(Op1, m_Not(m_Specific(X)))) {
+ if (C->isNonNegative())
+ return new ICmpInst(ICmpInst::ICMP_SLT, X,
+ Constant::getNullValue(X->getType()));
+ return new ICmpInst(ICmpInst::ICMP_UGT, X,
+ ConstantInt::get(X->getType(), ~*C));
+ }
+
+ if (I.getPredicate() == ICmpInst::ICMP_ULT &&
+ match(Op0, m_UMax(m_Value(X), m_APInt(C))) &&
+ match(Op1, m_Not(m_Specific(X)))) {
+ if (C->isNonNegative()) {
----------------
dtcxzyw wrote:
Drop braces.
https://github.com/llvm/llvm-project/pull/189396
More information about the llvm-commits
mailing list