diff mbox

[02/2] Add newly created bb to correct loop when reverting if-conversion in vectorizer

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

Commit Message

Bin Cheng March 28, 2017, 12:01 p.m. UTC
Hi,
This patch is to fix a latent vectorizer bug uncovered by previous one.  Function optimize_mask_stores
creates if-then structure in CFG in order to revert if-conversion transformation.  It adds newly created
then_bb to outer loop when vectorizing two levels loop nest and masked_store is in the inner loop.  
Without this patch, gcc.dg/tree-ssa/pr71077.c would be broken.  Bootstrap and test on AArch64, is it OK?

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

	* tree-vect-loop.c (optimize_mask_stores): Add bb to the right
	loop.

Comments

Richard Biener March 28, 2017, 12:18 p.m. UTC | #1
On Tue, Mar 28, 2017 at 2:01 PM, Bin Cheng <Bin.Cheng@arm.com> wrote:
> Hi,
> This patch is to fix a latent vectorizer bug uncovered by previous one.  Function optimize_mask_stores
> creates if-then structure in CFG in order to revert if-conversion transformation.  It adds newly created
> then_bb to outer loop when vectorizing two levels loop nest and masked_store is in the inner loop.
> Without this patch, gcc.dg/tree-ssa/pr71077.c would be broken.  Bootstrap and test on AArch64, is it OK?

Ok.

Richard.

> 2017-03-27  Bin Cheng  <bin.cheng@arm.com>
>
>         * tree-vect-loop.c (optimize_mask_stores): Add bb to the right
>         loop.
diff mbox

Patch

diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 6bbf816..af874e7 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -7229,6 +7229,7 @@  optimize_mask_stores (struct loop *loop)
   unsigned nbbs = loop->num_nodes;
   unsigned i;
   basic_block bb;
+  struct loop *bb_loop;
   gimple_stmt_iterator gsi;
   gimple *stmt;
   auto_vec<gimple *> worklist;
@@ -7267,11 +7268,16 @@  optimize_mask_stores (struct loop *loop)
       last = worklist.pop ();
       mask = gimple_call_arg (last, 2);
       bb = gimple_bb (last);
-      /* Create new bb.  */
+      /* Create then_bb and if-then structure in CFG, then_bb belongs to
+	 the same loop as if_bb.  It could be different to LOOP when two
+	 level loop-nest is vectorized and mask_store belongs to the inner
+	 one.  */
       e = split_block (bb, last);
+      bb_loop = bb->loop_father;
+      gcc_assert (loop == bb_loop || flow_loop_nested_p (loop, bb_loop));
       join_bb = e->dest;
       store_bb = create_empty_bb (bb);
-      add_bb_to_loop (store_bb, loop);
+      add_bb_to_loop (store_bb, bb_loop);
       e->flags = EDGE_TRUE_VALUE;
       efalse = make_edge (bb, store_bb, EDGE_FALSE_VALUE);
       /* Put STORE_BB to likely part.  */