[llvm] [SLP] De-duplicate costing of perfect-diamond gather spills (PR #220569)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 06:25:09 PDT 2026
================
@@ -19040,6 +19045,77 @@ InstructionCost BoUpSLP::getSpillCost() {
}
return nullptr;
};
+ auto IsCoveredByMatchingVectorEntry = [&](const TreeEntry *Gather,
+ const Loop *SpillLoop) -> bool {
+ assert(Gather->isGather() && "Expected a Gather Entry!");
+
+ Value *LookupValue = nullptr;
+ if (Gather->hasState()) {
+ LookupValue = Gather->getMainOp();
+ } else {
+ auto *It = find_if_not(Gather->Scalars, IsaPred<UndefValue>);
+ 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))
----------------
alexey-bataev wrote:
```suggestion
if (MinBWs.lookup(SameTE) != MinBWs.lookup(Gather))
```
https://github.com/llvm/llvm-project/pull/220569
More information about the llvm-commits
mailing list