[llvm] [SampleProfileLoader] Fix integer overflow in generateMDProfMetadata (PR #90217)

Nabeel Omer via llvm-commits llvm-commits at lists.llvm.org
Tue May 7 05:41:50 PDT 2024


================
@@ -1713,13 +1713,15 @@ void SampleProfileLoader::generateMDProfMetadata(Function &F) {
       // if needed. Sample counts in profiles are 64-bit unsigned values,
       // but internally branch weights are expressed as 32-bit values.
       if (Weight > std::numeric_limits<uint32_t>::max()) {
-        LLVM_DEBUG(dbgs() << " (saturated due to uint32_t overflow)");
+        LLVM_DEBUG(dbgs() << " (saturated due to uint32_t overflow)\n");
         Weight = std::numeric_limits<uint32_t>::max();
       }
       if (!SampleProfileUseProfi) {
         // Weight is added by one to avoid propagation errors introduced by
         // 0 weights.
-        Weights.push_back(static_cast<uint32_t>(Weight + 1));
+        Weights.push_back(static_cast<uint32_t>(
----------------
omern1 wrote:

Hi @spupyrev, I can't speak for all users of the non-profi inference path but from our perspective that would require analysis to understand the impact of profi on our codebases.

I think this discussion can be had separately from this patch.

If you / @WenleiHe  / @MatzeB are happy with the current state of this patch can I please get an LGTM?

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


More information about the llvm-commits mailing list