[llvm] [LoopUnroll] Combine partial sub/fsub reduction results with add/fadd (PR #201066)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 2 02:10:43 PDT 2026
================
@@ -1533,10 +1533,17 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
IRBuilder Builder(ExitBlock, ExitBlock->getFirstNonPHIIt());
Builder.setFastMathFlags(Reductions.begin()->second.getFastMathFlags());
RecurKind RK = Reductions.begin()->second.getRecurrenceKind();
+ // Partial results of sub/fsub reductions already carry the correct
+ // sign and must be summed; chaining them with sub/fsub would flip
+ // the sign of every other partial result.
+ unsigned RdxOpcode = RecurrenceDescriptor::getOpcode(RK);
+ if (RdxOpcode == Instruction::Sub)
+ RdxOpcode = Instruction::Add;
+ else if (RdxOpcode == Instruction::FSub)
+ RdxOpcode = Instruction::FAdd;
----------------
fhahn wrote:
Better use something like
```
Instruction::BinaryOps Opcode =
RecurrenceDescriptor::isSubRecurrenceKind(RK)
? getSubRecurOpcode(RK)
: (Instruction::BinaryOps)RecurrenceDescriptor::getOpcode(RK);
```
https://github.com/llvm/llvm-project/pull/201066
More information about the llvm-commits
mailing list