[PR87563][AARCH64-SVE]: Don't keep ifcvt loop when COND_<OP> ifn could not be vectorized.
authorRenlin Li <renlin.li@arm.com>
Mon, 15 Oct 2018 16:49:05 +0000 (16:49 +0000)
committerRenlin Li <renlin@gcc.gnu.org>
Mon, 15 Oct 2018 16:49:05 +0000 (16:49 +0000)
ifcvt will created versioned loop and it will permissively generate
scalar COND_<OP> ifn.

If in the loop vectorize pass, COND_<OP> could not get vectoized,
the if-converted loop should be abandoned when the target doesn't support
such ifn.

gcc/

2018-10-12  Renlin Li  <renlin.li@arm.com>

PR target/87563
* tree-vectorizer.c (try_vectorize_loop_1): Don't use
if-conversioned loop when it contains ifn with types not
supported by backend.
* internal-fn.c (expand_direct_optab_fn): Add an assert.
(direct_internal_fn_supported_p): New helper function.
* internal-fn.h (direct_internal_fn_supported_p): Declare.

gcc/testsuite/

2018-10-12  Renlin Li  <renlin.li@arm.com>

PR target/87563
* gcc.target/aarch64/sve/pr87563.c: New.

From-SVN: r265172

gcc/ChangeLog
gcc/internal-fn.c
gcc/internal-fn.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/aarch64/sve/pr87563.c [new file with mode: 0644]
gcc/tree-vectorizer.c

index 0a2b703b58197f3a87423beac35001e8b092647f..0b8c7e555a633df0803b74521ba81852a27d81b1 100644 (file)
@@ -1,3 +1,13 @@
+2018-10-15  Renlin Li  <renlin.li@arm.com>
+
+       PR target/87563
+       * tree-vectorizer.c (try_vectorize_loop_1): Don't use
+       if-conversioned loop when it contains ifn with types not
+       supported by backend.
+       * internal-fn.c (expand_direct_optab_fn): Add an assert.
+       (direct_internal_fn_supported_p): New helper function.
+       * internal-fn.h (direct_internal_fn_supported_p): Declare.
+
 2018-10-15  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/87572
index 34d4f9efab9a45e0a9e3622f37dab0fa417b76f7..d082dd5054fa7175ffd3a53414b1ef42a1fca14e 100644 (file)
@@ -2890,6 +2890,7 @@ expand_direct_optab_fn (internal_fn fn, gcall *stmt, direct_optab optab,
 
   tree_pair types = direct_internal_fn_types (fn, stmt);
   insn_code icode = direct_optab_handler (optab, TYPE_MODE (types.first));
+  gcc_assert (icode != CODE_FOR_nothing);
 
   tree lhs = gimple_call_lhs (stmt);
   rtx lhs_rtx = NULL_RTX;
@@ -3183,6 +3184,17 @@ direct_internal_fn_supported_p (internal_fn fn, tree type,
   return direct_internal_fn_supported_p (fn, tree_pair (type, type), opt_type);
 }
 
+/* Return true if the STMT is supported when the optimization type is OPT_TYPE,
+   given that STMT is a call to a direct internal function.  */
+
+bool
+direct_internal_fn_supported_p (gcall *stmt, optimization_type opt_type)
+{
+  internal_fn fn = gimple_call_internal_fn (stmt);
+  tree_pair types = direct_internal_fn_types (fn, stmt);
+  return direct_internal_fn_supported_p (fn, types, opt_type);
+}
+
 /* If FN is commutative in two consecutive arguments, return the
    index of the first, otherwise return -1.  */
 
index 99765cf407acc7d65356b156e91f9dc51f1dba34..ff3bace1ce643ee10e1f776efffa01af31b6bbe7 100644 (file)
@@ -187,6 +187,7 @@ extern bool direct_internal_fn_supported_p (internal_fn, tree_pair,
                                            optimization_type);
 extern bool direct_internal_fn_supported_p (internal_fn, tree,
                                            optimization_type);
+extern bool direct_internal_fn_supported_p (gcall *, optimization_type);
 
 /* Return true if FN is supported for types TYPE0 and TYPE1 when the
    optimization type is OPT_TYPE.  The types are those associated with
index f08abb181893d5de7f828d5272d36a5ea87839b7..7f8b0852e903925511fd8d7eab24686f7c7ca8a0 100644 (file)
@@ -1,3 +1,8 @@
+2018-10-15  Renlin Li  <renlin.li@arm.com>
+
+       PR target/87563
+       * gcc.target/aarch64/sve/pr87563.c: New.
+
 2018-10-15  Paul Thomas  <pault@gcc.gnu.org>
        Tobias Burnus  <burnus@gcc.gnu.org>
 
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr87563.c b/gcc/testsuite/gcc.target/aarch64/sve/pr87563.c
new file mode 100644 (file)
index 0000000..83553b7
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-vectorize -fdump-tree-ifcvt-details -fdump-tree-vect" } */
+
+int a, b, c, *e;
+int d[2];
+
+void f ()
+{
+  while (c)
+    {
+      d[0] = 4;
+      d[1] = 4;
+      *e = b == 0 ? 0 : a / b;
+    }
+}
+
+/* { dg-final { scan-tree-dump "COND_DIV" "ifcvt" } } */
+/* { dg-final { scan-tree-dump-not "COND_DIV" "vect" } } */
index 60ee7f6380c02f971e0c73340e5028a1252c1513..12bf0fcd5bde4b889fb74342c4e7dd52327efa57 100644 (file)
@@ -80,6 +80,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "attribs.h"
 #include "gimple-pretty-print.h"
 #include "opt-problem.h"
+#include "internal-fn.h"
 
 
 /* Loop or bb location, with hotness information.  */
@@ -899,23 +900,30 @@ try_vectorize_loop_1 (hash_table<simduid_to_vf> *&simduid_to_vf_htab,
          && ! loop->inner)
        {
          basic_block bb = loop->header;
-         bool has_mask_load_store = false;
+         bool require_loop_vectorize = false;
          for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
               !gsi_end_p (gsi); gsi_next (&gsi))
            {
              gimple *stmt = gsi_stmt (gsi);
-             if (is_gimple_call (stmt)
-                 && gimple_call_internal_p (stmt)
-                 && (gimple_call_internal_fn (stmt) == IFN_MASK_LOAD
-                     || gimple_call_internal_fn (stmt) == IFN_MASK_STORE))
+             gcall *call = dyn_cast <gcall *> (stmt);
+             if (call && gimple_call_internal_p (call))
                {
-                 has_mask_load_store = true;
-                 break;
+                 internal_fn ifn = gimple_call_internal_fn (call);
+                 if (ifn == IFN_MASK_LOAD || ifn == IFN_MASK_STORE
+                     /* Don't keep the if-converted parts when the ifn with
+                        specifc type is not supported by the backend.  */
+                     || (direct_internal_fn_p (ifn)
+                         && !direct_internal_fn_supported_p
+                         (call, OPTIMIZE_FOR_SPEED)))
+                   {
+                     require_loop_vectorize = true;
+                     break;
+                   }
                }
              gimple_set_uid (stmt, -1);
              gimple_set_visited (stmt, false);
            }
-         if (! has_mask_load_store && vect_slp_bb (bb))
+         if (!require_loop_vectorize && vect_slp_bb (bb))
            {
              dump_printf_loc (MSG_NOTE, vect_location,
                               "basic block vectorized\n");