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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 27 08:11:45 PDT 2025


================
@@ -965,6 +966,21 @@ LLVM_ABI bool matchSimpleRecurrence(const PHINode *P, BinaryOperator *&BO,
 LLVM_ABI bool matchSimpleRecurrence(const BinaryOperator *I, PHINode *&P,
                                     Value *&Start, Value *&Step);
 
+/// Attempt to match a simple value-accumulating recurrence of the form:
+///   %llvm.intrinsic.acc = phi Ty [%Init, %Entry], [%llvm.intrinsic, %backedge]
+///   %llvm.intrinsic = call Ty @llvm.intrinsic(%Invariant, %llvm.intrinsic.acc)
----------------
nikic wrote:

Don't call this Invariant, here and elsewhere. This matcher does not actually guarantee it's invariant (just like the one above doesn't guarantee Step is invariant).

The pattern you want to match has an invariant there, but a typical reduction pattern wouldn#t.

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


More information about the llvm-commits mailing list