[llvm] [SLP] De-duplicate costing of perfect-diamond gather spills (PR #220569)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 7 06:56:56 PDT 2026
================
@@ -19040,6 +19045,78 @@ InstructionCost BoUpSLP::getSpillCost() {
}
return nullptr;
};
+ auto IsCoveredByMatchingVectorEntry = [&](const TreeEntry *Gather,
+ const Loop *SpillLoop) -> bool {
+ assert(Gather->isGather());
+
+ Value *LookupValue = nullptr;
+ if (Gather->hasState()) {
+ LookupValue = Gather->getMainOp();
+ } else {
+ auto *It = find_if(Gather->Scalars, [](Value *V) {
+ return !isa<PoisonValue, UndefValue>(V);
+ });
+ if (It == Gather->Scalars.end())
+ return false;
+ LookupValue = *It;
+ }
+
+ // Find the real vector entry reused by this perfect-diamond gather.
+ const TreeEntry *SameTE =
+ getSameValuesTreeEntry(LookupValue, Gather->Scalars, /*SameVF=*/true);
+ if (!SameTE || SameTE == Gather || SameTE->State != TreeEntry::Vectorize ||
+ ScalarOrPseudoEntries.contains(SameTE) || !SameTE->UserTreeIndex)
+ return false;
+
+ // Only permit an ordinary vectorized user.
+ const TreeEntry *UserTE = SameTE->UserTreeIndex.UserTE;
+ assert(UserTE && "Expected a user tree entry.");
+ if (UserTE->State != TreeEntry::Vectorize ||
+ ScalarOrPseudoEntries.contains(UserTE) ||
+ UserTE->getOpcode() == Instruction::PHI)
+ return false;
+
+ // Different demotion state would make the two edge costs unequal.
+ if (MinBWs.contains(SameTE) != MinBWs.contains(Gather))
+ return false;
+
+ // The spill walk does not descend through gather entries; if any ancestor
+ // of the matching entry's user is a gather, the matching edge is never
----------------
alexey-bataev wrote:
```suggestion
// of the matching entry's user is a gather or a combined scalar/pseudo entry, the matching edge is never
```
https://github.com/llvm/llvm-project/pull/220569
More information about the llvm-commits
mailing list