[llvm] [InstCombine] Fold (add (add A, 1), (sext (icmp ne A, 0))) to call umax(A, 1) (PR #122491)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 12 06:29:18 PST 2025


================
@@ -1775,6 +1775,15 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
     }
   }
 
+  // (add (add A, 1), (sext (icmp ne A, 0))) => call umax(A, 1)
+  if (match(LHS, m_OneUse(m_Add(m_Value(A), m_One()))) &&
----------------
nikic wrote:

I think we should drop the one-use check on the add at least: https://llvm.godbolt.org/z/YGq6osY3z

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


More information about the llvm-commits mailing list