[llvm-branch-commits] [llvm] [SLP] Cancel the phantom load saving on fadd reductions that lose an fma (PR #228903)

Dmitry Sidorov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Oct 7 12:48:20 PDT 2026


================
@@ -17591,6 +17610,19 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
               Instruction::Load, VecTy, LI0->getAlign(),
               LI0->getPointerAddressSpace(), CostKind,
               TTI::getOperandInfo(LI0->getPointerOperand()));
+          // The vector load of a bundle saves nothing over scalar loads the
+          // target coalesces as well. A reduction that loses its fmas pays
+          // that saving back.
+          if (E->ReuseShuffleIndices.empty() && E->ReorderIndices.empty() &&
+              It == MinBWs.end() &&
+              reductionLosesFMAs(RdxKind, RdxFMF, VectorizedVals)) {
+            Align BestAlign = LI0->getAlign();
+            for (Value *V : VL)
+              BestAlign = std::max(BestAlign, cast<LoadInst>(V)->getAlign());
+            VecLdCost += TTI->getLoadCoalescingSaving(
+                LI0->getType(), VL.size(), BestAlign,
+                LI0->getPointerAddressSpace(), CostKind);
+          }
----------------
MrSidims wrote:

Frankly, because it would require to add yet another hook in TTI to account the cost properly aka it's another situation, where SLP knows the context better (N consecutive loads covering all lanes, with the best alignment among them, which only SLP knows).

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


More information about the llvm-branch-commits mailing list