[llvm] [ValueTracking] Add `matchSimpleBinaryIntrinsicRecurrence` helper (PR #145964)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 27 03:50:34 PDT 2025


================
@@ -9119,6 +9120,28 @@ bool llvm::matchSimpleRecurrence(const BinaryOperator *I, PHINode *&P,
   return P && matchSimpleRecurrence(P, BO, Start, Step) && BO == I;
 }
 
+bool llvm::matchSimpleBinaryIntrinsicRecurrence(const IntrinsicInst *I,
+                                                PHINode *&P, Value *&Init,
+                                                Value *&Invariant) {
+  IntrinsicInst *II = nullptr;
+  P = dyn_cast<PHINode>(I->getArgOperand(0));
+  if (!P)
+    P = dyn_cast<PHINode>(I->getArgOperand(1));
+
+  return P &&
+         matchTwoInputRecurrence<IntrinsicInst>(
+             P, II, Init, Invariant,
+             [](const IntrinsicInst *I) {
+               Intrinsic::ID IID = I->getIntrinsicID();
+               return isa<SaturatingInst, MinMaxIntrinsic>(I) ||
+                      IID == Intrinsic::minnum || IID == Intrinsic::maxnum ||
+                      IID == Intrinsic::minimum || IID == Intrinsic::maximum ||
+                      IID == Intrinsic::minimumnum ||
+                      IID == Intrinsic::maximumnum;
+             }) &&
----------------
antoniofrighetto wrote:

Oh, I stand corrected, it suffices to check `II == I` once matchTwoInputRecurrence returns.

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


More information about the llvm-commits mailing list