[llvm] [SLP] Order clustered load base pointers by ascending offsets (PR #100653)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 26 02:06:26 PDT 2024
================
@@ -4842,10 +4842,27 @@ static bool clusterSortPtrAccesses(ArrayRef<Value *> VL, Type *ElemTy,
if (!AnyConsecutive)
return false;
- for (auto &Base : Bases) {
- for (auto &T : Base.second)
+ // If we have a better order, also sort the base pointers by increasing
+ // (variable) values if possible, to try and keep the order more regular.
+ SmallVector<std::pair<Value *, Value *>> SortedBases;
+ for (auto &Base : Bases)
+ SortedBases.emplace_back(Base.first,
+ Base.first->stripInBoundsConstantOffsets());
+ llvm::stable_sort(SortedBases, [](std::pair<Value *, Value *> V1,
+ std::pair<Value *, Value *> V2) {
+ const Value *V = V2.second;
+ while(auto *Gep = dyn_cast<GetElementPtrInst>(V)) {
+ if (Gep->getOperand(0) == V1.second)
+ return true;
+ V = Gep->getOperand(0);
+ }
+ return false;
----------------
davemgreen wrote:
I (unconfidently) believe so. I had a previous version where it would only look one step for adjacent nodes that was certainly not transitive, but this version doesn't have those issues.
https://github.com/llvm/llvm-project/pull/100653
More information about the llvm-commits
mailing list