summaryrefslogtreecommitdiff
path: root/gcc/builtins.def
diff options
context:
space:
mode:
authorQing Zhao <qing.zhao@oracle.com>2018-05-31 20:01:42 +0000
committerQing Zhao <qinzhao@gcc.gnu.org>2018-05-31 20:01:42 +0000
commit8b0b334af3439179947522206b2478a28b908e61 (patch)
tree1788b6670d6db9169fdfad6b15c80815fe4af24d /gcc/builtins.def
parent28c84b6247e1ff5f3c7aa4c4912c361012fa3904 (diff)
downloadgcc-8b0b334af3439179947522206b2478a28b908e61.tar.gz
2nd Patch for PR78009
Patch for PR83026 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78809 Inline strcmp with small constant strings https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83026 missing strlen optimization for strcmp of unequal strings The design doc for PR78809 is at: https://www.mail-archive.com/gcc@gcc.gnu.org/msg83822.html this patch is for the second part of change of PR78809 and PR83026: B. for strncmp (s1, s2, n) (!)= 0 or strcmp (s1, s2) (!)= 0 B.1. (PR83026) When the lengths of both arguments are constant and it's a strcmp: * if the lengths are NOT equal, we can safely fold the call to a non-zero value. * otherwise, do nothing now. B.2. (PR78809) When the length of one argument is constant, try to replace the call with a __builtin_str(n)cmp_eq call where possible, i.e: strncmp (s, STR, C) (!)= 0 in which, s is a pointer to a string, STR is a string with constant length, C is a constant. if (C <= strlen(STR) && sizeof_array(s) > C) { replace this call with __builtin_strncmp_eq (s, STR, C) (!)= 0 } if (C > strlen(STR) { it can be safely treated as a call to strcmp (s, STR) (!)= 0 can handled by the following strcmp. } strcmp (s, STR) (!)= 0 in which, s is a pointer to a string, STR is a string with constant length. if (sizeof_array(s) > strlen(STR)) { replace this call with __builtin_strcmp_eq (s, STR, strlen(STR)+1) (!)= 0 } later when expanding the new __builtin_str(n)cmp_eq calls, first expand them as __builtin_memcmp_eq, if the expansion does not succeed, change them back to call to __builtin_str(n)cmp. adding test case strcmpopt_2.c and strcmpopt_4.c into gcc.dg for part B of PR78809 adding test case strcmpopt_3.c into gcc.dg for PR83026 From-SVN: r261039
Diffstat (limited to 'gcc/builtins.def')
-rw-r--r--gcc/builtins.def5
1 files changed, 5 insertions, 0 deletions
diff --git a/gcc/builtins.def b/gcc/builtins.def
index 449d08d682f..58b469844a7 100644
--- a/gcc/builtins.def
+++ b/gcc/builtins.def
@@ -971,6 +971,11 @@ DEF_BUILTIN_STUB (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX, "__builtin_alloca_with_ali
equality with zero. */
DEF_BUILTIN_STUB (BUILT_IN_MEMCMP_EQ, "__builtin_memcmp_eq")
+/* An internal version of strcmp/strncmp, used when the result is only
+ tested for equality with zero. */
+DEF_BUILTIN_STUB (BUILT_IN_STRCMP_EQ, "__builtin_strcmp_eq")
+DEF_BUILTIN_STUB (BUILT_IN_STRNCMP_EQ, "__builtin_strncmp_eq")
+
/* Object size checking builtins. */
DEF_GCC_BUILTIN (BUILT_IN_OBJECT_SIZE, "object_size", BT_FN_SIZE_CONST_PTR_INT, ATTR_PURE_NOTHROW_LEAF_LIST)
DEF_EXT_LIB_BUILTIN_CHKP (BUILT_IN_MEMCPY_CHK, "__memcpy_chk", BT_FN_PTR_PTR_CONST_PTR_SIZE_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)