diff options
author | Martin Sebor <msebor@redhat.com> | 2020-08-14 17:11:53 -0600 |
---|---|---|
committer | Martin Sebor <msebor@redhat.com> | 2020-08-14 17:11:53 -0600 |
commit | 866626efd749ed3e2b7014e88e4340b5a4c73560 (patch) | |
tree | 9a97cbd204e7f85f1d5388fd61e95f4e6a2ab9ad /gcc/builtins.c | |
parent | 2867118ddda9b56d991c16022f7d3d634ed08313 (diff) | |
download | gcc-866626efd749ed3e2b7014e88e4340b5a4c73560.zip gcc-866626efd749ed3e2b7014e88e4340b5a4c73560.tar.gz gcc-866626efd749ed3e2b7014e88e4340b5a4c73560.tar.bz2 |
PR tree-optimization/78257 - missing memcmp optimization with constant arrays
gcc/ChangeLog:
PR middle-end/78257
* builtins.c (expand_builtin_memory_copy_args): Rename called function.
(expand_builtin_stpcpy_1): Remove argument from call.
(expand_builtin_memcmp): Rename called function.
(inline_expand_builtin_bytecmp): Same.
* expr.c (convert_to_bytes): New function.
(constant_byte_string): New function (formerly string_constant).
(string_constant): Call constant_byte_string.
(byte_representation): New function.
* expr.h (byte_representation): Declare.
* fold-const-call.c (fold_const_call): Rename called function.
* fold-const.c (c_getstr): Remove an argument.
(getbyterep): Define a new function.
* fold-const.h (c_getstr): Remove an argument.
(getbyterep): Declare a new function.
* gimple-fold.c (gimple_fold_builtin_memory_op): Rename callee.
(gimple_fold_builtin_string_compare): Same.
(gimple_fold_builtin_memchr): Same.
gcc/testsuite/ChangeLog:
PR middle-end/78257
* gcc.dg/memchr.c: New test.
* gcc.dg/memcmp-2.c: New test.
* gcc.dg/memcmp-3.c: New test.
* gcc.dg/memcmp-4.c: New test.
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index beb56e0..8845816 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -4441,7 +4441,7 @@ expand_builtin_memory_copy_args (tree dest, tree src, tree len, /* Try to get the byte representation of the constant SRC points to, with its byte size in NBYTES. */ unsigned HOST_WIDE_INT nbytes; - const char *rep = c_getstr (src, &nbytes); + const char *rep = getbyterep (src, &nbytes); /* If the function's constant bound LEN_RTX is less than or equal to the byte size of the representation of the constant argument, @@ -4449,7 +4449,7 @@ expand_builtin_memory_copy_args (tree dest, tree src, tree len, the bytes from memory and only store the computed constant. This works in the overlap (memmove) case as well because store_by_pieces just generates a series of stores of constants - from the representation returned by c_getstr(). */ + from the representation returned by getbyterep(). */ if (rep && CONST_INT_P (len_rtx) && (unsigned HOST_WIDE_INT) INTVAL (len_rtx) <= nbytes @@ -4698,7 +4698,7 @@ expand_builtin_stpcpy_1 (tree exp, rtx target, machine_mode mode) because the latter will potentially produce pessimized code when used to produce the return value. */ c_strlen_data lendata = { }; - if (!c_getstr (src, NULL) + if (!c_getstr (src) || !(len = c_strlen (src, 0, &lendata, 1))) return expand_movstr (dst, src, target, /*retmode=*/ RETURN_END_MINUS_ONE); @@ -5351,11 +5351,11 @@ expand_builtin_memcmp (tree exp, rtx target, bool result_eq) when the function's result is used for equality to zero, ARG1) points to, with its byte size in NBYTES. */ unsigned HOST_WIDE_INT nbytes; - const char *rep = c_getstr (arg2, &nbytes); + const char *rep = getbyterep (arg2, &nbytes); if (result_eq && rep == NULL) { /* For equality to zero the arguments are interchangeable. */ - rep = c_getstr (arg1, &nbytes); + rep = getbyterep (arg1, &nbytes); if (rep != NULL) std::swap (arg1_rtx, arg2_rtx); } @@ -7805,8 +7805,8 @@ inline_expand_builtin_bytecmp (tree exp, rtx target) /* Get the object representation of the initializers of ARG1 and ARG2 as strings, provided they refer to constant objects, with their byte sizes in LEN1 and LEN2, respectively. */ - const char *bytes1 = c_getstr (arg1, &len1); - const char *bytes2 = c_getstr (arg2, &len2); + const char *bytes1 = getbyterep (arg1, &len1); + const char *bytes2 = getbyterep (arg2, &len2); /* Fail if neither argument refers to an initialized constant. */ if (!bytes1 && !bytes2) |