public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bin Cheng <Bin.Cheng@arm.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Cc: nd <nd@arm.com>
Subject: [PATCH 01/2]Maintain irreducible region information in vectorizer peeling
Date: Tue, 28 Mar 2017 12:01:00 -0000	[thread overview]
Message-ID: <VI1PR0802MB21769C4B77294F7B91499D03E7320@VI1PR0802MB2176.eurprd08.prod.outlook.com> (raw)

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

Hi,
This patch fixes a latent bug in vectorizer, specifically, vect_do_peeling doesn't mark newly created edge
with irreducible flag if the vectorized loop is in irreducible region.  Function checking_verify_loop_structure
needs to be explicitly called in vectorizer otherwise the issue is covered, but I am okay if we should avoid
this call.
Bootstrap and test on x86_64 and AArch64.  This patch causes new failure in gcc.dg/tree-ssa/pr71077.c,
which uncovers another latent bug in vectorizer.  That will be fixed by next patch.  Is this OK?

2017-03-27  Bin Cheng  <bin.cheng@arm.com>

	* tree-vect-loop-manip.c (slpeel_add_loop_guard): New param and
	mark new edge's irreducible flag accordign to it.
	(vect_do_peeling): Check loop preheader edge's irreducible flag
	and pass it to function slpeel_add_loop_guard.
	* tree-vectorizer.c (vectorize_loops): Explicitly call function
	checking_verify_loop_structure.

gcc/testsuite/ChangeLog
2017-03-27  Bin Cheng  <bin.cheng@arm.com>

	* gcc.c-torture/compile/irreducible-loop.c: New.

[-- Attachment #2: irreducible-loop-20170327.txt --]
[-- Type: text/plain, Size: 4354 bytes --]

diff --git a/gcc/testsuite/gcc.c-torture/compile/irreducible-loop.c b/gcc/testsuite/gcc.c-torture/compile/irreducible-loop.c
new file mode 100644
index 0000000..e4be667
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/irreducible-loop.c
@@ -0,0 +1,21 @@
+void foo (int n, double a, double *b, double *x)
+{
+  int i, j;
+
+  if(n <= 0) return;
+  if (a == 0.0e0) return;
+
+  if (a > 5.0)
+    {
+      i = 0;
+      goto sec;
+    }
+  for (i = 0; i < 1024; i++)
+    {
+      double y = b[i];
+sec:
+      b[i+1] = y + 5.0;
+      for (j = 0; j < n; j++)
+	x[j] = x[j] + a;
+    }
+}
diff --git a/gcc/tree-vect-loop-manip.c b/gcc/tree-vect-loop-manip.c
index 2f82061..f48336b 100644
--- a/gcc/tree-vect-loop-manip.c
+++ b/gcc/tree-vect-loop-manip.c
@@ -534,12 +534,13 @@ slpeel_tree_duplicate_loop_to_edge_cfg (struct loop *loop,
 /* Given the condition expression COND, put it as the last statement of
    GUARD_BB; set both edges' probability; set dominator of GUARD_TO to
    DOM_BB; return the skip edge.  GUARD_TO is the target basic block to
-   skip the loop.  PROBABILITY is the skip edge's probability.  */
+   skip the loop.  PROBABILITY is the skip edge's probability.  Mark the
+   new edge as irreducible if IRREDUCIBLE_P is true.  */
 
 static edge
 slpeel_add_loop_guard (basic_block guard_bb, tree cond,
 		       basic_block guard_to, basic_block dom_bb,
-		       int probability)
+		       int probability, bool irreducible_p)
 {
   gimple_stmt_iterator gsi;
   edge new_e, enter_e;
@@ -566,6 +567,9 @@ slpeel_add_loop_guard (basic_block guard_bb, tree cond,
   new_e->count = guard_bb->count;
   new_e->probability = probability;
   new_e->count = apply_probability (enter_e->count, probability);
+  if (irreducible_p)
+    new_e->flags |= EDGE_IRREDUCIBLE_LOOP;
+
   enter_e->count -= new_e->count;
   enter_e->probability = inverse_probability (probability);
   set_immediate_dominator (CDI_DOMINATORS, guard_to, dom_bb);
@@ -1667,6 +1671,7 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1,
 
   struct loop *prolog, *epilog = NULL, *loop = LOOP_VINFO_LOOP (loop_vinfo);
   struct loop *first_loop = loop;
+  bool irred_flag = loop_preheader_edge (loop)->flags & EDGE_IRREDUCIBLE_LOOP;
   create_lcssa_for_virtual_phi (loop);
   update_ssa (TODO_update_ssa_only_virtuals);
 
@@ -1748,7 +1753,8 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1,
 	  guard_to = split_edge (loop_preheader_edge (loop));
 	  guard_e = slpeel_add_loop_guard (guard_bb, guard_cond,
 					   guard_to, guard_bb,
-					   inverse_probability (prob_prolog));
+					   inverse_probability (prob_prolog),
+					   irred_flag);
 	  e = EDGE_PRED (guard_to, 0);
 	  e = (e != guard_e ? e : EDGE_PRED (guard_to, 1));
 	  slpeel_update_phi_nodes_for_guard1 (prolog, loop, guard_e, e);
@@ -1813,7 +1819,8 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1,
 	  guard_to = split_edge (loop_preheader_edge (epilog));
 	  guard_e = slpeel_add_loop_guard (guard_bb, guard_cond,
 					   guard_to, guard_bb,
-					   inverse_probability (prob_vector));
+					   inverse_probability (prob_vector),
+					   irred_flag);
 	  e = EDGE_PRED (guard_to, 0);
 	  e = (e != guard_e ? e : EDGE_PRED (guard_to, 1));
 	  slpeel_update_phi_nodes_for_guard1 (first_loop, epilog, guard_e, e);
@@ -1853,7 +1860,8 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1,
 	  guard_to = split_edge (single_exit (epilog));
 	  guard_e = slpeel_add_loop_guard (guard_bb, guard_cond, guard_to,
 					   skip_vector ? anchor : guard_bb,
-					   inverse_probability (prob_epilog));
+					   inverse_probability (prob_epilog),
+					   irred_flag);
 	  slpeel_update_phi_nodes_for_guard2 (loop, epilog, guard_e,
 					      single_exit (epilog));
 	  /* Only need to handle basic block before epilog loop if it's not
diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c
index f928dec..4e9b90d 100644
--- a/gcc/tree-vectorizer.c
+++ b/gcc/tree-vectorizer.c
@@ -781,6 +781,7 @@ vectorize_loops (void)
 	 ???  Also while we try hard to update loop-closed SSA form we fail
 	 to properly do this in some corner-cases (see PR56286).  */
       rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa_only_virtuals);
+      checking_verify_loop_structure ();
       return TODO_cleanup_cfg;
     }
 

             reply	other threads:[~2017-03-28 12:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-28 12:01 Bin Cheng [this message]
2017-03-28 12:18 ` Richard Biener

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=VI1PR0802MB21769C4B77294F7B91499D03E7320@VI1PR0802MB2176.eurprd08.prod.outlook.com \
    --to=bin.cheng@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=nd@arm.com \
    /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).