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

via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 11 13:09:57 PST 2025


================
@@ -1775,6 +1775,16 @@ 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()))) &&
+      match(RHS, m_OneUse(m_SExt(m_OneUse(m_SpecificICmp(
+                     ICmpInst::ICMP_NE, m_Deferred(A), m_ZeroInt())))))) {
+    Value *OneConst = ConstantInt::get(A->getType(), 1);
+    Value *UMax =
+        Builder.CreateIntrinsic(Intrinsic::umax, A->getType(), {A, OneConst});
----------------
goldsteinn wrote:

`Builder.CreateBinaryIntrinsic(Intrinsic::umax, A, OneConst)`

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


More information about the llvm-commits mailing list