public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "bin.cheng" <bin.cheng@linux.alibaba.com>
To: "gcc-patches" <gcc-patches@gcc.gnu.org>
Subject: [PATCH AutoFDO/2]Treat ZERO as common profile probability/count
Date: Wed, 31 Oct 2018 08:33:00 -0000	[thread overview]
Message-ID: <7f153787-f390-4661-92aa-06d47cefbbf5.bin.cheng@linux.alibaba.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1423 bytes --]

Hi,
In new profile probability/count infra, we have different precision quality categories,
and probabilities/counts of different categories are not supposed to be compared or
calculated.  Though in general is an improvement, it introduces unexpected behavior.
Specifically, class profile_probablity and profile_count themselves are implemented
by comparing probabilities/counts against profile_count::zero().  while zero() is of
profile_precision category, it's always compared different to zero of other precision
categories including afdo.

I can see two ways fixing this: 1) Treat zero as a common probability/count regardless
of its category; 2) Provide an "is_zero" method rather than relying on "==" comparison
against probability_count::zero().  2) requires lots of code changes so I went with 1)
in this patch set.  This patch doesn't handle "always" but it might be.

This patch also corrects a minor issue where we try to invert an uninitialized value.

Bootstrap and test on x86_64 in patch set.  Is it OK?

Thanks,
bin

2018-10-31  Bin Cheng  <bin.cheng@linux.alibaba.com>

	* expmed.c (emit_store_flag_force): Use profile_probability::always.
	* profile-count.h (profile_probability::always): Add parameter.
	(profile_probability::operator==, profile_count::operator==): Treat
	ZERO as common probability/count regardless of its quality.
	(profile_probability::invert): Don't invert uninitialized probability.

[-- Attachment #2: 0002-Handle-ZERO-profile-count-prob-as-a-general-value-fo.patch --]
[-- Type: application/octet-stream, Size: 2760 bytes --]

From 9532b75d548aee18929396dd3f5b05ffab1f32f5 Mon Sep 17 00:00:00 2001
From: chengbin <bin.cheng@linux.alibaba.com>
Date: Thu, 16 Aug 2018 12:09:48 +0800
Subject: [PATCH 2/4] Handle ZERO profile count/prob as a general value for
 different qualities. Don't invert uninitialized profile probability.

---
 gcc/expmed.c        |  2 +-
 gcc/profile-count.h | 16 ++++++++++------
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/gcc/expmed.c b/gcc/expmed.c
index 444d6a82f98..6e95f3c76eb 100644
--- a/gcc/expmed.c
+++ b/gcc/expmed.c
@@ -6166,7 +6166,7 @@ emit_store_flag_force (rtx target, enum rtx_code code, rtx op0, rtx op1,
   emit_move_insn (target, trueval);
   label = gen_label_rtx ();
   do_compare_rtx_and_jump (op0, op1, code, unsignedp, mode, NULL_RTX, NULL,
-			   label, profile_probability::uninitialized ());
+			   label, profile_probability::always ());
 
   emit_move_insn (target, falseval);
   emit_label (label);
diff --git a/gcc/profile-count.h b/gcc/profile-count.h
index f4d0c340a0a..7003d030d58 100644
--- a/gcc/profile-count.h
+++ b/gcc/profile-count.h
@@ -200,11 +200,11 @@ public:
       ret.m_quality = profile_guessed;
       return ret;
     }
-  static profile_probability always ()
+  static profile_probability always (enum profile_quality q = profile_precise)
     {
       profile_probability ret;
       ret.m_val = max_probability;
-      ret.m_quality = profile_precise;
+      ret.m_quality = q;
       return ret;
     }
   /* Probabilities which has not been initialized. Either because
@@ -284,7 +284,8 @@ public:
   /* Basic operations.  */
   bool operator== (const profile_probability &other) const
     {
-      return m_val == other.m_val && m_quality == other.m_quality;
+      return (m_val == other.m_val
+	      && (m_quality == other.m_quality || m_val == 0));
     }
   profile_probability operator+ (const profile_probability &other) const
     {
@@ -459,10 +460,12 @@ public:
       return RDIV (val * m_val, max_probability);
     }
 
-  /* Return 1-*THIS.  */
+  /* Return 1-*THIS.  It's meaningless to invert an uninitialized value.  */
   profile_probability invert () const
     {
-      return profile_probability::always() - *this;
+      if (! initialized_p ())
+	return *this;
+      return profile_probability::always(m_quality) - *this;
     }
 
   /* Return THIS with quality dropped to GUESSED.  */
@@ -754,7 +757,8 @@ public:
   /* Basic operations.  */
   bool operator== (const profile_count &other) const
     {
-      return m_val == other.m_val && m_quality == other.m_quality;
+      return (m_val == other.m_val
+	      && (m_quality == other.m_quality || m_val == 0));
     }
   profile_count operator+ (const profile_count &other) const
     {
-- 
2.14.4.44.g2045bb6


             reply	other threads:[~2018-10-31  6:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-31  8:33 bin.cheng [this message]
2018-10-31  9:43 ` Richard Biener
2018-10-31  9:57   ` Bin.Cheng
2018-11-02  5:31   ` bin.cheng
2018-11-05 14:38     ` Jan Hubicka
2018-11-05 14:40     ` Jan Hubicka
2018-11-13  6:58       ` Bin.Cheng
     [not found]   ` <20181105141206.4ncu3s2v2jxv6o54@kam.mff.cuni.cz>
2018-11-20 10:54     ` bin.cheng
     [not found]       ` <CAHFci28CQB3KK+Yp7gb8BR61UaGhAJJ-R1yzZPHxitczvgEB3w@mail.gmail.com>
2018-11-28 16:20         ` Jan Hubicka
2018-12-04  8:40           ` Bin.Cheng
2018-12-07 10:00             ` Bin.Cheng
2018-12-07 16:57               ` Jan Hubicka
2018-12-09  6:40                 ` Bin.Cheng
2018-10-31 15:02 ` Jeff Law
2018-11-01  1:11   ` Bin.Cheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7f153787-f390-4661-92aa-06d47cefbbf5.bin.cheng@linux.alibaba.com \
    --to=bin.cheng@linux.alibaba.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).