On Mon, 26 Oct 2020, Jan Hubicka wrote: > Hi, > while looking for special cases of buitins I noticed that tree-ssa-ccp > can use EAF_RETURNS_ARG. I wonder if same should be done by value > numbering and other propagators....
The issue is that changing q = memcpy (p, r); .. use q ... to memcpy (p, r); .. use p .. is bad for RA so we generally do not want to copy-propagate EAF_RETURNS_ARG. We eventually do want to optimize a following if (q == p) of course. And we eventually want to do the _reverse_ transform, replacing memcpy (p, r) .. use p .. with tem = memcpy (p, r) .. use tem .. ISTR playing with patches doing all of the above, would need to dig them out again. There's also a PR about this I think. Bernd added some code to RTL call expansion, not sure exactly what it does... > Bootstrapped/regtested x86_64-linux, OK? OK. Thanks, Richard. > Honza > > * tree-ssa-ccp.c (evaluate_stmt): Use EAF_RETURNS_ARG; do not handle > string buitings specially. > diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c > index 0432fe5513d..ef44e66ce8b 100644 > --- a/gcc/tree-ssa-ccp.c > +++ b/gcc/tree-ssa-ccp.c > @@ -1796,6 +1796,7 @@ evaluate_stmt (gimple *stmt) > ccp_lattice_t likelyvalue = likely_value (stmt); > bool is_constant = false; > unsigned int align; > + bool ignore_return_flags = false; > > if (dump_file && (dump_flags & TDF_DETAILS)) > { > @@ -1965,22 +1966,9 @@ evaluate_stmt (gimple *stmt) > val.mask = ~((HOST_WIDE_INT) align / BITS_PER_UNIT - 1); > break; > > - /* These builtins return their first argument, unmodified. */ > - case BUILT_IN_MEMCPY: > - case BUILT_IN_MEMMOVE: > - case BUILT_IN_MEMSET: > - case BUILT_IN_STRCPY: > - case BUILT_IN_STRNCPY: > - case BUILT_IN_MEMCPY_CHK: > - case BUILT_IN_MEMMOVE_CHK: > - case BUILT_IN_MEMSET_CHK: > - case BUILT_IN_STRCPY_CHK: > - case BUILT_IN_STRNCPY_CHK: > - val = get_value_for_expr (gimple_call_arg (stmt, 0), true); > - break; > - > case BUILT_IN_ASSUME_ALIGNED: > val = bit_value_assume_aligned (stmt, NULL_TREE, val, false); > + ignore_return_flags = true; > break; > > case BUILT_IN_ALIGNED_ALLOC: > @@ -2049,6 +2037,15 @@ evaluate_stmt (gimple *stmt) > if (attrs) > val = bit_value_assume_aligned (stmt, attrs, val, true); > } > + int flags = ignore_return_flags > + ? 0 : gimple_call_return_flags (as_a <gcall *> (stmt)); > + if (flags & ERF_RETURNS_ARG > + && (flags & ERF_RETURN_ARG_MASK) < gimple_call_num_args (stmt)) > + { > + val = get_value_for_expr > + (gimple_call_arg (stmt, > + flags & ERF_RETURN_ARG_MASK), true); > + } > } > is_constant = (val.lattice_val == CONSTANT); > } > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Felix Imend