[llvm] [InstCombine] Fold smin(-a, x - a) + a to smin(x, 0) (PR #167109)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 8 01:45:50 PST 2025


================
@@ -2037,6 +2037,20 @@ Instruction *InstCombinerImpl::visitFAdd(BinaryOperator &I) {
     return BinaryOperator::CreateFSubFMF(Z, XY, &I);
   }
 
+  // smin(-a, x - a) + a --> smin(x, 0) [2 commuted variants]
+  // smin(x - a, -a) + a --> smin(x, 0) [2 commuted variants]
+  if (match(&I,
+            m_c_FAdd(m_SMin(m_FNeg(m_Value(A)), m_FSub(m_Value(X), m_Value(A))),
----------------
dtcxzyw wrote:

I don't know why it works... You are matching an fadd instead of an add.

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


More information about the llvm-commits mailing list