Skip to content

Commit b6fa78d

Browse files
authored
[LAA] refactor sortPtrAccesses (NFC) (#92256)
Use the destructuring syntax in C++ and llvm::enumerate to make sortPtrAccesses a little more readable.
1 parent 7a67479 commit b6fa78d

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,32 +1621,27 @@ bool llvm::sortPtrAccesses(ArrayRef<Value *> VL, Type *ElemTy,
16211621
auto Compare = llvm::less_first();
16221622
std::set<DistOrdPair, decltype(Compare)> Offsets(Compare);
16231623
Offsets.emplace(0, 0);
1624-
int Cnt = 1;
16251624
bool IsConsecutive = true;
1626-
for (auto *Ptr : VL.drop_front()) {
1625+
for (auto [Idx, Ptr] : drop_begin(enumerate(VL))) {
16271626
std::optional<int> Diff = getPointersDiff(ElemTy, Ptr0, ElemTy, Ptr, DL, SE,
16281627
/*StrictCheck=*/true);
16291628
if (!Diff)
16301629
return false;
16311630

16321631
// Check if the pointer with the same offset is found.
16331632
int64_t Offset = *Diff;
1634-
auto Res = Offsets.emplace(Offset, Cnt);
1635-
if (!Res.second)
1633+
auto [It, IsInserted] = Offsets.emplace(Offset, Idx);
1634+
if (!IsInserted)
16361635
return false;
16371636
// Consecutive order if the inserted element is the last one.
1638-
IsConsecutive = IsConsecutive && std::next(Res.first) == Offsets.end();
1639-
++Cnt;
1637+
IsConsecutive &= std::next(It) == Offsets.end();
16401638
}
16411639
SortedIndices.clear();
16421640
if (!IsConsecutive) {
16431641
// Fill SortedIndices array only if it is non-consecutive.
16441642
SortedIndices.resize(VL.size());
1645-
Cnt = 0;
1646-
for (const std::pair<int64_t, int> &Pair : Offsets) {
1647-
SortedIndices[Cnt] = Pair.second;
1648-
++Cnt;
1649-
}
1643+
for (auto [Idx, Off] : enumerate(Offsets))
1644+
SortedIndices[Idx] = Off.second;
16501645
}
16511646
return true;
16521647
}
@@ -2639,7 +2634,7 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
26392634
SymbolicStrides, UncomputablePtr, false);
26402635
if (!CanDoRTIfNeeded) {
26412636
auto *I = dyn_cast_or_null<Instruction>(UncomputablePtr);
2642-
recordAnalysis("CantIdentifyArrayBounds", I)
2637+
recordAnalysis("CantIdentifyArrayBounds", I)
26432638
<< "cannot identify array bounds";
26442639
LLVM_DEBUG(dbgs() << "LAA: We can't vectorize because we can't find "
26452640
<< "the array bounds.\n");

0 commit comments

Comments
 (0)