enable live comparison vectorization
authorRichard Biener <rguenther@suse.de>
Wed, 9 Sep 2020 10:05:55 +0000 (12:05 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 9 Sep 2020 11:12:27 +0000 (13:12 +0200)
This removes a check preventing vectorization of live results of
vectorized comparisons.  I tested it with AVX512 mask registers
(inspecting assembly) and traditional vector masks.

2020-09-09  Richard Biener  <rguenther@suse.de>

* tree-vect-stmts.c (vectorizable_comparison): Allow
STMT_VINFO_LIVE_P stmts.

* gcc.dg/vect/vect-live-6.c: New testcase.

gcc/testsuite/gcc.dg/vect/vect-live-6.c [new file with mode: 0644]
gcc/tree-vect-stmts.c

diff --git a/gcc/testsuite/gcc.dg/vect/vect-live-6.c b/gcc/testsuite/gcc.dg/vect/vect-live-6.c
new file mode 100644 (file)
index 0000000..c986c97
--- /dev/null
@@ -0,0 +1,31 @@
+#include "tree-vect.h"
+
+int a[1024];
+int b[1024];
+
+_Bool
+fn1 ()
+{
+  _Bool tem;
+  for (int i = 0; i < 1024; ++i)
+    {
+      tem = !a[i];
+      b[i] = tem;
+    }
+  return tem;
+}
+
+int main()
+{
+  check_vect ();
+  for (int i = 0; i < 1024; ++i)
+    {
+      a[i] = i & 5;
+      __asm__ volatile ("" ::: "memory");
+    }
+  if (fn1 () != !(1023 & 5) || b[2] != 1)
+    abort ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump "vectorized 1 loops" "vect" { target vect_int } } } */
index e069f874f72537a5236a27836fd37e87626b4e7f..191957c3543031ff587adccaf3bf19a641a815eb 100644 (file)
@@ -10319,14 +10319,6 @@ vectorizable_comparison (vec_info *vinfo,
   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def)
     return false;
 
-  if (loop_vinfo && STMT_VINFO_LIVE_P (stmt_info))
-    {
-      if (dump_enabled_p ())
-       dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-                        "value used after loop.\n");
-      return false;
-    }
-
   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
   if (!stmt)
     return false;