From: "Martin Liška" <mliska@suse.cz>
To: Richard Biener <richard.guenther@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 1/3] Fold __builtin_str{n}{case}cmp functions (version 2)
Date: Tue, 11 Oct 2016 09:26:00 -0000 [thread overview]
Message-ID: <8b542e2d-8e49-8073-8f0c-25500b965341@suse.cz> (raw)
In-Reply-To: <CAFiYyc00X0ffun7_gr1i4jp7yvRCGFXCNN2e926LDbPqLFEUQw@mail.gmail.com>
On 10/07/2016 12:50 PM, Richard Biener wrote:
> On Fri, Oct 7, 2016 at 10:39 AM, Martin Liška <mliska@suse.cz> wrote:
>> I'm resending the patch, where I implemented all builtins mentions in subject
>> in gimp-fold.c.
>>
>> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
>>
>> Ready to be installed?
>
> + case BUILT_IN_STRNCASECMP:
> + {
> + r = strncmp (p1, p2, length);
> + if (r == 0)
> + known_result = true;
>
> length might be -1 here -- I think you need to guard against that (but you can
> handle BUILT_IN_STRCASECMP which you miss?). Likewise for the strncmp case.
Fixed, I've added comment to STRCASECMP case.
>
> Also do we know whether the c_getstr () result is '\0'-terminated? AFAICS these
> constant foldings were not implemented in builtins.c, I see a STRCMP one in
> fold-const-call.c though. I believe the STRING_CST string is not guaranteed to
> be '\0' terminated (STRING_CST comes with explicit length).
You are absolutely right that we do not have always '\0'-terminated string constants.
Thus I'll send a patch that would return a string from c_getstr just in case
string[string_length] == 0 (separate email with patch will be sent).
>
> + tree temp = fold_build2_loc (loc, MEM_REF, cst_uchar_node, str1,
> + off0);
> + temp = gimple_build (&stmts, loc, NOP_EXPR, cst_uchar_node, temp);
>
> please don't use gimple_build here, there is nothing to simplify for it. Using
> a NOP_EXPR is also confusing (to match the API...). Just do
> gimple_build_assign (make_ssa_name (...), ..) like other folders do.
>
> + replace_call_with_value (gsi, fold_convert_loc (loc, type, temp));
>
> and you'd want to replace the call with the MEM_REF stmt using
> gsi_replace_with_seq_vops as you fail to set virtual operands properly
> above (thus you'll get ICEs when this only matches during GIMPLE opts).
>
> + location_t loc = gimple_location (stmt);
> + tree cst_uchar_node = build_type_variant (unsigned_char_type_node, 1, 0);
> + tree cst_uchar_ptr_node
> + = build_pointer_type_for_mode (cst_uchar_node, ptr_mode, true);
> + tree off0 = build_int_cst (cst_uchar_ptr_node, 0);
>
> it would be nice to not do this tree building if nothign is folded.
>
> + case BUILT_IN_STRCMP:
> + return gimple_fold_builtin_string_compare (gsi);
> + case BUILT_IN_STRCASECMP:
> + return gimple_fold_builtin_string_compare (gsi);
> + case BUILT_IN_STRNCMP:
> + return gimple_fold_builtin_string_compare (gsi);
> + case BUILT_IN_STRNCASECMP:
> + return gimple_fold_builtin_string_compare (gsi);
>
> please do
>
> + case BUILT_IN_STRCMP:
> + case BUILT_IN_STRCASECMP:
> ...
> + return gimple_fold_builtin_string_compare (gsi);
>
> Thanks,
> Richard.
Sure, all notes will be fixed in an email which reply to this one.
Martin
>
>> Martin
next prev parent reply other threads:[~2016-10-11 9:26 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 ` [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-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 1/3] Fold BUILT_IN_STRNCASECMP marxin
2016-08-17 7:10 ` 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 [this message]
2016-10-11 10:27 ` Richard Biener
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: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: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-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=8b542e2d-8e49-8073-8f0c-25500b965341@suse.cz \
--to=mliska@suse.cz \
--cc=gcc-patches@gcc.gnu.org \
--cc=richard.guenther@gmail.com \
/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).