[llvm] [SLP] Order clustered load base pointers by ascending offsets (PR #100653)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 25 16:05:28 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;
----------------
alexey-bataev wrote:
Does it provide strict weak ordering?
https://github.com/llvm/llvm-project/pull/100653
More information about the llvm-commits
mailing list