public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Introduce new param: AVG_LOOP_NITER
@ 2016-07-11  7:56 Martin Liška
  2016-07-11 14:35 ` Jeff Law
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Liška @ 2016-07-11  7:56 UTC (permalink / raw)
  To: GCC Patches; +Cc: Jan Hubicka

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

Hello.

During investigation of an IVOPTs issue, I noticed that tree-ssa-loop-ivopts.c uses a hard-coded
constant AVG_LOOP_NITER. Very similar constant can be seen in cfgloopanal.c. Thus, I've changed
that to a new param.

Apart from that, I would like to change the default value to 10.
As numbers of SPEC CPU2006 show:

Loop count: 18236
  avg. # of iter: 11908.46
  median # of iter: 10.00
  avg. (1% cutoff) # of iter: 1003.87
  avg. (5% cutoff) # of iter: 449.78
  avg. (10% cutoff) # of iter: 209.46
  avg. (20% cutoff) # of iter: 62.24
  avg. (30% cutoff) # of iter: 42.69

Even though the average number of loop iteration is quite high, let's start to increase it
conservatively to 10. Benchmark results are within a noise level (-Ofast runs faster by 0.47%).

Patch survives regression tests and bootstraps on x86_64-linux-gnu.
Ready for trunk?
Thanks,
Martin

[-- Attachment #2: 0001-Introduce-new-param-AVG_LOOP_NITER.patch --]
[-- Type: text/x-patch, Size: 3035 bytes --]

From 604637de550a9d23b8a509cdbf493a7212a186f0 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 21 Jun 2016 14:52:31 +0200
Subject: [PATCH] Introduce new param: AVG_LOOP_NITER

gcc/ChangeLog:

2016-06-21  Martin Liska  <mliska@suse.cz>

	* params.def: Add avg-loop niter.
	* tree-ssa-loop-ivopts.c (avg_loop_niter): Use the param.
	* cfgloopanal.c (expected_loop_iterations_unbounded): Likewise.
---
 gcc/cfgloopanal.c          | 9 ++++-----
 gcc/params.def             | 5 +++++
 gcc/tree-ssa-loop-ivopts.c | 7 +++----
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/gcc/cfgloopanal.c b/gcc/cfgloopanal.c
index c163986..2739f44 100644
--- a/gcc/cfgloopanal.c
+++ b/gcc/cfgloopanal.c
@@ -241,10 +241,9 @@ expected_loop_iterations_unbounded (const struct loop *loop,
   if (read_profile_p)
     *read_profile_p = false;
 
-  /* Average loop rolls about 3 times. If we have no profile at all, it is
-     best we can do.  */
+  /* If we have no profile at all, use AVG_LOOP_NITER.  */
   if (profile_status_for_fn (cfun) == PROFILE_ABSENT)
-    expected = 3;
+    expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER);
   else if (loop->latch->count || loop->header->count)
     {
       gcov_type count_in, count_latch;
@@ -282,9 +281,9 @@ expected_loop_iterations_unbounded (const struct loop *loop,
 
       if (freq_in == 0)
 	{
-	  /* If we have no profile at all, expect 3 iterations.  */
+	  /* If we have no profile at all, use AVG_LOOP_NITER iterations.  */
 	  if (!freq_latch)
-	    expected = 3;
+	    expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER);
 	  else
 	    expected = freq_latch * 2;
 	}
diff --git a/gcc/params.def b/gcc/params.def
index 894b7f3..b86d592 100644
--- a/gcc/params.def
+++ b/gcc/params.def
@@ -527,6 +527,11 @@ DEFPARAM(PARAM_IV_ALWAYS_PRUNE_CAND_SET_BOUND,
 	 "If number of candidates in the set is smaller, we always try to remove unused ivs during its optimization.",
 	 10, 0, 0)
 
+DEFPARAM(PARAM_AVG_LOOP_NITER,
+	 "avg-loop-niter",
+	 "Average number of iterations of a loop.",
+	 10, 1, 0)
+
 DEFPARAM(PARAM_SCEV_MAX_EXPR_SIZE,
  	 "scev-max-expr-size",
 	 "Bound on size of expressions used in the scalar evolutions analyzer.",
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 6b403f5..d401c41 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -115,8 +115,6 @@ along with GCC; see the file COPYING3.  If not see
 /* The infinite cost.  */
 #define INFTY 10000000
 
-#define AVG_LOOP_NITER(LOOP) 5
-
 /* Returns the expected number of loop iterations for LOOP.
    The average trip count is computed from profile data if it
    exists. */
@@ -128,8 +126,9 @@ avg_loop_niter (struct loop *loop)
   if (niter == -1)
     {
       niter = likely_max_stmt_executions_int (loop);
-      if (niter == -1 || niter > AVG_LOOP_NITER (loop))
-	return AVG_LOOP_NITER (loop);
+
+      if (niter == -1 || niter > PARAM_VALUE (PARAM_AVG_LOOP_NITER))
+	return PARAM_VALUE (PARAM_AVG_LOOP_NITER);
     }
 
   return niter;
-- 
2.8.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Introduce new param: AVG_LOOP_NITER
  2016-07-11  7:56 [PATCH] Introduce new param: AVG_LOOP_NITER Martin Liška
@ 2016-07-11 14:35 ` Jeff Law
  2016-07-12 15:27   ` Martin Liška
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Law @ 2016-07-11 14:35 UTC (permalink / raw)
  To: Martin Liška, GCC Patches; +Cc: Jan Hubicka

On 07/11/2016 01:55 AM, Martin Liška wrote:
> Hello.
>
> During investigation of an IVOPTs issue, I noticed that tree-ssa-loop-ivopts.c uses a hard-coded
> constant AVG_LOOP_NITER. Very similar constant can be seen in cfgloopanal.c. Thus, I've changed
> that to a new param.
>
> Apart from that, I would like to change the default value to 10.
> As numbers of SPEC CPU2006 show:
>
> Loop count: 18236
>   avg. # of iter: 11908.46
>   median # of iter: 10.00
>   avg. (1% cutoff) # of iter: 1003.87
>   avg. (5% cutoff) # of iter: 449.78
>   avg. (10% cutoff) # of iter: 209.46
>   avg. (20% cutoff) # of iter: 62.24
>   avg. (30% cutoff) # of iter: 42.69
>
> Even though the average number of loop iteration is quite high, let's start to increase it
> conservatively to 10. Benchmark results are within a noise level (-Ofast runs faster by 0.47%).
>
> Patch survives regression tests and bootstraps on x86_64-linux-gnu.
> Ready for trunk?
Don't you need a corresponding change to invoke.texi?

OK with that change.

jeff

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Introduce new param: AVG_LOOP_NITER
  2016-07-11 14:35 ` Jeff Law
