public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH PR81369/02]Conservatively not distribute loop with unknown niters
@ 2017-07-14 14:32 Bin Cheng
  2017-07-17 10:12 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Bin Cheng @ 2017-07-14 14:32 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd

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

Hi,
This is a followup patch for previous fix to PR81369.  In that test case, GCC
tries to distribute infinite loop, which doesn't make much sense.  This patch
works conservatively by skipping loops with unknown niters.  It also simplifies
code a bit.
Bootstrap and test on x86_64 and AArch64, is it OK?

Thanks,
bin
2017-07-12  Bin Cheng  <bin.cheng@arm.com>

	PR target/81369
	* tree-loop-distribution.c (classify_partition): Only assert on
	numer of iterations.
	(merge_dep_scc_partitions): Delete prameter.  Update function call.
	(distribute_loop): Remove code handling loop with unknown niters.
	(pass_loop_distribution::execute): Skip loop with unknown niters.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-skip-loop-with-unknown-niters.txt.patch --]
[-- Type: text/x-patch; name="0002-skip-loop-with-unknown-niters.txt.patch", Size: 3370 bytes --]

From b96c0053b79fd457df1fdb91c4401a1a7ccace7d Mon Sep 17 00:00:00 2001
From: Bin Cheng <binche01@e108451-lin.cambridge.arm.com>
Date: Wed, 12 Jul 2017 12:30:12 +0100
Subject: [PATCH 2/2] skip-loop-with-unknown-niters.txt

---
 gcc/tree-loop-distribution.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c
index fe678a5..497e6a9 100644
--- a/gcc/tree-loop-distribution.c
+++ b/gcc/tree-loop-distribution.c
@@ -1412,8 +1412,7 @@ classify_partition (loop_p loop, struct graph *rdg, partition *partition,
     return;
 
   nb_iter = number_of_latch_executions (loop);
-  if (!nb_iter || nb_iter == chrec_dont_know)
-    return;
+  gcc_assert (nb_iter && nb_iter != chrec_dont_know);
   if (dominated_by_p (CDI_DOMINATORS, single_exit (loop)->src,
 		      gimple_bb (DR_STMT (single_store))))
     plus_one = true;
@@ -1962,18 +1961,16 @@ sort_partitions_by_post_order (struct graph *pg,
 }
 
 /* Given reduced dependence graph RDG merge strong connected components
-   of PARTITIONS.  If IGNORE_ALIAS_P is true, data dependence caused by
-   possible alias between references is ignored, as if it doesn't exist
-   at all; otherwise all depdendences are considered.  */
+   of PARTITIONS.  In this function, data dependence caused by possible
+   alias between references is ignored, as if it doesn't exist at all.  */
 
 static void
 merge_dep_scc_partitions (struct graph *rdg,
-			  vec<struct partition *> *partitions,
-			  bool ignore_alias_p)
+			  vec<struct partition *> *partitions)
 {
   struct partition *partition1, *partition2;
   struct pg_vdata *data;
-  graph *pg = build_partition_graph (rdg, partitions, ignore_alias_p);
+  graph *pg = build_partition_graph (rdg, partitions, true);
   int i, j, num_sccs = graphds_scc (pg, NULL);
 
   /* Strong connected compoenent means dependence cycle, we cannot distribute
@@ -2420,9 +2417,6 @@ distribute_loop (struct loop *loop, vec<gimple *> stmts,
   auto_vec<struct partition *, 3> partitions;
   rdg_build_partitions (rdg, stmts, &partitions);
 
-  /* Can't do runtime alias check if loop niter is unknown.  */
-  tree niters = number_of_latch_executions (loop);
-  bool rt_alias_check_p = (niters != NULL_TREE && niters != chrec_dont_know);
   auto_vec<ddr_p> alias_ddrs;
 
   auto_bitmap stmt_in_all_partitions;
@@ -2511,9 +2505,9 @@ distribute_loop (struct loop *loop, vec<gimple *> stmts,
   /* Build the partition dependency graph.  */
   if (partitions.length () > 1)
     {
-      merge_dep_scc_partitions (rdg, &partitions, rt_alias_check_p);
+      merge_dep_scc_partitions (rdg, &partitions);
       alias_ddrs.truncate (0);
-      if (rt_alias_check_p && partitions.length () > 1)
+      if (partitions.length () > 1)
 	break_alias_scc_partitions (rdg, &partitions, &alias_ddrs);
     }
 
@@ -2653,6 +2647,11 @@ pass_loop_distribution::execute (function *fun)
       if (!optimize_loop_for_speed_p (loop))
 	continue;
 
+      /* Don't distribute loop if niters is unknown.  */
+      tree niters = number_of_latch_executions (loop);
+      if (niters == NULL_TREE || niters == chrec_dont_know)
+	continue;
+
       /* Initialize the worklist with stmts we seed the partitions with.  */
       bbs = get_loop_body_in_dom_order (loop);
       for (i = 0; i < loop->num_nodes; ++i)
-- 
1.9.1


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

* Re: [PATCH PR81369/02]Conservatively not distribute loop with unknown niters
  2017-07-14 14:32 [PATCH PR81369/02]Conservatively not distribute loop with unknown niters Bin Cheng
@ 2017-07-17 10:12 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-07-17 10:12 UTC (permalink / raw)
  To: Bin Cheng; +Cc: gcc-patches, nd

On Fri, Jul 14, 2017 at 4:32 PM, Bin Cheng <Bin.Cheng@arm.com> wrote:
> Hi,
> This is a followup patch for previous fix to PR81369.  In that test case, GCC
> tries to distribute infinite loop, which doesn't make much sense.  This patch
> works conservatively by skipping loops with unknown niters.  It also simplifies
> code a bit.
> Bootstrap and test on x86_64 and AArch64, is it OK?

Ok.

Thanks,
Richard.

> Thanks,
> bin
> 2017-07-12  Bin Cheng  <bin.cheng@arm.com>
>
>         PR target/81369
>         * tree-loop-distribution.c (classify_partition): Only assert on
>         numer of iterations.
>         (merge_dep_scc_partitions): Delete prameter.  Update function call.
>         (distribute_loop): Remove code handling loop with unknown niters.
>         (pass_loop_distribution::execute): Skip loop with unknown niters.

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

end of thread, other threads:[~2017-07-17 10:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-14 14:32 [PATCH PR81369/02]Conservatively not distribute loop with unknown niters Bin Cheng
2017-07-17 10:12 ` 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).