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

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


================
@@ -9119,6 +9121,23 @@ 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));
+
+  std::function<bool(const IntrinsicInst *)> IsBinaryOrMinMaxFn =
----------------
antoniofrighetto wrote:

We could run the predicate after matching the recurrence, but that would imply computing all the recurrence needlessly, if the intrinsic turned out not to be a candidate one (as we're passing a general IntrinsicInst), in addition to checking intrinsic operands size (as not to go out of bound when retrieving the Operation ops). Switched this to using a lightweight llvm::function_ref instead, I think it should be quite better.

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


More information about the llvm-commits mailing list