Skip to content

Commit 8b9906e

Browse files
committed
Compute LessThan by walking up gep chains
1 parent 62f69dc commit 8b9906e

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4854,24 +4854,27 @@ static bool clusterSortPtrAccesses(ArrayRef<Value *> VL, Type *ElemTy,
48544854
Root = Gep->getOperand(0);
48554855
SortedBases.emplace_back(Base.first, Strip, Root);
48564856
}
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[std::get<1>(*I)] = DenseMap<Value *, bool>();
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;
48754878
}
48764879

48774880
// Collect the final order of sorted indices

0 commit comments

Comments
 (0)