[Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments

2024-04-08 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58806

Andrew Pinski  changed:

   What|Removed |Added

 Ever confirmed|0   |1
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2024-04-09
   Keywords||missed-optimization

--- Comment #6 from Andrew Pinski  ---
I thought there was a way already to do this. But nope.

[Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments

2013-10-22 Thread glisse at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58806

--- Comment #5 from Marc Glisse  ---
Created attachment 31074
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31074&action=edit
experimental patch

This optimizes the testcase in comment #0 if I mark g with the attribute
"no_global_write" and use some way of marking g's argument as EAF_DIRECT. Maybe
it would be easier to have the no_global_write attribute (possibly with a
different name) imply EAF_DIRECT on the arguments, as it gets tricky trying to
see what we may alias by following an arbitrary chain starting at a given
pointer.


[Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments

2013-10-22 Thread glisse at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58806

--- Comment #4 from Marc Glisse  ---
(In reply to Marc Glisse from comment #3)
> I should look at where exactly the difference between memcpy and init plays a 
> role.

It is in call_may_clobber_ref_p_1 that memcpy takes a shortcut: it only checks
for refs_may_alias_p_1 with its first argument, instead of going through the
usual intersection of clobber sets.


[Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments

2013-10-22 Thread glisse at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58806

--- Comment #3 from Marc Glisse  ---
(In reply to Richard Biener from comment #2)
> You cannot find the PR because it's already implemented via the "fn spec"
> attribute (conveniently not user-accessible because bike-shedding about
> whether separate attributes are required).  The documentation resides
> in gimple.c:gimple_call_arg_flags,

Thanks, I knew of the EAF_* flags (none look that promising for my particular
use), but not of this "fn spec" attribute.

> and I _think_ it doesn't quite provide
> what you want as it was designed to help the context and flow-insensitive
> points-to analysis which doesn't benefit from "this call does not clobber
> or read from escaped memory".  But what it provides is "the argument to
> this function does not escape" which is important.

I locally changed the name to fn_spec so I could try it. Nothing helps for
comment #0. The combination EAF_NOCLOBBER | EAF_NOESCAPE (aka 'r') is enough to
optimize comment #1. However, EAF_NOCLOBBER is exactly the opposite of what I
want since the whole point of g is to write to its argument, and I don't see
why EAF_NOESCAPE should be necessary since there is no other call afterwards.

So I guess more flags (ECF_* since they wouldn't apply to a specific argument)
would be good. I tried the attributes nothrow,nonnull,leaf on comment #0
because that's what gcc puts on memcpy and gcc knows that memcpy(data,...)
doesn't change *p, but that didn't work, I should look at where exactly the
difference between memcpy and init plays a role.


[Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments

2013-10-21 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58806

--- Comment #2 from Richard Biener  ---
You cannot find the PR because it's already implemented via the "fn spec"
attribute (conveniently not user-accessible because bike-shedding about
whether separate attributes are required).  The documentation resides
in gimple.c:gimple_call_arg_flags, and I _think_ it doesn't quite provide
what you want as it was designed to help the context and flow-insensitive
points-to analysis which doesn't benefit from "this call does not clobber
or read from escaped memory".  But what it provides is "the argument to
this function does not escape" which is important.


[Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments

2013-10-21 Thread glisse at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58806

--- Comment #1 from Marc Glisse  ---
struct A { int i; double d; };

void g(double*);
void f(){
  A a;
  a.i=1;
  g(&a.d);
  if(a.i != 1) __builtin_abort();
}

Here, I guess g is allowed to take its argument, cast it to char*, subtract
offsetof(struct A, d), cast to A* and go modify ->i of that? It would be
convenient to have a way to promise that g does no such thing, but that looks
like a different type of promise than the one in comment #0.

The example is derived from the use of a temporary object of a
reference-counted type, where ideally all uses of the counter should disappear
and the code be equivalent to: double d; g(&d);