]> git.ipfire.org Git - thirdparty/gcc.git/commit
ldist: Recognize strlen and rawmemchr like loops
authorStefan Schulze Frielinghaus <stefansf@linux.ibm.com>
Mon, 11 Oct 2021 07:59:13 +0000 (09:59 +0200)
committerStefan Schulze Frielinghaus <stefansf@linux.ibm.com>
Mon, 11 Oct 2021 07:59:13 +0000 (09:59 +0200)
commit6f966f06146be7689af471d152e18ff50c609d99
tree72af686fdc3b931398a2f5837d57d2a364616302
parent9abf8c9534144fe9b4948a3104655983821ca7a1
ldist: Recognize strlen and rawmemchr like loops

This patch adds support for recognizing loops which mimic the behaviour
of functions strlen and rawmemchr, and replaces those with internal
function calls in case a target provides them.  In contrast to the
standard strlen and rawmemchr functions, this patch also supports
different instances where the memory pointed to is interpreted as 8, 16,
and 32-bit sized, respectively.

gcc/ChangeLog:

* builtins.c (get_memory_rtx): Change to external linkage.
* builtins.h (get_memory_rtx): Add function prototype.
* doc/md.texi (rawmemchr<mode>): Document.
* internal-fn.c (expand_RAWMEMCHR): Define.
* internal-fn.def (RAWMEMCHR): Add.
* optabs.def (rawmemchr_optab): Add.
* tree-loop-distribution.c (find_single_drs): Change return code
behaviour by also returning true if no single store was found
but a single load.
(loop_distribution::classify_partition): Respect the new return
code behaviour of function find_single_drs.
(loop_distribution::execute): Call new function
transform_reduction_loop in order to replace rawmemchr or strlen
like loops by calls into builtins.
(generate_reduction_builtin_1): New function.
(generate_rawmemchr_builtin): New function.
(generate_strlen_builtin_1): New function.
(generate_strlen_builtin): New function.
(generate_strlen_builtin_using_rawmemchr): New function.
(reduction_var_overflows_first): New function.
(determine_reduction_stmt_1): New function.
(determine_reduction_stmt): New function.
(loop_distribution::transform_reduction_loop): New function.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/ldist-rawmemchr-1.c: New test.
* gcc.dg/tree-ssa/ldist-rawmemchr-2.c: New test.
* gcc.dg/tree-ssa/ldist-strlen-1.c: New test.
* gcc.dg/tree-ssa/ldist-strlen-2.c: New test.
* gcc.dg/tree-ssa/ldist-strlen-3.c: New test.
12 files changed:
gcc/builtins.c
gcc/builtins.h
gcc/doc/md.texi
gcc/internal-fn.c
gcc/internal-fn.def
gcc/optabs.def
gcc/testsuite/gcc.dg/tree-ssa/ldist-rawmemchr-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/ldist-rawmemchr-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/ldist-strlen-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/ldist-strlen-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/ldist-strlen-3.c [new file with mode: 0644]
gcc/tree-loop-distribution.c