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

Sam Tebbs via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 30 08:08:29 PDT 2025


================
@@ -2524,10 +2529,15 @@ void VPReductionRecipe::execute(VPTransformState &State) {
     NewRed = createSimpleReduction(State.Builder, NewVecOp, Kind);
     if (RecurrenceDescriptor::isMinMaxRecurrenceKind(Kind))
       NextInChain = createMinMaxOp(State.Builder, Kind, NewRed, PrevInChain);
-    else
+    else {
+      // Sub reductions aren't commutative so the operands need to be swapped.
+      bool IsSub = Kind == RecurKind::Sub;
+      Value *LHS = IsSub ? PrevInChain : NewRed;
----------------
SamTebbs33 wrote:

Agreed.

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


More information about the llvm-commits mailing list