diff mbox

[GCC8,27/33] Extend candidate set if new_cp has cheaper dependence

Message ID VI1PR0802MB217666947C35BB2926F75108E7190@VI1PR0802MB2176.eurprd08.prod.outlook.com
State New
Headers show

Commit Message

Bin Cheng April 18, 2017, 10:52 a.m. UTC
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.
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(-)

Comments

Richard Biener April 26, 2017, 1:30 p.m. UTC | #1
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.
diff mbox

Patch

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);
     }