[llvm] [PGO] Implement PGO counter promotion for atomic updates (PR #202487)
Wael Yehia via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 12 10:51:39 PDT 2026
================
@@ -567,6 +612,7 @@ class PGOCounterPromoter {
L.getLoopPreheader(), ExitBlocks,
InsertPts, LoopToCandidates, LI);
Promoter.run(SmallVector<Instruction *, 2>({Cand.first, Cand.second}));
+ Cand = {nullptr, nullptr};
----------------
w2yehia wrote:
so what you're saying is that a new `Loop*` map entry might be added to `LoopToCandidates`, which might rehash, invalidating any references to any `SmallVector<LoadStorePair,8>` object (in particular references to memory within the object, not malloc'ed memory which I presume is "moved").
That makes sense, and that would mean the [existing code](https://github.com/llvm/llvm-project/blob/8433cf6d6ccc49a0fd99ed86c7d94a1fbb2fd1be/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp#L547) is also broken because the iterator over the LoopToCandidates[&L] would get invalidated.
I think today, in the default -fprofile-generate path, every loop gets a counter, so `LoopToCandidates[TargetLoop]` will always find an existing entry in the map (i.e. no rehashing should occur).
https://github.com/llvm/llvm-project/pull/202487
More information about the llvm-commits
mailing list