public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: "Bin.Cheng" <amker.cheng@gmail.com>
Cc: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 2/3] Add profiling support for IVOPTS
Date: Mon, 30 May 2016 19:51:00 -0000	[thread overview]
Message-ID: <574C649F.8000808@suse.cz> (raw)
In-Reply-To: <CAHFci2-wYWJ=gsZ0THYoD1M28DCCBc362-DB0CSBSzFj7EjNhQ@mail.gmail.com>

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

On 05/24/2016 12:11 PM, Bin.Cheng wrote:
> Hi,
> Could you please factor out this as a function and remove the goto
> statements?  Okay with this change if no fallout in benchmarks you
> run.
> 
> Thanks,
> bin

Hi.

Thanks for the review, I've just verified that it does not introduce any
regression on SPECv6 and it improves couple of SPEC2006 benchmarks w/
PGO. I'm going to install the patch and make a control run of benchmarks.

Thanks
Martin

[-- Attachment #2: 0002-Add-profiling-support-for-IVOPTS-final.patch --]
[-- Type: text/x-patch, Size: 4117 bytes --]

From 2991622862dd934e464f542e9e58270bf0088544 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 17 May 2016 15:22:43 +0200
Subject: [PATCH 1/5] Add profiling support for IVOPTS

gcc/ChangeLog:

2016-05-17  Martin Liska  <mliska@suse.cz>

	* tree-ssa-loop-ivopts.c (get_computation_cost_at): Scale
	computed costs by frequency of BB they belong to.
	(get_scaled_computation_cost_at): New function.
---
 gcc/tree-ssa-loop-ivopts.c | 62 ++++++++++++++++++++++++++++++++++------------
 1 file changed, 46 insertions(+), 16 deletions(-)

diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index d770ec9..a541ef8 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -4794,7 +4794,33 @@ get_loop_invariant_expr (struct ivopts_data *data, tree ubase,
   return record_inv_expr (data, expr);
 }
 
+/* Scale (multiply) the computed COST (except scratch part that should be
+   hoisted out a loop) by header->frequency / AT->frequency,
+   which makes expected cost more accurate.  */
 
+static comp_cost
+get_scaled_computation_cost_at (ivopts_data *data, gimple *at, iv_cand *cand,
+				comp_cost cost)
+{
+   int loop_freq = data->current_loop->header->frequency;
+   int bb_freq = at->bb->frequency;
+   if (loop_freq != 0)
+     {
+       gcc_assert (cost.scratch <= cost.cost);
+       int scaled_cost
+	 = cost.scratch + (cost.cost - cost.scratch) * bb_freq / loop_freq;
+
+       if (dump_file && (dump_flags & TDF_DETAILS))
+	 fprintf (dump_file, "Scaling iv_use based on cand %d "
+		  "by %2.2f: %d (scratch: %d) -> %d (%d/%d)\n",
+		  cand->id, 1.0f * bb_freq / loop_freq, cost.cost,
+		  cost.scratch, scaled_cost, bb_freq, loop_freq);
+
+       cost.cost = scaled_cost;
+     }
+
+  return cost;
+}
 
 /* Determines the cost of the computation by that USE is expressed
    from induction variable CAND.  If ADDRESS_P is true, we just need
@@ -4982,18 +5008,21 @@ get_computation_cost_at (struct ivopts_data *data,
      (symbol/var1/const parts may be omitted).  If we are looking for an
      address, find the cost of addressing this.  */
   if (address_p)
-    return cost + get_address_cost (symbol_present, var_present,
-				    offset, ratio, cstepi,
-				    mem_mode,
-				    TYPE_ADDR_SPACE (TREE_TYPE (utype)),
-				    speed, stmt_is_after_inc, can_autoinc);
+    {
+      cost += get_address_cost (symbol_present, var_present,
+				offset, ratio, cstepi,
+				mem_mode,
+				TYPE_ADDR_SPACE (TREE_TYPE (utype)),
+				speed, stmt_is_after_inc, can_autoinc);
+      return get_scaled_computation_cost_at (data, at, cand, cost);
+    }
 
   /* Otherwise estimate the costs for computing the expression.  */
   if (!symbol_present && !var_present && !offset)
     {
       if (ratio != 1)
 	cost += mult_by_coeff_cost (ratio, TYPE_MODE (ctype), speed);
-      return cost;
+      return get_scaled_computation_cost_at (data, at, cand, cost);
     }
 
   /* Symbol + offset should be compile-time computable so consider that they
@@ -5012,24 +5041,25 @@ get_computation_cost_at (struct ivopts_data *data,
   aratio = ratio > 0 ? ratio : -ratio;
   if (aratio != 1)
     cost += mult_by_coeff_cost (aratio, TYPE_MODE (ctype), speed);
-  return cost;
+
+  return get_scaled_computation_cost_at (data, at, cand, cost);
 
 fallback:
   if (can_autoinc)
     *can_autoinc = false;
 
-  {
-    /* Just get the expression, expand it and measure the cost.  */
-    tree comp = get_computation_at (data->current_loop, use, cand, at);
+  /* Just get the expression, expand it and measure the cost.  */
+  tree comp = get_computation_at (data->current_loop, use, cand, at);
 
-    if (!comp)
-      return infinite_cost;
+  if (!comp)
+    return infinite_cost;
+
+  if (address_p)
+    comp = build_simple_mem_ref (comp);
 
-    if (address_p)
-      comp = build_simple_mem_ref (comp);
+  cost = comp_cost (computation_cost (comp, speed), 0);
 
-    return comp_cost (computation_cost (comp, speed), 0);
-  }
+  return get_scaled_computation_cost_at (data, at, cand, cost);
 }
 
 /* Determines the cost of the computation by that USE is expressed
-- 
2.8.3


  parent reply	other threads:[~2016-05-30 16:05 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-29 11:58 [PATCH 0/3] IVOPTS: support profiling marxin
2016-04-29 11:58 ` [PATCH 3/3] Enhance dumps of IVOPTS marxin
2016-05-06  9:19   ` Martin Liška
2016-05-09  9:47     ` Richard Biener
2016-05-10 13:16       ` Bin.Cheng
2016-05-11 14:18         ` Martin Liška
2016-05-12 12:14         ` Martin Liška
2016-05-12 13:51           ` Bin.Cheng
2016-05-12 16:42             ` Martin Liška
2016-05-13  9:43               ` Bin.Cheng
2016-05-13 10:44                 ` Martin Liška
2016-05-13 12:12                   ` H.J. Lu
2016-05-13 12:39                     ` Martin Liška
2016-05-13 12:44                       ` Kyrill Tkachov
2016-05-13 12:47                         ` Richard Biener
2016-05-13 12:51                           ` Martin Liška
2016-05-13 14:17                             ` H.J. Lu
2016-05-13 14:46                               ` H.J. Lu
2016-04-29 11:58 ` [PATCH 2/3] Add profiling support for IVOPTS marxin
2016-05-16 13:56   ` Martin Liška
2016-05-16 22:27     ` Bin.Cheng
2016-05-19 10:28       ` Martin Liška
2016-05-20 10:04         ` Bin.Cheng
2016-05-24 10:19         ` Bin.Cheng
2016-05-24 10:33           ` Bin.Cheng
2016-05-24 11:01           ` Bin.Cheng
2016-05-30 19:51           ` Martin Liška [this message]
2016-04-29 11:58 ` [PATCH 1/3] Encapsulate comp_cost within a class with methods marxin
2016-05-16 10:14   ` Bin.Cheng
2016-05-16 13:55     ` Martin Liška
2016-05-19 10:23       ` Martin Liška
2016-05-19 11:24         ` Bin.Cheng
2016-05-26 21:02           ` Martin Liška
2016-05-03  9:28 ` [PATCH 0/3] IVOPTS: support profiling 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=574C649F.8000808@suse.cz \
    --to=mliska@suse.cz \
    --cc=amker.cheng@gmail.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).