[llvm] [SLP] Check for extracts, being replaced by original scalars, for user nodes (PR #149572)
Gaƫtan Bossu via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 5 09:38:40 PDT 2025
================
@@ -9151,6 +9165,93 @@ getVectorCallCosts(CallInst *CI, FixedVectorType *VecTy,
return {IntrinsicCost, LibCost};
}
+/// Check if extracts are cheaper than the original scalars.
+static bool
+areExtractsCheaperThanScalars(TargetTransformInfo &TTI, Type *UserScalarTy,
+ VectorType *UserVecTy, const APInt &DemandedElts,
+ const InstructionCost UserScalarsCost,
+ Type *ScalarTy, unsigned VF, ArrayRef<int> Mask,
+ InstructionCost UserEntryCost) {
+ constexpr TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
+ // If extracts are cheaper than the original scalars - success.
+ InstructionCost ExtractCost =
+ ::getScalarizationOverhead(TTI, UserScalarTy, UserVecTy, DemandedElts,
+ /*Insert=*/false, /*Extract=*/true, CostKind);
+ if (ExtractCost <= UserScalarsCost)
+ return true;
+ // The node is profitable for vectorization - success.
+ if (ExtractCost <= UserEntryCost)
+ return true;
----------------
gbossu wrote:
I understand the first `ExtractCost <= UserScalarsCost` check, because if the lanes are already extracted from the user `TreeEntry`, then there's no need to extract or scalarize operands.
But the check below is still a bit of a mystery to me:
```
// The node is profitable for vectorization - success.
if (ExtractCost <= UserEntryCost)
return true;
```
Which node are we talking about? The user node has already been vectorized, and this is checking nothing about the to-be-created node, so I feel this check should be removed.
https://github.com/llvm/llvm-project/pull/149572
More information about the llvm-commits
mailing list