On Wed, Mar 28, 2018 at 04:18:45PM +0200, Martin Liška wrote:
> 2018-03-14  Martin Liska  <mli...@suse.cz>
> 
>       PR middle-end/81657
>       * builtins.c (expand_builtin_memory_copy_args): Handle situation
>       when libc library provides a fast mempcpy implementation/
>       * config/i386/i386-protos.h (gnu_libc_func_speed): New.
>       * config/i386/i386.c (enum libc_speed): Likewise.
>       (ix86_libc_func_speed): Likewise.
>       (TARGET_LIBC_FUNC_SPEED): Likewise.
>       * coretypes.h (enum libc_speed): Likewise.
>       * doc/tm.texi: Document new target hook.
>       * doc/tm.texi.in: Likewise.
>       * expr.c (emit_block_move_hints): Handle libc bail out argument.
>       * expr.h (emit_block_move_hints): Add new parameters.
>       * target.def: Add new hook.
>       * targhooks.c (enum libc_speed): New enum.
>       (default_libc_func_speed): Provide a default hook
>       implementation.
>       * targhooks.h (default_libc_func_speed): Likewise.
> 
> gcc/testsuite/ChangeLog:
> 
> 2018-03-14  Martin Liska  <mli...@suse.cz>
> 
>       * gcc.dg/string-opt-1.c: Adjust scans for i386 and glibc target
>       and others.
>    /* Copy word part most expediently.  */
> +  bool libcall_avoided = false;
>    dest_addr = emit_block_move_hints (dest_mem, src_mem, len_rtx,
>                                    CALL_EXPR_TAILCALL (exp)
>                                    && (endp == 0 || target == const0_rtx)
>                                    ? BLOCK_OP_TAILCALL : BLOCK_OP_NORMAL,
>                                    expected_align, expected_size,
> -                                  min_size, max_size, probable_max_size);
> +                                  min_size, max_size, probable_max_size,
> +                                  avoid_libcall ? &libcall_avoided: NULL);

Missing space before :.
> +
> +  if (libcall_avoided)
> +    return NULL_RTX;
>  
> --- a/gcc/config/i386/i386-protos.h
> +++ b/gcc/config/i386/i386-protos.h
> @@ -47,6 +47,8 @@ extern void ix86_reset_previous_fndecl (void);
>  
>  extern bool ix86_using_red_zone (void);
>  
> +extern enum libc_speed gnu_libc_func_speed (int fn);

Here you declare gnu_libc_func_speed.

> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -2735,6 +2735,27 @@ ix86_using_red_zone (void)
>         && (!cfun->machine->has_local_indirect_jump
>             || cfun->machine->indirect_branch_type == indirect_branch_keep));
>  }
> +
> +/* This hook determines whether a function from libc has a fast 
> implementation
> +   FN is present at the runtime.  We override it for i386 and glibc C library
> +   as this combination provides fast implementation of mempcpy function.  */
> +
> +enum libc_speed
> +ix86_libc_func_speed (int fn)

But define a different function.

> +{
> +  enum built_in_function f = (built_in_function)fn;
> +
> +  if (!OPTION_GLIBC)
> +    return LIBC_UNKNOWN_SPEED;

OPTION_GLIBC is only defined if linux.h is included, so I think you break
all other x86 targets this way.  The hook should have linux in the name,
perhaps defined only in config/i386/linux.h and redefined in i386.c through
#ifdef SUBTARGET_LIBC_FUNC_SPEED
#undef TARGET_LIBC_FUNC_SPEED
#define TARGET_LIBC_FUNC_SPEED SUBTARGET_LIBC_FUNC_SPEED
#endif
or something similar.

Otherwise LGTM, but please get approval also from Richi (for the generic part) 
and
Uros (for the backend side).

        Jakub

Reply via email to