From: marxin <mliska@suse.cz>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH 1/3] Fold BUILT_IN_STRNCASECMP
Date: Wed, 17 Aug 2016 06:55:00 -0000 [thread overview]
Message-ID: <a512b4ec59733c5a2fd74945762456eaa4402cee.1471416736.git.mliska@suse.cz> (raw)
In-Reply-To: <cover.1471416736.git.mliska@suse.cz>
gcc/ChangeLog:
2016-08-16 Martin Liska <mliska@suse.cz>
* builtins.c (fold_builtin_strncmp): Rename to
fold_builtin_strncmp_strncasecmp and support also
strncasecmp.
(fold_builtin_3): Handle BUILT_IN_STRNCASECMP.
---
gcc/builtins.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 03a0dc8..8f1c752 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -150,7 +150,8 @@ static tree fold_builtin_strchr (location_t, tree, tree, tree);
static tree fold_builtin_memchr (location_t, tree, tree, tree, tree);
static tree fold_builtin_memcmp (location_t, tree, tree, tree);
static tree fold_builtin_strcmp (location_t, tree, tree);
-static tree fold_builtin_strncmp (location_t, tree, tree, tree);
+static tree fold_builtin_strncmp_strncasecmp (location_t, tree, tree, tree,
+ bool);
static tree fold_builtin_isascii (location_t, tree);
static tree fold_builtin_toascii (location_t, tree);
static tree fold_builtin_isdigit (location_t, tree);
@@ -7383,11 +7384,13 @@ fold_builtin_strcmp (location_t loc, tree arg1, tree arg2)
return NULL_TREE;
}
-/* Fold function call to builtin strncmp with arguments ARG1, ARG2, and LEN.
- Return NULL_TREE if no simplification can be made. */
+/* Fold function call to builtin strncmp (or strncasecmp) with arguments ARG1,
+ ARG2, and LEN. Return NULL_TREE if no simplification can be made.
+ IS_STRNCASECMP is true for strncasecmp, false otherwise. */
static tree
-fold_builtin_strncmp (location_t loc, tree arg1, tree arg2, tree len)
+fold_builtin_strncmp_strncasecmp (location_t loc, tree arg1, tree arg2,
+ tree len, bool is_strncasecmp)
{
if (!validate_arg (arg1, POINTER_TYPE)
|| !validate_arg (arg2, POINTER_TYPE)
@@ -7442,7 +7445,8 @@ fold_builtin_strncmp (location_t loc, tree arg1, tree arg2, tree len)
/* If len parameter is one, return an expression corresponding to
(*(const unsigned char*)arg1 - (const unsigned char*)arg2). */
- if (tree_fits_uhwi_p (len) && tree_to_uhwi (len) == 1)
+ if (is_strncasecmp
+ && tree_fits_uhwi_p (len) && tree_to_uhwi (len) == 1)
{
tree cst_uchar_node = build_type_variant (unsigned_char_type_node, 1, 0);
tree cst_uchar_ptr_node
@@ -8483,7 +8487,10 @@ fold_builtin_3 (location_t loc, tree fndecl,
break;
case BUILT_IN_STRNCMP:
- return fold_builtin_strncmp (loc, arg0, arg1, arg2);
+ return fold_builtin_strncmp_strncasecmp (loc, arg0, arg1, arg2, false);
+
+ case BUILT_IN_STRNCASECMP:
+ return fold_builtin_strncmp_strncasecmp (loc, arg0, arg1, arg2, true);
case BUILT_IN_MEMCHR:
return fold_builtin_memchr (loc, arg0, arg1, arg2, type);
--
2.9.2
next prev parent reply other threads:[~2016-08-17 6:55 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-17 6:55 [PATCH 0/3] Better folding of 2 string builtin-ins marxin
2016-08-17 6:55 ` marxin [this message]
2016-08-17 7:10 ` [PATCH 1/3] Fold BUILT_IN_STRNCASECMP Jakub Jelinek
2016-08-17 7:52 ` Martin Liška
2016-10-07 8:39 ` [PATCH 1/3] Fold __builtin_str{n}{case}cmp functions (version 2) Martin Liška
2016-10-07 10:50 ` Richard Biener
2016-10-11 9:26 ` Martin Liška
2016-10-11 10:27 ` Richard Biener
2016-10-11 9:28 ` [PATCH] Check \0-termination of string in c_getstr Martin Liška
2016-10-11 10:28 ` Richard Biener
2016-10-12 13:14 ` Martin Liška
2016-10-13 15:24 ` [PATCH] Check \0-termination of string in c_getstr (simplified version) Martin Liška
2016-10-14 9:38 ` Richard Biener
2016-10-14 11:10 ` Martin Liška
2016-10-11 9:28 ` [PATCH] Add a helper function: create_tmp Martin Liška
2016-10-11 10:30 ` Richard Biener
2016-10-11 10:31 ` Richard Biener
2016-10-12 10:50 ` Martin Liška
2016-10-11 9:34 ` [PATCH] Fold __builtin_str{n}{case}cmp functions (version 3) Martin Liška
2016-10-12 8:30 ` Richard Biener
2016-10-12 13:17 ` Martin Liška
2016-10-13 15:25 ` [PATCH] Fold __builtin_str{n}{case}cmp functions (simplified version 4) Martin Liška
2016-10-14 11:55 ` Richard Biener
2016-08-17 6:55 ` [PATCH 3/3] Test folding of strn{case}cmp and memchr marxin
2016-08-17 7:52 ` Martin Liška
2016-10-07 8:42 ` [PATCH 3/3] Test folding of str{n}{case}cmp and memchr (version 2) Martin Liška
2016-10-11 9:39 ` [PATCH] Test folding of str{n}{case}cmp and memchr (version 3) Martin Liška
2016-10-12 8:35 ` Richard Biener
2016-10-12 13:20 ` Martin Liška
2016-10-13 15:27 ` [PATCH] Test folding of str{n}{case}cmp and memchr (simplified version 4) Martin Liška
2016-10-14 11:58 ` Richard Biener
2016-08-17 6:55 ` [PATCH 2/3] Smarter folding of __builtin_memchr marxin
2016-08-17 8:41 ` Richard Biener
2016-10-07 8:41 ` [PATCH 2/3] Fold __builtin_memchr (version 2) Martin Liška
2016-10-07 11:01 ` Richard Biener
2016-10-11 9:38 ` [PATCH] Fold __builtin_memchr (version 3) Martin Liška
2016-10-12 8:34 ` Richard Biener
2016-10-12 8:36 ` Richard Biener
2016-10-12 13:19 ` Martin Liška
2016-10-13 15:26 ` [PATCH] Fold __builtin_memchr (simplified version 4) Martin Liška
2016-10-14 11:57 ` Richard Biener
2016-10-12 13:48 ` [RFC] Possible folding opportunities for string built-ins Martin Liška
2016-10-12 15:55 ` Joseph Myers
2016-10-12 19:45 ` Jim Wilson
2016-10-13 8:38 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a512b4ec59733c5a2fd74945762456eaa4402cee.1471416736.git.mliska@suse.cz \
--to=mliska@suse.cz \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).