[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 10:52:27 PDT 2026
================
@@ -19404,6 +19420,29 @@ BoUpSLP::calculateTreeCostAndTrimNonProfitable(ArrayRef<Value *> VectorizedVals,
return false;
return IsExternallyUsedV(V);
};
+ // 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.
+ bool LosesFMAs = reductionLosesFMAs(RdxKind, RdxFMF, VectorizedVals);
+ auto GetCoalescedLoadSaving = [&](const TreeEntry &TE) -> InstructionCost {
+ if (!LosesFMAs || !TE.hasState() || TE.isGather() ||
+ TE.getOpcode() != Instruction::Load ||
+ TE.State != TreeEntry::Vectorize || TE.getInterleaveFactor())
+ return 0;
+ if (DeletedNodes.contains(&TE) || TransformedToGatherNodes.contains(&TE))
+ return 0;
+ if (!TE.ReuseShuffleIndices.empty() || !TE.ReorderIndices.empty() ||
+ MinBWs.contains(&TE))
+ return 0;
+ if (!all_of(TE.Scalars, IsaPred<LoadInst>))
+ return 0;
+ auto *LI0 = cast<LoadInst>(TE.getMainOp());
+ Align BestAlign = LI0->getAlign();
+ for (Value *V : TE.Scalars)
+ BestAlign = std::max(BestAlign, cast<LoadInst>(V)->getAlign());
+ return TTI->getLoadCoalescingSaving(
+ LI0->getType(), TE.Scalars.size(), BestAlign,
+ LI0->getPointerAddressSpace(), CostKind);
----------------
MrSidims wrote:
Moved to getEntryCost
https://github.com/llvm/llvm-project/pull/228903
More information about the llvm-branch-commits
mailing list