[llvm] [CostModel] getInstructionCost - improve estimation of costs for length changing shuffles (PR #84156)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 6 05:57:45 PST 2024
================
@@ -1356,7 +1357,35 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
DemandedDstElts, CostKind);
}
- return CostKind == TTI::TCK_RecipThroughput ? -1 : 1;
+ bool IsUnary = isa<UndefValue>(Operands[1]);
+ NumSubElts = VecSrcTy->getElementCount().getKnownMinValue();
+ SmallVector<int, 16> AdjustMask(Mask.begin(), Mask.end());
+
+ // Widening shuffle - widening the source(s) to the new length
+ // (treated as free - see above), and then perform the adjusted
+ // shuffle at that width.
+ if (Shuffle->increasesLength()) {
+ for (int &M : AdjustMask)
+ M = M >= NumSubElts ? (M + (Mask.size() - NumSubElts)) : M;
+
+ return TargetTTI->getShuffleCost(
+ IsUnary ? TTI::SK_PermuteSingleSrc : TTI::SK_PermuteTwoSrc, VecTy,
+ AdjustMask, CostKind, 0, nullptr);
+ }
+
+ // Narrowing shuffle - perform shuffle at original wider width and
+ // then extract the lower elements.
+ AdjustMask.append(NumSubElts - Mask.size(), -1);
----------------
alexey-bataev wrote:
```suggestion
AdjustMask.append(NumSubElts - Mask.size(), PoisonMaskElem);
```
https://github.com/llvm/llvm-project/pull/84156
More information about the llvm-commits
mailing list