[PATCH 2/6] Make builtin_vectorized_function take a combined_fn

Richard Biener richard.guenther@gmail.com
Tue Nov 10 10:36:00 GMT 2015


On Mon, Nov 9, 2015 at 5:25 PM, Richard Sandiford
<richard.sandiford@arm.com> wrote:
> This patch replaces the fndecl argument to builtin_vectorized_function
> with a combined_fn and gets the vectoriser to call it for internal
> functions too.  The patch also moves vectorisation of machine-specific
> built-ins to a new hook, builtin_md_vectorized_function.
>
> I've attached a -b version too since that's easier to read.

@@ -42095,8 +42018,7 @@ ix86_builtin_vectorized_function (tree fndecl,
tree type_out,

   /* Dispatch to a handler for a vectorization library.  */
   if (ix86_veclib_handler)
-    return ix86_veclib_handler ((enum built_in_function) fn, type_out,
-                               type_in);
+    return ix86_veclib_handler (combined_fn (fn), type_out, type_in);

   return NULL_TREE;
 }

fn is already a combined_fn?  Why does the builtin_vectorized_function
not take one but an unsigned int?

@@ -42176,11 +42077,12 @@ ix86_veclibabi_svml (enum built_in_function
fn, tree type_out, tree type_in)
       return NULL_TREE;
     }

-  bname = IDENTIFIER_POINTER (DECL_NAME (builtin_decl_implicit (fn)));
+  tree fndecl = mathfn_built_in (TREE_TYPE (type_in), fn);
+  bname = IDENTIFIER_POINTER (DECL_NAME (fndecl));

-  if (fn == BUILT_IN_LOGF)
+  if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_LOGF)

with 'fn' now a combined_fn how is this going to work with IFNs?

@@ -42194,9 +42096,7 @@ ix86_veclibabi_svml (enum built_in_function
fn, tree type_out, tree type_in)
   name[4] &= ~0x20;

   arity = 0;
-  for (args = DECL_ARGUMENTS (builtin_decl_implicit (fn));
-       args;
-       args = TREE_CHAIN (args))
+  for (args = DECL_ARGUMENTS (fndecl); args; args = TREE_CHAIN (args))
     arity++;


or this?

Did you try this out?  We have only two basic testcases for all this
code using sin()
which may not end up as IFN even with -ffast-math(?).

+/* Implement TARGET_VECTORIZE_BUILTIN_MD_VECTORIZED_FUNCTION.  */
+
+static tree
+rs6000_builtin_md_vectorized_function (tree fndecl, tree type_out,
+                                      tree type_in)
+{

any reason you are using a fndecl for this hook instead of the function code?

@@ -1639,20 +1639,20 @@ vect_finish_stmt_generation (gimple *stmt,
gimple *vec_stmt,
 tree
 vectorizable_function (gcall *call, tree vectype_out, tree vectype_in)
 {
-  tree fndecl = gimple_call_fndecl (call);
-
-  /* We only handle functions that do not read or clobber memory -- i.e.
-     const or novops ones.  */
-  if (!(gimple_call_flags (call) & (ECF_CONST | ECF_NOVOPS)))
+  /* We only handle functions that do not read or clobber memory.  */
+  if (gimple_vuse (call))
     return NULL_TREE;

-  if (!fndecl
-      || TREE_CODE (fndecl) != FUNCTION_DECL
-      || !DECL_BUILT_IN (fndecl))
-    return NULL_TREE;
+  combined_fn fn = gimple_call_combined_fn (call);
+  if (fn != CFN_LAST)
+    return targetm.vectorize.builtin_vectorized_function
+      (fn, vectype_out, vectype_in);

-  return targetm.vectorize.builtin_vectorized_function (fndecl, vectype_out,
-                                                       vectype_in);
+  if (gimple_call_builtin_p (call, BUILT_IN_MD))
+    return targetm.vectorize.builtin_md_vectorized_function
+      (gimple_call_fndecl (call), vectype_out, vectype_in);
+
+  return NULL_TREE;

Looking at this and the issues above wouldn't it be easier to simply
pass the call stmt to the hook (which then can again handle
both normal and target builtins)?  And it has context available
(actual arguments and number of arguments for IFN calls).

Richard.

>
> gcc/
>         * target.def (builtin_vectorized_function): Take a combined_fn (in
>         the form of an unsigned int) rather than a function decl.
>         (builtin_md_vectorized_function): New.
>         * targhooks.h (default_builtin_vectorized_function): Replace the
>         fndecl argument with an unsigned int.
>         (default_builtin_md_vectorized_function): Declare.
>         * targhooks.c (default_builtin_vectorized_function): Replace the
>         fndecl argument with an unsigned int.
>         (default_builtin_md_vectorized_function): New function.
>         * doc/tm.texi.in (TARGET_VECTORIZE_BUILTIN_MD_VECTORIZED_FUNCTION):
>         New hook.
>         * doc/tm.texi: Regenerate.
>         * tree-vect-stmts.c (vectorizable_function): Update call to
>         builtin_vectorized_function, also passing internal functions.
>         Call builtin_md_vectorized_function for target-specific builtins.
>         * config/aarch64/aarch64-protos.h
>         (aarch64_builtin_vectorized_function): Replace fndecl argument
>         with an unsigned int.
>         * config/aarch64/aarch64-builtins.c: Include case-cfn-macros.h.
>         (aarch64_builtin_vectorized_function): Update after above changes.
>         Use CASE_CFN_*.
>         * config/arm/arm-protos.h (arm_builtin_vectorized_function): Replace
>         fndecl argument with an unsigned int.
>         * config/arm/arm-builtins.c: Include case-cfn-macros.h
>         (arm_builtin_vectorized_function): Update after above changes.
>         Use CASE_CFN_*.
>         * config/i386/i386.c: Include case-cfn-macros.h
>         (ix86_veclib_handler): Take a combined_fn rather than a
>         built_in_function.
>         (ix86_veclibabi_svml, ix86_veclibabi_acml): Likewise.  Use
>         mathfn_built_in rather than calling builtin_decl_implicit directly.
>         (ix86_builtin_vectorized_function) Update after above changes.
>         Use CASE_CFN_*.
>         * config/rs6000/rs6000.c: Include case-cfn-macros.h
>         (rs6000_builtin_vectorized_libmass): Replace fndecl argument
>         with a combined_fn.  Use CASE_CFN_*.  Use mathfn_built_in rather
>         than calling builtin_decl_implicit directly.
>         (rs6000_builtin_vectorized_function): Update after above changes.
>         Use CASE_CFN_*.  Move BUILT_IN_MD to...
>         (rs6000_builtin_md_vectorized_function): ...this new function.
>         (TARGET_VECTORIZE_BUILTIN_MD_VECTORIZED_FUNCTION): Define.
>



More information about the Gcc-patches mailing list