@ 2016-07-12 15:27   ` Martin Liška
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Liška @ 2016-07-12 15:27 UTC (permalink / raw)
  To: Jeff Law, GCC Patches; +Cc: Jan Hubicka

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

On 07/11/2016 04:35 PM, Jeff Law wrote:
> Don't you need a corresponding change to invoke.texi?
> 
> OK with that change.
> 
> jeff

Thanks, I've just mentioned the param in invoke.texi, installed as r238252.

Martin

[-- Attachment #2: 0001-Introduce-new-param-AVG_LOOP_NITER-v2.patch --]
[-- Type: text/x-patch, Size: 3621 bytes --]

From c4c456c2bea9225c287f7af0e88f39cf780f815d Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 21 Jun 2016 14:52:31 +0200
Subject: [PATCH] Introduce new param: AVG_LOOP_NITER

gcc/ChangeLog:

2016-06-21  Martin Liska  <mliska@suse.cz>

	* params.def: Add avg-loop niter.
	* tree-ssa-loop-ivopts.c (avg_loop_niter): Use the param.
	* cfgloopanal.c (expected_loop_iterations_unbounded): Likewise.
	* doc/invoke.texi: Document the new parameter.
---
 gcc/cfgloopanal.c          | 9 ++++-----
 gcc/doc/invoke.texi        | 3 +++
 gcc/params.def             | 5 +++++
 gcc/tree-ssa-loop-ivopts.c | 7 +++----
 4 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/gcc/cfgloopanal.c b/gcc/cfgloopanal.c
index c163986..2739f44 100644
--- a/gcc/cfgloopanal.c
+++ b/gcc/cfgloopanal.c
@@ -241,10 +241,9 @@ expected_loop_iterations_unbounded (const struct loop *loop,
   if (read_profile_p)
     *read_profile_p = false;
 
-  /* Average loop rolls about 3 times. If we have no profile at all, it is
-     best we can do.  */
+  /* If we have no profile at all, use AVG_LOOP_NITER.  */
   if (profile_status_for_fn (cfun) == PROFILE_ABSENT)
-    expected = 3;
+    expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER);
   else if (loop->latch->count || loop->header->count)
     {
       gcov_type count_in, count_latch;
@@ -282,9 +281,9 @@ expected_loop_iterations_unbounded (const struct loop *loop,
 
       if (freq_in == 0)
 	{
-	  /* If we have no profile at all, expect 3 iterations.  */
+	  /* If we have no profile at all, use AVG_LOOP_NITER iterations.  */
 	  if (!freq_latch)
-	    expected = 3;
+	    expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER);
 	  else
 	    expected = freq_latch * 2;
 	}
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 997faa1..88fff05 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -9150,6 +9150,9 @@ If the number of candidates in the set is smaller than this value,
 always try to remove unnecessary ivs from the set
 when adding a new one.
 
+@item avg-loop-niter
+Average number of iterations of a loop.
+
 @item scev-max-expr-size
 Bound on size of expressions used in the scalar evolutions analyzer.
 Large expressions slow the analyzer.
diff --git a/gcc/params.def b/gcc/params.def
index 894b7f3..b86d592 100644
--- a/gcc/params.def
+++ b/gcc/params.def
@@ -527,6 +527,11 @@ DEFPARAM(PARAM_IV_ALWAYS_PRUNE_CAND_SET_BOUND,
 	 "If number of candidates in the set is smaller, we always try to remove unused ivs during its optimization.",
 	 10, 0, 0)
 
+DEFPARAM(PARAM_AVG_LOOP_NITER,
+	 "avg-loop-niter",
+	 "Average number of iterations of a loop.",
+	 10, 1, 0)
+
 DEFPARAM(PARAM_SCEV_MAX_EXPR_SIZE,
  	 "scev-max-expr-size",
 	 "Bound on size of expressions used in the scalar evolutions analyzer.",
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index f5f6e78..20cf9ef 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -115,8 +115,6 @@ along with GCC; see the file COPYING3.  If not see
 /* The infinite cost.  */
 #define INFTY 10000000
 
-#define AVG_LOOP_NITER(LOOP) 5
-
 /* Returns the expected number of loop iterations for LOOP.
    The average trip count is computed from profile data if it
    exists. */
@@ -128,8 +126,9 @@ avg_loop_niter (struct loop *loop)
   if (niter == -1)
     {
       niter = likely_max_stmt_executions_int (loop);
-      if (niter == -1 || niter > AVG_LOOP_NITER (loop))
-	return AVG_LOOP_NITER (loop);
+
+      if (niter == -1 || niter > PARAM_VALUE (PARAM_AVG_LOOP_NITER))
+	return PARAM_VALUE (PARAM_AVG_LOOP_NITER);
     }
 
   return niter;
-- 
2.8.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-12 15:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-11  7:56 [PATCH] Introduce new param: AVG_LOOP_NITER Martin Liška
2016-07-11 14:35 ` Jeff Law
2016-07-12 15:27   ` Martin Liška

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).