[llvm] [SLP][X86]Vectorize alternate fadd/fsub fused with fmul (fmaddsub/fmsubadd) (PR #229268)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 7 05:25:03 PDT 2026
================
@@ -13523,6 +13523,32 @@ uint64_t BoUpSLP::getNumScalarInsts(bool HasTreeLoop) {
uint64_t BoUpSLP::getNumVectorInsts(bool HasTreeLoop, bool CountExtracts) {
uint64_t Total = 0;
+ // The alternate op, fused with the multiplication by the target, is counted
+ // with the multiplication node, the same way as the scalar fmas.
+ auto IsFusedAlt = [&](const TreeEntry &TE) {
+ if (!TE.hasState() || TE.State != TreeEntry::Vectorize ||
+ DeletedNodes.contains(&TE) || TransformedToGatherNodes.contains(&TE) ||
+ !TE.isAltShuffle() || TE.hasReassocScalars() ||
+ !TE.getMainOp()->getType()->isFloatingPointTy() ||
+ !TE.getOperations().isAddSubLikeOp())
+ return false;
+ Type *ScalarTy = TE.getMainOp()->getType();
+ auto *VecTy =
+ cast<VectorType>(getWidenedType(ScalarTy, TE.getVectorFactor()));
+ SmallBitVector OpcodeMask(getAltInstrMask(
+ TE.Scalars, ScalarTy, TE.getOpcode(), TE.getAltOpcode()));
+ return TTI->isLegalAltInstr(VecTy, TE.getOpcode(), TE.getAltOpcode(),
+ OpcodeMask, TE.Scalars) &&
+ canConvertToFMA(TE.Scalars, TE.getOperations(), *DT, *DL, *TTI, *TLI,
+ *this)
+ .isValid();
+ };
+ // The scalar count already credits the fused scalars as fmas, a tree with the
+ // fused alternate op is counted at the level of the machine instructions.
----------------
alexey-bataev wrote:
Applying adjustemnts needs separate per-target evaluation. Here the scalar side already counts the fused scalars as fmas, so only trees with the fused alternate op are counted at the machine-instruction level. I modified the comment. Unconditional counting can be a follow-up.
https://github.com/llvm/llvm-project/pull/229268
More information about the llvm-commits
mailing list