re PR tree-optimization/77503 (ICE in vect_transform_stmt compiling postgresql)
authorBin Cheng <bin.cheng@arm.com>
Thu, 15 Sep 2016 16:31:35 +0000 (16:31 +0000)
committerBin Cheng <amker@gcc.gnu.org>
Thu, 15 Sep 2016 16:31:35 +0000 (16:31 +0000)
PR tree-optimization/77503
* tree-vect-loop.c (vectorizable_reduction): Record reduction
code for CONST_COND_REDUCTION at analysis stage and use it at
transform stage.
* tree-vectorizer.h (struct _stmt_vec_info): New field.
(STMT_VINFO_VEC_CONST_COND_REDUC_CODE): New macro.
* tree-vect-stmts.c (new_stmt_vec_info): Initialize above new
field.

gcc/testsuite
* gcc.dg/vect/pr77503.c: New test.

From-SVN: r240166

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/pr77503.c [new file with mode: 0644]
gcc/tree-vect-loop.c
gcc/tree-vect-stmts.c
gcc/tree-vectorizer.h

index 019be1a49e43f988f7f01f6a9a870de6ea58f732..63651f74fbd9543193df66fe5a8d0d7086c041bf 100644 (file)
@@ -1,3 +1,14 @@
+2016-09-15  Bin Cheng  <bin.cheng@arm.com>
+
+       PR tree-optimization/77503
+       * tree-vect-loop.c (vectorizable_reduction): Record reduction
+       code for CONST_COND_REDUCTION at analysis stage and use it at
+       transform stage.
+       * tree-vectorizer.h (struct _stmt_vec_info): New field.
+       (STMT_VINFO_VEC_CONST_COND_REDUC_CODE): New macro.
+       * tree-vect-stmts.c (new_stmt_vec_info): Initialize above new
+       field.
+
 2016-09-15  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/77544
index 6a7cc9c330638b9825382b108b41828a4c1cda13..fdd2acdcca762ad574014417b11a3355748c4530 100644 (file)
@@ -1,3 +1,8 @@
+2016-09-15  Bin Cheng  <bin.cheng@arm.com>
+
+       PR tree-optimization/77503
+       * gcc.dg/vect/pr77503.c: New test.
+
 2016-09-15  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/77544
