On 10/7/20 1:18 PM, Martin Liška wrote:
     * ipa-utils.c (ipa_merge_profiles):

I forgot to fill up the ChangeLog entry. Fixed.

Martin
>From a5d5d23175d336883972ebef66380cbc4f1b6d54 Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Wed, 7 Oct 2020 12:30:27 +0200
Subject: [PATCH] IPA: merge profiles more sensitively

During WPA we merge 2 functions where one is built with -O3
-fprofile-use while the other one uses -O0. We end up with:

prevailing node:

BitwiseCast (const double aFrom)
{
  long unsigned int temp;
  long unsigned int D.4528;

  <bb 2> :
  BitwiseCast (aFrom_2(D), &temp);
  _4 = temp;
  temp ={v} {CLOBBER};

  <bb 3> :
<L0>:
  return _4;

}

merged node:
BitwiseCast (const double aFrom)
{
  <bb 2> [count: 1509]:
  _3 = VIEW_CONVERT_EXPR<long unsigned int>(aFrom_2(D));
  return _3;
}

What happens is that we copy dst->count = src->count.ipa() but
we skip merging of BBs (a different CFG). Then we end up in situation
where profile of a ENTRY_BB_FOR_FN == uninitialized while
dst->count.quality is precise.

gcc/ChangeLog:

	PR ipa/97295
	* ipa-utils.c (ipa_merge_profiles): Assign dst->count only
	when CFG matches.
---
 gcc/ipa-utils.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/ipa-utils.c b/gcc/ipa-utils.c
index 23e7f714306..fe2149069be 100644
--- a/gcc/ipa-utils.c
+++ b/gcc/ipa-utils.c
@@ -437,10 +437,7 @@ ipa_merge_profiles (struct cgraph_node *dst,
   else if (dst->count.ipa ().initialized_p ())
     ;
   else if (src->count.ipa ().initialized_p ())
-    {
-      copy_counts = true;
-      dst->count = src->count.ipa ();
-    }
+    copy_counts = true;
 
   /* If no updating needed return early.  */
   if (dst->count == orig_count)
@@ -620,6 +617,9 @@ ipa_merge_profiles (struct cgraph_node *dst,
       bool dstscale = !copy_counts
 		      && dstnum.initialized_p () && !(dstnum == dstden);
 
+      if (copy_counts)
+	dst->count = src->count.ipa ();
+
       /* TODO: merge also statement histograms.  */
       FOR_ALL_BB_FN (srcbb, srccfun)
 	{
-- 
2.28.0

Reply via email to