> -----Original Message-----
> From: Prathamesh Kulkarni
> Sent: 02 April 2026 19:35
> To: [email protected]; Jan Hubicka <[email protected]>; Richard
> Biener <[email protected]>
> Subject: [auto-profile] Improve handling of timestamp merging.
> 
> Hi,
> The following condition in function_instance::merge if (other-
> >timestamp() < timestamp())
>   set_timestamp (other->timestamp())
> 
> would set timestamp() to 0 if other->timestamp() was 0 effectively
> dropping the symbol from time-profile based reordering resulting in
> substantially reduced performance.
> 
> The patch fixes this by ensuring other->timestamp() is greater than
> zero before assigning it to timestamp.
> Also, handles the case when timestamp() is zero but other->timestamp()
> is non-zero.
> 
> For a large internal workload, this resulted in avoiding around ~67
> symbols from getting dropped which were present in gcov file and
> included in function reordering, which resulted in ~10% improvement.
> Would the patch be OK to commit to trunk, given that it's pretty
> localized and gated on -fauto-profile ?
Sorry, forgot to attach patch :/
Please find it attached.

Thanks,
Prathamesh
> 
> PS: There is also another issue I noticed about same filename having
> different indices in autofdo_source_profile::map_ which makes
> find_function_instance return NULL even if the symbol/filename entry
> is present in gcov file but that's an orthogonal issue.
> 
> Thanks,
> Prathamesh
[auto-profile] Improve handling of timestamp merging.

The following condition:
if (other->timestamp() < timestamp())
  set_timestamp (other->timestamp())

would set timestamp() to 0 if other->timestamp() was zero effectively
dropping the symbol from time-profile based reordering.
The patch fixes this by ensuring other->timestamp() is greater than zero.

Also, handles the case when timestamp() is zero but other->timestamp() is 
non-zero.

gcc/ChangeLog:
        * gcc/auto-profile.cc (function_instance::merge): Set 
other->timestamp() if it's
        lesser than timestamp() and greater than zero or if timestamp() is zero.

Signed-off-by: Prathamesh Kulkarni <[email protected]>

diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc
index 34f863a7731..f4562d7f2f9 100644
--- a/gcc/auto-profile.cc
+++ b/gcc/auto-profile.cc
@@ -1372,7 +1372,9 @@ function_instance::merge (function_instance *other,
     head_count_ += other->head_count_;
 
   /* While merging timestamps, set the one that occurs earlier.  */
-  if (other->timestamp () < timestamp ())
+  if (timestamp () == 0
+      || (other->timestamp () > 0
+         && other->timestamp () < timestamp ()))
     set_timestamp (other->timestamp ());
 
   bool changed = true;

Reply via email to