diff mbox series

Record the loop masks needed for EXTRACT_LAST_REDUCTIONs

Message ID mpt5zio5s8m.fsf@arm.com
State New
Headers show
Series Record the loop masks needed for EXTRACT_LAST_REDUCTIONs | expand

Commit Message

Richard Sandiford Dec. 10, 2019, 11:34 a.m. UTC
The analysis phase of vectorizable_condition wasn't recording the
loop masks needed by the transform phase.  This meant that the masks
wouldn't be created in the (rare) case that no other statement needed
them.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Richard


2019-12-10  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* tree-vect-stmts.c (vectorizable_condition): Record the loop
	masks required for extract-last reductions.

gcc/testsuite/
	* gcc.target/aarch64/sve/clastb_9.c: New test.

Comments

Richard Biener Dec. 10, 2019, 12:13 p.m. UTC | #1
On December 10, 2019 12:34:33 PM GMT+01:00, Richard Sandiford <richard.sandiford@arm.com> wrote:
>The analysis phase of vectorizable_condition wasn't recording the
>loop masks needed by the transform phase.  This meant that the masks
>wouldn't be created in the (rare) case that no other statement needed
>them.
>
>Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Ok. 

Richard. 

>Richard
>
>
>2019-12-10  Richard Sandiford  <richard.sandiford@arm.com>
>
>gcc/
>	* tree-vect-stmts.c (vectorizable_condition): Record the loop
>	masks required for extract-last reductions.
>
>gcc/testsuite/
>	* gcc.target/aarch64/sve/clastb_9.c: New test.
>
>Index: gcc/tree-vect-stmts.c
>===================================================================
>--- gcc/tree-vect-stmts.c	2019-12-10 11:33:27.136893420 +0000
>+++ gcc/tree-vect-stmts.c	2019-12-10 11:33:34.084845950 +0000
>@@ -9912,6 +9912,7 @@ vectorizable_condition (stmt_vec_info st
>        vect_unknown_def_type, vect_unknown_def_type};
>   int ndts = 4;
>   int ncopies;
>+  int vec_num;
>  enum tree_code code, cond_code, bitop1 = NOP_EXPR, bitop2 = NOP_EXPR;
>   stmt_vec_info prev_stmt_info = NULL;
>   int i, j;
>@@ -9969,9 +9970,15 @@ vectorizable_condition (stmt_vec_info st
>   tree vectype1 = NULL_TREE, vectype2 = NULL_TREE;
> 
>   if (slp_node)
>-    ncopies = 1;
>+    {
>+      ncopies = 1;
>+      vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
>+    }
>   else
>-    ncopies = vect_get_num_copies (loop_vinfo, vectype);
>+    {
>+      ncopies = vect_get_num_copies (loop_vinfo, vectype);
>+      vec_num = 1;
>+    }
> 
>   gcc_assert (ncopies >= 1);
>   if (for_reduction && ncopies > 1)
>@@ -10094,6 +10101,12 @@ vectorizable_condition (stmt_vec_info st
> 	    }
> 	}
> 
>+      if (loop_vinfo
>+	  && LOOP_VINFO_CAN_FULLY_MASK_P (loop_vinfo)
>+	  && reduction_type == EXTRACT_LAST_REDUCTION)
>+	vect_record_loop_mask (loop_vinfo, &LOOP_VINFO_MASKS (loop_vinfo),
>+			       ncopies * vec_num, vectype, NULL);
>+
>       vect_cost_for_stmt kind = vector_stmt;
>       if (reduction_type == EXTRACT_LAST_REDUCTION)
> 	/* Count one reduction-like operation per vector.  */
>Index: gcc/testsuite/gcc.target/aarch64/sve/clastb_9.c
>===================================================================
>--- /dev/null	2019-09-17 11:41:18.176664108 +0100
>+++ gcc/testsuite/gcc.target/aarch64/sve/clastb_9.c	2019-12-10
>11:33:34.080845979 +0000
>@@ -0,0 +1,21 @@
>+/* Originally gcc.dg/vect/O1-pr41008.c.  */
>+/* { dg-options "-O1 -ftree-vectorize -fno-vect-cost-model
>-msve-vector-bits=256" } */
>+
>+double heating[2][2];
>+
>+void foo (int, int);
>+
>+void map_do()
>+{
>+  int jsav, ksav, k, j;
>+
>+  for(k = 0; k < 2; k++)
>+    for(j = 0; j < 2; j++)
>+      if (heating[k][j] > 0.)
>+        {
>+          jsav = j;
>+          ksav = k;
>+        }
>+
>+  foo (jsav, ksav);
>+}
diff mbox series

Patch

Index: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c	2019-12-10 11:33:27.136893420 +0000
+++ gcc/tree-vect-stmts.c	2019-12-10 11:33:34.084845950 +0000
@@ -9912,6 +9912,7 @@  vectorizable_condition (stmt_vec_info st
        vect_unknown_def_type, vect_unknown_def_type};
   int ndts = 4;
   int ncopies;
+  int vec_num;
   enum tree_code code, cond_code, bitop1 = NOP_EXPR, bitop2 = NOP_EXPR;
   stmt_vec_info prev_stmt_info = NULL;
   int i, j;
@@ -9969,9 +9970,15 @@  vectorizable_condition (stmt_vec_info st
   tree vectype1 = NULL_TREE, vectype2 = NULL_TREE;
 
   if (slp_node)
-    ncopies = 1;
+    {
+      ncopies = 1;
+      vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
+    }
   else
-    ncopies = vect_get_num_copies (loop_vinfo, vectype);
+    {
+      ncopies = vect_get_num_copies (loop_vinfo, vectype);
+      vec_num = 1;
+    }
 
   gcc_assert (ncopies >= 1);
   if (for_reduction && ncopies > 1)
@@ -10094,6 +10101,12 @@  vectorizable_condition (stmt_vec_info st
 	    }
 	}
 
+      if (loop_vinfo
+	  && LOOP_VINFO_CAN_FULLY_MASK_P (loop_vinfo)
+	  && reduction_type == EXTRACT_LAST_REDUCTION)
+	vect_record_loop_mask (loop_vinfo, &LOOP_VINFO_MASKS (loop_vinfo),
+			       ncopies * vec_num, vectype, NULL);
+
       vect_cost_for_stmt kind = vector_stmt;
       if (reduction_type == EXTRACT_LAST_REDUCTION)
 	/* Count one reduction-like operation per vector.  */
Index: gcc/testsuite/gcc.target/aarch64/sve/clastb_9.c
===================================================================
--- /dev/null	2019-09-17 11:41:18.176664108 +0100
+++ gcc/testsuite/gcc.target/aarch64/sve/clastb_9.c	2019-12-10 11:33:34.080845979 +0000
@@ -0,0 +1,21 @@ 
+/* Originally gcc.dg/vect/O1-pr41008.c.  */
+/* { dg-options "-O1 -ftree-vectorize -fno-vect-cost-model -msve-vector-bits=256" } */
+
+double heating[2][2];
+
+void foo (int, int);
+
+void map_do()
+{
+  int jsav, ksav, k, j;
+
+  for(k = 0; k < 2; k++)
+    for(j = 0; j < 2; j++)
+      if (heating[k][j] > 0.)
+        {
+          jsav = j;
+          ksav = k;
+        }
+
+  foo (jsav, ksav);
+}