[llvm] [LoopUnroll] Combine partial sub/fsub reduction results with add/fadd (PR #201066)
Samuel Attard via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 2 02:22:38 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;
----------------
MarshallOfSound wrote:
done — matched the LV pattern and comment (adapted since the partials are scalars here)
https://github.com/llvm/llvm-project/pull/201066
More information about the llvm-commits
mailing list