[llvm] [MergeFunctions] Preserve entry counts on folds (PR #202218)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 18 23:12:47 PDT 2026


================
@@ -872,6 +877,25 @@ static bool isODR(const Function *F) {
   return F->hasWeakODRLinkage() || F->hasLinkOnceODRLinkage();
 }
 
+static void mergeEntryCountsInto(Function *F,
+                                 std::optional<Function::ProfileCount> FC,
+                                 std::optional<Function::ProfileCount> GC) {
+  if (!FC && !GC)
+    return;
+  uint64_t Sum = SaturatingAdd(FC ? FC->getCount() : uint64_t{0},
+                               GC ? GC->getCount() : uint64_t{0});
+  Function::ProfileCountType PCT =
+      ((FC && FC->isSynthetic()) || (GC && GC->isSynthetic()))
+          ? Function::PCT_Synthetic
+          : Function::PCT_Real;
+  if (FC && FC->getType() != PCT) {
----------------
boomanaiden154 wrote:

This logic is confusing.

It seems like we're trying to only propagate entry counts of the same type, but I feel the code could be written to be more readable.

It's also unclear to me why we even care about the synthetic case. As far as I can tell, it's not really used anywhere and should probably just be removed entirely.

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


More information about the llvm-commits mailing list