aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-fold.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2020-08-14 17:11:53 -0600
committerMartin Sebor <msebor@redhat.com>2020-08-14 17:11:53 -0600
commit866626efd749ed3e2b7014e88e4340b5a4c73560 (patch)
tree9a97cbd204e7f85f1d5388fd61e95f4e6a2ab9ad /gcc/gimple-fold.c
parent2867118ddda9b56d991c16022f7d3d634ed08313 (diff)
downloadgcc-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/gimple-fold.c')
-rw-r--r--gcc/gimple-fold.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 4368817..db56cb6 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -774,7 +774,7 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
strlenopt tests that rely on it for passing are adjusted, this
hack can be removed. */
&& !c_strlen (src, 1)
- && !((tmp_str = c_getstr (src, &tmp_len)) != NULL
+ && !((tmp_str = getbyterep (src, &tmp_len)) != NULL
&& memchr (tmp_str, 0, tmp_len) == NULL)
&& !(srctype
&& AGGREGATE_TYPE_P (srctype)
@@ -2464,8 +2464,8 @@ gimple_fold_builtin_string_compare (gimple_stmt_iterator *gsi)
For nul-terminated strings then adjusted to their length so that
LENx == NULPOSx holds. */
unsigned HOST_WIDE_INT len1 = HOST_WIDE_INT_MAX, len2 = len1;
- const char *p1 = c_getstr (str1, &len1);
- const char *p2 = c_getstr (str2, &len2);
+ const char *p1 = getbyterep (str1, &len1);
+ const char *p2 = getbyterep (str2, &len2);
/* The position of the terminating nul character if one exists, otherwise
a value greater than LENx. */
@@ -2662,7 +2662,7 @@ gimple_fold_builtin_memchr (gimple_stmt_iterator *gsi)
unsigned HOST_WIDE_INT length = tree_to_uhwi (len);
unsigned HOST_WIDE_INT string_length;
- const char *p1 = c_getstr (arg1, &string_length);
+ const char *p1 = getbyterep (arg1, &string_length);
if (p1)
{