diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp index d071e53324408f..00ab4f2da41a9b 100644 --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -1636,9 +1636,8 @@ bool llvm::sortPtrAccesses(ArrayRef VL, Type *ElemTy, auto Compare = llvm::less_first(); std::set 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 Diff = getPointersDiff(ElemTy, Ptr0, ElemTy, Ptr, DL, SE, /*StrictCheck=*/true); if (!Diff) @@ -1646,22 +1645,18 @@ bool llvm::sortPtrAccesses(ArrayRef VL, Type *ElemTy, // 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 &= std::next(It) == Offsets.end(); } SortedIndices.clear(); if (!IsConsecutive) { // Fill SortedIndices array only if it is non-consecutive. SortedIndices.resize(VL.size()); - Cnt = 0; - for (const std::pair &Pair : Offsets) { - SortedIndices[Cnt] = Pair.second; - ++Cnt; - } + for (auto [Idx, Off] : enumerate(Offsets)) + SortedIndices[Idx] = Off.second; } return true; } @@ -2656,7 +2651,7 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI, SymbolicStrides, UncomputablePtr, false); if (!CanDoRTIfNeeded) { auto *I = dyn_cast_or_null(UncomputablePtr); - recordAnalysis("CantIdentifyArrayBounds", I) + recordAnalysis("CantIdentifyArrayBounds", I) << "cannot identify array bounds"; LLVM_DEBUG(dbgs() << "LAA: We can't vectorize because we can't find " << "the array bounds.\n");