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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 27 03:49:46 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;
+             }) &&
----------------
nikic wrote:

I don't understand why this function needs to check the intrinsic ID at all. We recently removed the check for opcodes form the BinaryOperator variant, leaving the choice of which intrinsics to support to the caller.

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


More information about the llvm-commits mailing list