[llvm] [SLP] Account for GEP pointer-chain cost when root scalars feed load/store indices (PR #192726)
Ryan Buchner via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 30 16:55:47 PDT 2026
================
@@ -19073,6 +19093,41 @@ InstructionCost BoUpSLP::getTreeCost(InstructionCost TreeCost,
ExtractCost += ExtraCost;
}
+ // Charge the pointer-chain cost difference once for the root entry when
+ // every external use of its scalars is a GEP feeding a single load/store
+ // (see the detection loop above). Vectorizing the root in this pattern
+ // forces lane extracts (or a vector GEP with unknown stride) to drive the
+ // address computation, which is typically more expensive than keeping the
+ // indices scalar in a unit-stride address chain. Add the delta once rather
+ // than per external use.
+ if (AllUsersGEPSWithStoresLoads && !Pointers.empty()) {
+ const TreeEntry &RootEntry = *VectorizableTree.front();
+ const bool AnyRootKeptAsScalar = any_of(RootEntry.Scalars, [&](Value *V) {
+ return ExternalUsesAsOriginalScalar.contains(V);
+ });
+ const Value *CommonBase = nullptr;
+ bool HaveCommonBase = true;
+ for (const Value *P : Pointers) {
+ const Value *Op = cast<GetElementPtrInst>(P)->getPointerOperand();
----------------
bababuck wrote:
Could we use `getUnderlyingObject` instead?
https://github.com/llvm/llvm-project/pull/192726
More information about the llvm-commits
mailing list