[llvm] [SLP]Add cost estimation for gather node reshuffling (PR #115201)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 27 09:11:29 PST 2024
================
@@ -259,6 +259,33 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
return AddrExtractCost + MemoryOpCost + PackingCost + ConditionalCost;
}
+ /// Checks if the provided mask \p is a splat mask, i.e. it contains only -1
+ /// or same non -1 index value and this index value contained at least twice.
+ /// So, mask <0, -1,-1, -1> is not considered splat (it is just identity),
+ /// same for <-1, 0, -1, -1> (just a slide), while <2, -1, 2, -1> is a splat
+ /// with \p Index=2.
+ static bool isSplatMask(ArrayRef<int> Mask, unsigned NumSrcElts, int &Index) {
+ // Check that the broadcast index meets at least twice.
+ bool IsCompared = false;
+ if (int SplatIdx = PoisonMaskElem;
+ all_of(enumerate(Mask), [&](const auto &P) {
+ if (P.value() == PoisonMaskElem)
+ return P.index() != Mask.size() - 1 || IsCompared;
+ if (static_cast<unsigned>(P.value()) >= NumSrcElts * 2)
+ return false;
+ if (SplatIdx == PoisonMaskElem) {
+ SplatIdx = P.value();
+ return P.index() != Mask.size() - 1;
+ }
+ IsCompared = true;
+ return SplatIdx == P.value();
+ })) {
+ Index = SplatIdx;
+ return true;
----------------
RKSimon wrote:
This should only update Index and return true if SplatIdx != PoisonMaskElem
https://github.com/llvm/llvm-project/pull/115201
More information about the llvm-commits
mailing list