[llvm] [PGO][NFC] Avoid floating-point block uniformity check (PR #206547)

Yaxun Liu via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 29 10:48:25 PDT 2026


https://github.com/yxsamliu created https://github.com/llvm/llvm-project/pull/206547

Use an integer threshold when deciding whether a block is mostly uniform.

This keeps the 90% rule exact and avoids relying on floating-point arithmetic in profile merging.

>From b0396138a1b3f426293f4897f0c2d617a4f21975 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" <yaxun.liu at amd.com>
Date: Mon, 29 Jun 2026 13:02:42 -0400
Subject: [PATCH] [PGO][NFC] Avoid floating-point block uniformity check

Use an integer threshold when deciding whether a block is mostly uniform.

This keeps the 90% rule exact and avoids relying on floating-point arithmetic in profile merging.
---
 llvm/lib/ProfileData/InstrProf.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index 1124cbd95b185..1002c80af7801 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -962,8 +962,8 @@ void InstrProfRecord::computeBlockUniformity() {
   for (size_t I = 0, E = Counts.size(); I < E; ++I) {
     uint64_t TotalCount = Counts[I];
     uint64_t UniformCount = UniformCounts[I];
-    bool IsUniform =
-        TotalCount == 0 || (double)UniformCount / TotalCount >= 0.9;
+    uint64_t MinUniformCount = TotalCount - TotalCount / 10;
+    bool IsUniform = UniformCount >= MinUniformCount;
     if (!IsUniform)
       UniformityBits[I / 8] &= ~(1 << (I % 8));
   }



More information about the llvm-commits mailing list