Don't try to vectorise COND_EXPR reduction chains (PR 84913)
authorRichard Sandiford <richard.sandiford@linaro.org>
Sun, 18 Mar 2018 10:25:29 +0000 (10:25 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Sun, 18 Mar 2018 10:25:29 +0000 (10:25 +0000)
The testcase ICEd for both SVE and AVX512 because we were trying
to vectorise a chain of COND_EXPRs as a reduction and getting
confused by reduc_index == -1.

2018-03-18  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
PR tree-optimization/84913
* tree-vect-loop.c (vectorizable_reduction): Don't try to
vectorize chains of COND_EXPRs.

gcc/testsuite/
PR tree-optimization/84913
* gfortran.dg/vect/pr84913.f90: New test.

From-SVN: r258631

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/vect/pr84913.f90 [new file with mode: 0644]
gcc/tree-vect-loop.c

index 601cf5962f34d2ef679dcac692f80af1d395c1e1..2a77e3b9245fdd471dbdae508c90ea0f4f00da8f 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-18  Richard Sandiford  <richard.sandiford@linaro.org>
+
+       PR tree-optimization/84913
+       * tree-vect-loop.c (vectorizable_reduction): Don't try to
+       vectorize chains of COND_EXPRs.
+
 2018-03-18  Chung-Ju Wu  <jasonwucj@gmail.com>
 
        * config/nds32/nds32.h (MAX_REGS_PER_ADDRESS): Fix the value.
index 098444aaf33c4c2969f5cf1332a24eb73f208f5a..7d9a3fd4c2c93c86c7909778a95603379c89f979 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-18  Richard Sandiford  <richard.sandiford@linaro.org>
+
+       PR tree-optimization/84913
+       * gfortran.dg/vect/pr84913.f90: New test.
+
 2018-03-18  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/79929
diff --git a/gcc/testsuite/gfortran.dg/vect/pr84913.f90 b/gcc/testsuite/gfortran.dg/vect/pr84913.f90
new file mode 100644 (file)
index 0000000..f2ec4d2
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do compile }
+
+function foo(a, b, c, n)
+  integer :: a(n), b(n), c(n), n, i, foo
+  foo = 0
+  do i = 1, n
+    if (a(i) .eq. b(i)) then
+      foo = 1
+    else if (a(i) .eq. c(i)) then
+      foo = 2
+    end if
+  end do
+end function foo
index 6585c85cfe039465cbe850926787a34af6cc079a..7b3009aed2dcddcfd9153d06f1bf31fc2e08f131 100644 (file)
@@ -6788,6 +6788,30 @@ vectorizable_reduction (gimple *stmt, gimple_stmt_iterator *gsi,
   /* If we have a condition reduction, see if we can simplify it further.  */
   if (v_reduc_type == COND_REDUCTION)
     {
+      /* TODO: We can't yet handle reduction chains, since we need to treat
+        each COND_EXPR in the chain specially, not just the last one.
+        E.g. for:
+
+           x_1 = PHI <x_3, ...>
+           x_2 = a_2 ? ... : x_1;
+           x_3 = a_3 ? ... : x_2;
+
+        we're interested in the last element in x_3 for which a_2 || a_3
+        is true, whereas the current reduction chain handling would
+        vectorize x_2 as a normal VEC_COND_EXPR and only treat x_3
+        as a reduction operation.  */
+      if (reduc_index == -1)
+       {
+         if (dump_enabled_p ())
+           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                            "conditional reduction chains not supported\n");
+         return false;
+       }
+
+      /* vect_is_simple_reduction ensured that operand 2 is the
+        loop-carried operand.  */
+      gcc_assert (reduc_index == 2);
+
       /* 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