On Tue, Oct 11, 2016 at 11:38 AM, Martin Liška <mli...@suse.cz> wrote: > On 10/07/2016 01:01 PM, Richard Biener wrote: >> On Fri, Oct 7, 2016 at 10:41 AM, Martin Liška <mli...@suse.cz> wrote: >>> Resending the patch, where I implemented folding in gimple-fold.c >>> >>> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. >> >> +/* Fold a call to the str{n}{case}cmp builtin pointed by GSI iterator. >> + FCODE is the name of the builtin. */ >> >> wrong comment > > Fixed. > >> >> +static bool >> +gimple_fold_builtin_memchr (gimple_stmt_iterator *gsi) >> >> + { >> + replace_call_with_value (gsi, build_int_cst (type, 0)); >> >> use ptr_type_node (void *) instead of type here and below. > > Done. > >> >> + HOST_WIDE_INT offset = r - p1; >> + if (compare_tree_int (len, offset) <= 0) >> + { >> >> == 0 can occur in which case we have to return a pointer to the >> first char. I think len < offset can't happen with memchr? > > Here I reworked the patch as it's not desired to trigger an undefined behavior > in a host compiler for cases like: memchr ("", 'x', 5). Thus I switched to > strchr > and aforementioned hunk would make sense. > >> >> + replace_call_with_value (gsi, build_int_cst (type, 0)); >> + return true; >> + } >> + else >> + { >> + tree temp = fold_build_pointer_plus_hwi_loc (loc, arg1, >> offset); >> + replace_call_with_value (gsi, temp); >> >> That yields valid GIMPLE by chance, I'd prefer if you'd built that to a >> stmt and use the replace-with-vops. > > Done. > > Apart from that I added handling of lhs and the patch supports folding > of CFN_BUILT_IN_MEMCHR. > > One question that comes to my mind is whether there's a possibility > to fully test gimple folding of all cases if some of them are already > eaten by generic folding? > > Tests of the series have been running.
Ok. Thanks, Richard. > Martin > >> >> + return true; >> + } >> >> >>> Ready to be installed? >>> Martin >