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

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 26 23:04:55 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 =
+      [](const IntrinsicInst *I) {
+        return isa<BinaryOpIntrinsic, MinMaxIntrinsic>(I);
----------------
dtcxzyw wrote:

`xx.with.overflow` should not be accepted. BTW, I'd like to handle fmax/fmin as well.

```suggestion
        return isa<SaturatingInst, MinMaxIntrinsic>(I);
```

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


More information about the llvm-commits mailing list