[llvm] [LV] Create in-loop sub reductions (PR #147026)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 8 00:53:31 PDT 2025


================
@@ -897,8 +899,21 @@ RecurrenceDescriptor::InstDesc RecurrenceDescriptor::isRecurrenceInstr(
   case Instruction::PHI:
     return InstDesc(I, Prev.getRecKind(), Prev.getExactFPMathInst());
   case Instruction::Sub:
+    if ((Kind == RecurKind::AddChainWithSubs || Kind == RecurKind::Add) &&
+        Kind == Prev.getRecKind())
----------------
sdesmalen-arm wrote:

This logic is a bit confusing now. What about making this simpler and instead always first trying to match a full add- or sub-reduction (chain) in `RecurrenceDescriptor::isReductionPHI`, and only then trying to match a mixed add/sub reduction?

That means this could be changed to:

```
case Instruction::Sub:
    return InstDesc(Kind == RecurKind::Sub || Kind == RecurKind::AddChainWithSubs, I);
```

and similar below for the `Instruction::Add`.

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


More information about the llvm-commits mailing list