@@ -4854,24 +4854,27 @@ static bool clusterSortPtrAccesses(ArrayRef<Value *> VL, Type *ElemTy,
4854
4854
Root = Gep->getOperand(0);
4855
4855
SortedBases.emplace_back(Base.first, Strip, Root);
4856
4856
}
4857
- if (SortedBases.size() <= 16) {
4858
- auto Begin = SortedBases.begin();
4859
- auto End = SortedBases.end();
4860
- while (Begin != End) {
4861
- Value *Root = std::get<2>(*Begin);
4862
- auto Mid = std::stable_partition(
4863
- Begin, End, [&Root](auto V) { return std::get<2>(V) == Root; });
4864
- std::stable_sort(Begin, Mid, [](auto V1, auto V2) {
4865
- const Value *V = std::get<1>(V2);
4866
- while (auto *Gep = dyn_cast<GetElementPtrInst>(V)) {
4867
- if (Gep->getOperand(0) == std::get<1>(V1))
4868
- return true;
4869
- V = Gep->getOperand(0);
4870
- }
4871
- return false;
4872
- });
4873
- Begin = Mid;
4874
- }
4857
+ auto *Begin = SortedBases.begin();
4858
+ auto *End = SortedBases.end();
4859
+ while (Begin != End) {
4860
+ Value *Root = std::get<2>(*Begin);
4861
+ auto *Mid = std::stable_partition(
4862
+ Begin, End, [&Root](auto V) { return std::get<2>(V) == Root; });
4863
+ DenseMap<Value *, DenseMap<Value *, bool>> LessThan;
4864
+ for (auto I = Begin; I < Mid; ++I)
4865
+ LessThan.try_emplace(std::get<1>(*I));
4866
+ for (auto I = Begin; I < Mid; ++I) {
4867
+ Value *V = std::get<1>(*I);
4868
+ while (auto *Gep = dyn_cast<GetElementPtrInst>(V)) {
4869
+ V = Gep->getOperand(0);
4870
+ if (LessThan.contains(V))
4871
+ LessThan[V][std::get<1>(*I)] = true;
4872
+ }
4873
+ }
4874
+ std::stable_sort(Begin, Mid, [&LessThan](auto &V1, auto &V2) {
4875
+ return LessThan[std::get<1>(V1)][std::get<1>(V2)];
4876
+ });
4877
+ Begin = Mid;
4875
4878
}
4876
4879
4877
4880
// Collect the final order of sorted indices
0 commit comments