[llvm] [LAA] refactor sortPtrAccesses (NFC) (PR #92256)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu May 16 08:12:45 PDT 2024
================
@@ -1636,32 +1636,27 @@ bool llvm::sortPtrAccesses(ArrayRef<Value *> VL, Type *ElemTy,
auto Compare = llvm::less_first();
std::set<DistOrdPair, decltype(Compare)> Offsets(Compare);
Offsets.emplace(0, 0);
- int Cnt = 1;
bool IsConsecutive = true;
- for (auto *Ptr : VL.drop_front()) {
+ for (auto [Idx, Ptr] : drop_begin(enumerate(VL))) {
std::optional<int> Diff = getPointersDiff(ElemTy, Ptr0, ElemTy, Ptr, DL, SE,
/*StrictCheck=*/true);
if (!Diff)
return false;
// Check if the pointer with the same offset is found.
int64_t Offset = *Diff;
- auto Res = Offsets.emplace(Offset, Cnt);
- if (!Res.second)
+ auto [It, IsInserted] = Offsets.emplace(Offset, Idx);
+ if (!IsInserted)
return false;
// Consecutive order if the inserted element is the last one.
- IsConsecutive = IsConsecutive && std::next(Res.first) == Offsets.end();
- ++Cnt;
+ IsConsecutive = IsConsecutive && std::next(It) == Offsets.end();
----------------
fhahn wrote:
nit: `IsConsecutive &= std::next(It) == Offsets.end();`?
https://github.com/llvm/llvm-project/pull/92256
More information about the llvm-commits
mailing list