The EXTRACT_LAST_REDUCTION handling needs to generate a separate
comparison instruction that feeds the vector mask argument of the
IFN_EXTRACT_LAST call.  We weren't checking whether that comparison
was supported, leading to an ICE on the testcase.

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

Richard


2019-12-28  Richard Sandiford  <richard.sandif...@arm.com>

gcc/
        * tree-vect-stmts.c (vectorizable_condition): For extract-last
        reductions, check that the target supports the required comparison
        operation.

gcc/testsuite/
        * gcc.dg/vect/vect-cond-12.c: New test.

Index: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c       2019-12-27 16:53:46.000000000 +0000
+++ gcc/tree-vect-stmts.c       2019-12-28 16:28:16.344143831 +0000
@@ -10081,6 +10081,16 @@ vectorizable_condition (stmt_vec_info st
       cond_code = SSA_NAME;
     }
 
+  if (TREE_CODE_CLASS (cond_code) == tcc_comparison
+      && reduction_type == EXTRACT_LAST_REDUCTION
+      && !expand_vec_cmp_expr_p (comp_vectype, vec_cmp_type, cond_code))
+    {
+      if (dump_enabled_p ())
+       dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                        "reduction comparison operation not supported.\n");
+      return false;
+    }
+
   if (!vec_stmt)
     {
       if (bitop1 != NOP_EXPR)
Index: gcc/testsuite/gcc.dg/vect/vect-cond-12.c
===================================================================
--- /dev/null   2019-09-17 11:41:18.176664108 +0100
+++ gcc/testsuite/gcc.dg/vect/vect-cond-12.c    2019-12-28 16:28:16.344143831 
+0000
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+
+int
+f (int *x, short *y)
+{
+  int res = 100;
+  for (int i = 0; i < 40; ++i)
+    {
+      if (y[i] > 1)
+       res = x[i];
+      x[i] += y[i];
+    }
+  return res;
+}

Reply via email to