This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH v3] Optimize strchr to strlen
On Wed, Sep 28, 2016 at 5:45 PM, Jason Merrill <jason@redhat.com> wrote:
> OK.
>
> On Wed, Sep 28, 2016 at 11:43 AM, Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:
>> Jason Merrill wrote:
>>> I think this broke g++.dg/ext/builtin10.C.
>>
>> That's odd. It appears if you add a fold in gimple-fold.c, it no longer calls the
>> folding code in builtins.c. No idea what the idea behind that is (especially since
>> there are other builtins that appear in both files), but this simple patch fixes it:
>>
>> If strchr can't be folded in gimple-fold.c, break so folding code in builtins.c is
>> also called.
>>
>> OK for commit?
Please move the remaining folding of strchr to gimple-fold.c then.
All of the non-constant "folding" in builtins.c should move there,
constant folding parts should move to fold-const-call.c.
Thanks,
Richard.
>> 2016-09-28 Wilco Dijkstra <wdijkstr@arm.com>
>>
>> * gimple-fold.c (gimple_fold_builtin): After failing to fold
>> strchr, also try the generic folding.
>> --
>> diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
>> index ddf4cf0ae68ef6708377fdb1a2b45575d90da799..b6802e81fd1a7fd0b309cb9aa0f984f7bacb6596 100644
>> --- a/gcc/gimple-fold.c
>> +++ b/gcc/gimple-fold.c
>> @@ -2948,7 +2948,10 @@ gimple_fold_builtin (gimple_stmt_iterator *gsi)
>> case BUILT_IN_STRNCAT:
>> return gimple_fold_builtin_strncat (gsi);
>> case BUILT_IN_STRCHR:
>> - return gimple_fold_builtin_strchr (gsi);
>> + if (gimple_fold_builtin_strchr (gsi))
>> + return true;
>> + /* Perform additional folding in builtin.c. */
>> + break;
>> case BUILT_IN_FPUTS:
>> return gimple_fold_builtin_fputs (gsi, gimple_call_arg (stmt, 0),
>> gimple_call_arg (stmt, 1), false);
>>