https://gcc.gnu.org/g:cd589516b12e28ee30aefc4c51500f634f1b888e

commit r16-1603-gcd589516b12e28ee30aefc4c51500f634f1b888e
Author: Jan Hubicka <hubi...@ucw.cz>
Date:   Sat Jun 21 22:29:50 2025 +0200

    Fix profile after fnsplit
    
    when splitting functions, tree-inline determined correctly entry count of 
the
    new function part, but then in case entry block of new function part is in a
    loop it scales body which is not suposed to happen.
    
            * tree-inline.cc (copy_cfg_body): Fix profile of split functions.

Diff:
---
 gcc/tree-inline.cc | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc
index b25705173433..dee2dfc26206 100644
--- a/gcc/tree-inline.cc
+++ b/gcc/tree-inline.cc
@@ -3084,7 +3084,7 @@ copy_cfg_body (copy_body_data * id,
   /* Register specific tree functions.  */
   gimple_register_cfg_hooks ();
 
-  /* If we are inlining just region of the function, make sure to connect
+  /* If we are offlining region of the function, make sure to connect
      new entry to ENTRY_BLOCK_PTR_FOR_FN (cfun).  Since new entry can be
      part of loop, we must compute frequency and probability of
      ENTRY_BLOCK_PTR_FOR_FN (cfun) based on the frequencies and
@@ -3093,12 +3093,14 @@ copy_cfg_body (copy_body_data * id,
     {
       edge e;
       edge_iterator ei;
-      den = profile_count::zero ();
+      ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = profile_count::zero ();
 
       FOR_EACH_EDGE (e, ei, new_entry->preds)
        if (!e->src->aux)
-         den += e->count ();
-      ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = den;
+         ENTRY_BLOCK_PTR_FOR_FN (cfun)->count += e->count ();
+      /* Do not scale - the profile of offlined region should
+        remain unchanged.  */
+      num = den = profile_count::one ();
     }
 
   profile_count::adjust_for_ipa_scaling (&num, &den);

Reply via email to