[llvm] [Instrumentation] Fix EdgeCounts vector size in SetBranchWeights (PR #99064)

Avi Kivity via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 8 12:32:00 PDT 2024


================
@@ -1623,10 +1623,12 @@ void PGOUseFunc::setBranchWeights() {
       continue;
 
     // We have a non-zero Branch BB.
-    unsigned Size = BBCountInfo.OutEdges.size();
-    SmallVector<uint64_t, 2> EdgeCounts(Size, 0);
+    unsigned OutEdgesCount = BBCountInfo.OutEdges.size();
+    unsigned SuccessorCount = BB.getTerminator()->getNumSuccessors();
+
+    SmallVector<uint64_t, 2> EdgeCounts(SuccessorCount, 0);
----------------
avikivity wrote:

I'm not an LLVM developer. I don't even know what a successor is in this context.  I observed a crash, and following the source I saw the EdgeCounts vector was sized differently than the range of the index. So I changed the vector size to match the range of the index.

Since I don't observe the crash in llvm main, it could be that it changed so that the range of the index now matches the size of the vector. It could also be (and I think this is likely) that the pgo machinery changed enough that the 18.1.6 based profile no longer triggers the bug. I don't have any way to tell. I believe the change improves the code either way (though only cosmetically in one case).

I'm willing to follow guidance in order to generate a test case, but my knowledge here is almost nil.

https://github.com/llvm/llvm-project/pull/99064


More information about the llvm-commits mailing list