gcc/gcc/testsuite/gcc.dg/tree-ssa/ldist-rawmemchr-1.c

74 lines
1.8 KiB
C
Raw Normal View History

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.
2021-10-11 09:59:13 +02:00
/* { dg-do run { target s390x-*-* } } */
/* { dg-options "-O2 -ftree-loop-distribution -fdump-tree-ldist-details" } */
/* { dg-additional-options "-march=z13 -mzarch" { target s390x-*-* } } */
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.
2021-10-11 09:59:13 +02:00
/* { dg-final { scan-tree-dump-times "generated rawmemchrQI" 2 "ldist" { target s390x-*-* } } } */
/* { dg-final { scan-tree-dump-times "generated rawmemchrHI" 2 "ldist" { target s390x-*-* } } } */
/* { dg-final { scan-tree-dump-times "generated rawmemchrSI" 2 "ldist" { target s390x-*-* } } } */
/* Rawmemchr pattern: reduction stmt and no store */
#include <stdint.h>
#include <assert.h>
typedef __SIZE_TYPE__ size_t;
extern void* malloc (size_t);
extern void* memset (void*, int, size_t);
#define test(T, pattern) \
__attribute__((noinline)) \
T *test_##T (T *p) \
{ \
while (*p != (T)pattern) \
++p; \
return p; \
}
test (uint8_t, 0xab)
test (uint16_t, 0xabcd)
test (uint32_t, 0xabcdef15)
test (int8_t, 0xab)
test (int16_t, 0xabcd)
test (int32_t, 0xabcdef15)
#define run(T, pattern, i) \
{ \
T *q = p; \
q[i] = (T)pattern; \
assert (test_##T (p) == &q[i]); \
q[i] = 0; \
}
int main(void)
{
void *p = malloc (1024);
assert (p);
memset (p, 0, 1024);
run (uint8_t, 0xab, 0);
run (uint8_t, 0xab, 1);
run (uint8_t, 0xab, 13);
run (uint16_t, 0xabcd, 0);
run (uint16_t, 0xabcd, 1);
run (uint16_t, 0xabcd, 13);
run (uint32_t, 0xabcdef15, 0);
run (uint32_t, 0xabcdef15, 1);
run (uint32_t, 0xabcdef15, 13);
run (int8_t, 0xab, 0);
run (int8_t, 0xab, 1);
run (int8_t, 0xab, 13);
run (int16_t, 0xabcd, 0);
run (int16_t, 0xabcd, 1);
run (int16_t, 0xabcd, 13);
run (int32_t, 0xabcdef15, 0);
run (int32_t, 0xabcdef15, 1);
run (int32_t, 0xabcdef15, 13);
return 0;
}