diff --git a/gcc/testsuite/gcc.dg/vect/pr77503.c b/gcc/testsuite/gcc.dg/vect/pr77503.c
new file mode 100644 (file)
index 0000000..609e7fb
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_condition } */
+/* { dg-skip-if "need vect_max_reduc support" { ! vect_max_reduc } } */
+
+extern void d(void);
+void a() {
+  char *b;
+  char c = 0;
+  for (; b < (char *)a; b++) {
+    if (*b)
+      c = 1;
+    *b = 0;
+  }
+  if (c)
+    d();
+}
+/* { dg-final { scan-tree-dump "vectorized 1 loops" "vect" } } */
index fa06505d1f228279cf7ec8d4f597687cd432722b..58f3456fe407e2da9049880b8348154ebeb9cc86 100644 (file)
@@ -5438,7 +5438,7 @@ vectorizable_reduction (gimple *stmt, gimple_stmt_iterator *gsi,
   tree def0, def1, tem, op1 = NULL_TREE;
   bool first_p = true;
   tree cr_index_scalar_type = NULL_TREE, cr_index_vector_type = NULL_TREE;
-  tree cond_reduc_val = NULL_TREE, const_cond_cmp = NULL_TREE;
+  tree cond_reduc_val = NULL_TREE;
 
   /* In case of reduction chain we switch to the first stmt in the chain, but
      we don't update STMT_INFO, since only the last stmt is marked as reduction
@@ -5645,7 +5645,19 @@ vectorizable_reduction (gimple *stmt, gimple_stmt_iterator *gsi,
            = INTEGER_INDUC_COND_REDUCTION;
        }
 
-      if (cond_reduc_dt == vect_constant_def)
+      /* Loop peeling modifies initial value of reduction PHI, which
+        makes the reduction stmt to be transformed different to the
+        original stmt analyzed.  We need to record reduction code for
+        CONST_COND_REDUCTION type reduction at analyzing stage, thus
+        it can be used directly at transform stage.  */
+      if (STMT_VINFO_VEC_CONST_COND_REDUC_CODE (stmt_info) == MAX_EXPR
+         || STMT_VINFO_VEC_CONST_COND_REDUC_CODE (stmt_info) == MIN_EXPR)
+       {
+         /* Also set the reduction type to CONST_COND_REDUCTION.  */
+         gcc_assert (cond_reduc_dt == vect_constant_def);
+         STMT_VINFO_VEC_REDUCTION_TYPE (stmt_info) = CONST_COND_REDUCTION;
+       }
+      else if (cond_reduc_dt == vect_constant_def)
        {
          enum vect_def_type cond_initial_dt;
          gimple *def_stmt = SSA_NAME_DEF_STMT (ops[reduc_index]);
@@ -5667,7 +5679,9 @@ vectorizable_reduction (gimple *stmt, gimple_stmt_iterator *gsi,
                    dump_printf_loc (MSG_NOTE, vect_location,
                                     "condition expression based on "
                                     "compile time constant.\n");
-                 const_cond_cmp = e;
+                 /* Record reduction code at analysis stage.  */
+                 STMT_VINFO_VEC_CONST_COND_REDUC_CODE (stmt_info)
+                   = integer_onep (e) ? MAX_EXPR : MIN_EXPR;
                  STMT_VINFO_VEC_REDUCTION_TYPE (stmt_info)
                    = CONST_COND_REDUCTION;
                }
@@ -5821,10 +5835,8 @@ vectorizable_reduction (gimple *stmt, gimple_stmt_iterator *gsi,
         we want to base our reduction around.  */
       if (STMT_VINFO_VEC_REDUCTION_TYPE (stmt_info) == CONST_COND_REDUCTION)
        {
-         gcc_assert (const_cond_cmp != NULL_TREE);
-         gcc_assert (integer_onep (const_cond_cmp)
-                     || integer_zerop (const_cond_cmp));
-         orig_code = integer_onep (const_cond_cmp) ? MAX_EXPR : MIN_EXPR;
+         orig_code = STMT_VINFO_VEC_CONST_COND_REDUC_CODE (stmt_info);
+         gcc_assert (orig_code == MAX_EXPR || orig_code == MIN_EXPR);
        }
       else if (STMT_VINFO_VEC_REDUCTION_TYPE (stmt_info)
                 == INTEGER_INDUC_COND_REDUCTION)
index ce5536c69276962bd8bd426f9e032c04e472bd78..6a6167ba50431c2f8ed3704c0df94f161a9c6c12 100644 (file)
@@ -8563,6 +8563,7 @@ new_stmt_vec_info (gimple *stmt, vec_info *vinfo)
   STMT_VINFO_PATTERN_DEF_SEQ (res) = NULL;
   STMT_VINFO_DATA_REF (res) = NULL;
   STMT_VINFO_VEC_REDUCTION_TYPE (res) = TREE_CODE_REDUCTION;
+  STMT_VINFO_VEC_CONST_COND_REDUC_CODE (res) = ERROR_MARK;
 
   STMT_VINFO_DR_BASE_ADDRESS (res) = NULL;
   STMT_VINFO_DR_OFFSET (res) = NULL;
index 29ef676cbf498480499c39e3b498f4b088faf906..240af069a51fb18d196745217279046fe08f19e1 100644 (file)
@@ -657,6 +657,9 @@ typedef struct _stmt_vec_info {
   /* For reduction loops, this is the type of reduction.  */
   enum vect_reduction_type v_reduc_type;
 
+  /* For CONST_COND_REDUCTION, record the reduc code.  */
+  enum tree_code const_cond_reduc_code;
+
   /* The number of scalar stmt references from active SLP instances.  */
   unsigned int num_slp_uses;
 } *stmt_vec_info;
@@ -711,6 +714,7 @@ STMT_VINFO_BB_VINFO (stmt_vec_info stmt_vinfo)
 #define STMT_VINFO_MEMORY_ACCESS_TYPE(S)   (S)->memory_access_type
 #define STMT_VINFO_SIMD_LANE_ACCESS_P(S)   (S)->simd_lane_access_p
 #define STMT_VINFO_VEC_REDUCTION_TYPE(S)   (S)->v_reduc_type
+#define STMT_VINFO_VEC_CONST_COND_REDUC_CODE(S) (S)->const_cond_reduc_code
 
 #define STMT_VINFO_DR_BASE_ADDRESS(S)      (S)->dr_base_address
 #define STMT_VINFO_DR_INIT(S)              (S)->dr_init