* [PATCH 01/2]Maintain irreducible region information in vectorizer peeling
@ 2017-03-28 12:01 Bin Cheng
2017-03-28 12:18 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Bin Cheng @ 2017-03-28 12:01 UTC (permalink / raw)
To: gcc-patches; +Cc: nd
[-- 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;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 01/2]Maintain irreducible region information in vectorizer peeling
2017-03-28 12:01 [PATCH 01/2]Maintain irreducible region information in vectorizer peeling Bin Cheng
@ 2017-03-28 12:18 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-03-28 12:18 UTC (permalink / raw)
To: Bin Cheng; +Cc: gcc-patches, nd
On Tue, Mar 28, 2017 at 2:01 PM, Bin Cheng <Bin.Cheng@arm.com> wrote:
> 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?
Ok (please omit the checking_verify_loop_structure call for now).
Thanks,
Richard.
> 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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-03-28 12:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-28 12:01 [PATCH 01/2]Maintain irreducible region information in vectorizer peeling Bin Cheng
2017-03-28 12:18 ` 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).