[llvm] [LV] Create in-loop sub reductions (PR #147026)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 30 06:16:08 PDT 2025
================
@@ -810,10 +810,15 @@ Value *VPInstruction::generate(VPTransformState &State) {
Value *RdxPart = RdxParts[Part];
if (RecurrenceDescriptor::isMinMaxRecurrenceKind(RK))
ReducedPartRdx = createMinMaxOp(Builder, RK, ReducedPartRdx, RdxPart);
- else
- ReducedPartRdx = Builder.CreateBinOp(
- (Instruction::BinaryOps)RecurrenceDescriptor::getOpcode(RK),
- RdxPart, ReducedPartRdx, "bin.rdx");
+ else {
+ // Interleaved/unrolled sub reductions should still be added together
----------------
sdesmalen-arm wrote:
nit: I think this requires some rationale to explain why `RecurKind::Sub` uses `add`, since the comment above on line 814 doesn't describe that.
Perhaps something like this is clearer:
```
Instruction::BinaryOps Opcode;
// For sub-recurrences, each UF's reduction variable is already
// negative, we need to do: reduce.add(-acc_uf0 + -acc_uf1)
if (RK == RecurKind::Sub)
Opcode = Instruction::Add;
else
Opcode = RecurrenceDescriptor::getOpcode(RK);
```
https://github.com/llvm/llvm-project/pull/147026
More information about the llvm-commits
mailing list