[llvm] [LoopUnroll] Introduce parallel accumulators when unrolling FP reductions. (PR #166630)
Julian Nagele via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 7 08:35:06 PST 2025
================
@@ -1256,14 +1257,19 @@ llvm::canParallelizeReductionWhenUnrolling(PHINode &Phi, Loop *L,
return std::nullopt;
RecurKind RK = RdxDesc.getRecurrenceKind();
// Skip unsupported reductions.
- // TODO: Handle additional reductions, including FP and min-max
- // reductions.
- if (!RecurrenceDescriptor::isIntegerRecurrenceKind(RK) ||
+ // TODO: Handle additional reductions, including min-max reductions.
+ if (!(RecurrenceDescriptor::isIntegerRecurrenceKind(RK) ||
+ RecurrenceDescriptor::isFloatingPointRecurrenceKind(RK)) ||
RecurrenceDescriptor::isAnyOfRecurrenceKind(RK) ||
RecurrenceDescriptor::isFindIVRecurrenceKind(RK) ||
RecurrenceDescriptor::isMinMaxRecurrenceKind(RK))
return std::nullopt;
+ if (RecurrenceDescriptor::isFloatingPointRecurrenceKind(RK)) {
+ if (!RdxDesc.getFastMathFlags().allowReassoc())
+ return std::nullopt;
+ }
----------------
juliannagele wrote:
Hm, afaict `isRecurrenceInstr` doesn't return `None` but remembers the instruction that doesn't have reassoc
```
InstDesc(Kind == RecurKind::FAdd, I,
I->hasAllowReassoc() ? nullptr : I);
```
So I think we do need a check but we could simplify it to
```
if (RdxDesc.hasExactFPMath())
return std::nullopt;
```
where
```
/// Returns true if the recurrence has floating-point math that requires
/// precise (ordered) operations.
bool hasExactFPMath() const { return ExactFPMathInst != nullptr; }
```
https://github.com/llvm/llvm-project/pull/166630
More information about the llvm-commits
mailing list