public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH GCC8][27/33]Extend candidate set if new_cp has cheaper dependence
@ 2017-04-18 10:52 Bin Cheng
  2017-04-26 13:38 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Bin Cheng @ 2017-04-18 10:52 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd

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

Hi,
Currently we only allow iv_ca extension if new_cp has cheaper cost and less deps than old_cp.
This is inaccurate because it's possible the overall deps is reduced even new_cp has more deps
than old_cp.  This happens in case that new_cp's deps are already in iv_ca.  This patch allows
more iv_ca extension by checking overall deps in iv_ca.
Is it OK?

Thanks,
bin
2017-04-11  Bin Cheng  <bin.cheng@arm.com>

	* tree-ssa-loop-ivopts.c (compare_cost_pair): New.
	(iv_ca_more_deps): Renamed to ...
	(iv_ca_compare_deps): ... this.
	(iv_ca_extend): Extend iv_ca if NEW_CP is cheaper than OLD_CP.

[-- Attachment #2: 0027-extend-cand-with-cheaper-deps-20170310.txt --]
[-- Type: text/plain, Size: 2908 bytes --]

From 9f45d3762e60b3c1d2de17ef3683f944be408f96 Mon Sep 17 00:00:00 2001
From: Bin Cheng <binche01@e108451-lin.cambridge.arm.com>
Date: Fri, 31 Mar 2017 14:18:55 +0100
Subject: [PATCH 27/33] extend-cand-with-cheaper-deps-20170310.txt

---
 gcc/tree-ssa-loop-ivopts.c | 43 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index b93a589..0b9170c 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -5633,6 +5633,19 @@ cheaper_cost_pair (struct cost_pair *a, struct cost_pair *b)
   return false;
 }
 
+/* Compare if A is a more expensive cost pair than B.  Return 1, 0 and -1
+   for more expensive, equal and cheaper respectively.  */
+
+static int
+compare_cost_pair (struct cost_pair *a, struct cost_pair *b)
+{
+  if (cheaper_cost_pair (a, b))
+    return -1;
+  if (cheaper_cost_pair (b, a))
+    return 1;
+
+  return 0;
+}
 
 /* Returns candidate by that USE is expressed in IVS.  */
 
@@ -5818,13 +5831,14 @@ iv_ca_cost (struct iv_ca *ivs)
     return ivs->cost;
 }
 
-/* Returns true if applying NEW_CP to GROUP for IVS introduces more
-   invariants than OLD_CP.  */
+/* Compare if applying NEW_CP to GROUP for IVS introduces more invariants
+   than OLD_CP.  Return 1, 0 and -1 for more, equal and fewer invariants
+   respectively.  */
 
-static bool
-iv_ca_more_deps (struct ivopts_data *data, struct iv_ca *ivs,
-		 struct iv_group *group, struct cost_pair *old_cp,
-		 struct cost_pair *new_cp)
+static int
+iv_ca_compare_deps (struct ivopts_data *data, struct iv_ca *ivs,
+		    struct iv_group *group, struct cost_pair *old_cp,
+		    struct cost_pair *new_cp)
 {
   gcc_assert (old_cp && new_cp && old_cp != new_cp);
   unsigned old_n_invs = ivs->n_invs;
@@ -5832,7 +5846,7 @@ iv_ca_more_deps (struct ivopts_data *data, struct iv_ca *ivs,
   unsigned new_n_invs = ivs->n_invs;
   iv_ca_set_cp (data, ivs, group, old_cp);
 
-  return (new_n_invs > old_n_invs);
+  return new_n_invs > old_n_invs ? 1 : (new_n_invs < old_n_invs ? -1 : 0);
 }
 
 /* Creates change of expressing GROUP by NEW_CP instead of OLD_CP and chains
@@ -6064,11 +6078,18 @@ iv_ca_extend (struct ivopts_data *data, struct iv_ca *ivs,
       if (!new_cp)
 	continue;
 
-      if (!min_ncand && iv_ca_more_deps (data, ivs, group, old_cp, new_cp))
-	continue;
+      if (!min_ncand)
+	{
+	  int cmp_invs = iv_ca_compare_deps (data, ivs, group, old_cp, new_cp);
+	  /* Skip if new_cp depends on more invariants.  */
+	  if (cmp_invs > 0)
+	    continue;
 
-      if (!min_ncand && !cheaper_cost_pair (new_cp, old_cp))
-	continue;
+	  int cmp_cost = compare_cost_pair (new_cp, old_cp);
+	  /* Skip if new_cp is not cheaper.  */
+	  if (cmp_cost > 0 || (cmp_cost == 0 && cmp_invs == 0))
+	    continue;
+	}
 
       *delta = iv_ca_delta_add (group, old_cp, new_cp, *delta);
     }
-- 
1.9.1


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

* Re: [PATCH GCC8][27/33]Extend candidate set if new_cp has cheaper dependence
  2017-04-18 10:52 [PATCH GCC8][27/33]Extend candidate set if new_cp has cheaper dependence Bin Cheng
@ 2017-04-26 13:38 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-04-26 13:38 UTC (permalink / raw)
  To: Bin Cheng; +Cc: gcc-patches, nd

On Tue, Apr 18, 2017 at 12:52 PM, Bin Cheng <Bin.Cheng@arm.com> wrote:
> Hi,
> Currently we only allow iv_ca extension if new_cp has cheaper cost and less deps than old_cp.
> This is inaccurate because it's possible the overall deps is reduced even new_cp has more deps
> than old_cp.  This happens in case that new_cp's deps are already in iv_ca.  This patch allows
> more iv_ca extension by checking overall deps in iv_ca.
> Is it OK?

Ok.

Richard.

> Thanks,
> bin
> 2017-04-11  Bin Cheng  <bin.cheng@arm.com>
>
>         * tree-ssa-loop-ivopts.c (compare_cost_pair): New.
>         (iv_ca_more_deps): Renamed to ...
>         (iv_ca_compare_deps): ... this.
>         (iv_ca_extend): Extend iv_ca if NEW_CP is cheaper than OLD_CP.

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

end of thread, other threads:[~2017-04-26 13:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-18 10:52 [PATCH GCC8][27/33]Extend candidate set if new_cp has cheaper dependence Bin Cheng
2017-04-26 13:38 ` Richard Biener

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