public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments
       [not found] <bug-58806-4@http.gcc.gnu.org/bugzilla/>
@ 2013-10-21  2:14 ` glisse at gcc dot gnu.org
  2013-10-21  8:34 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-21  2:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58806

--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
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);


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments
       [not found] <bug-58806-4@http.gcc.gnu.org/bugzilla/>
  2013-10-21  2:14 ` [Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments glisse at gcc dot gnu.org
@ 2013-10-21  8:34 ` rguenth at gcc dot gnu.org
  2013-10-22 11:32 ` glisse at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-10-21  8:34 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58806

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments
       [not found] <bug-58806-4@http.gcc.gnu.org/bugzilla/>
  2013-10-21  2:14 ` [Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments glisse at gcc dot gnu.org
  2013-10-21  8:34 ` rguenth at gcc dot gnu.org
@ 2013-10-22 11:32 ` glisse at gcc dot gnu.org
  2013-10-22 14:58 ` glisse at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-22 11:32 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58806

--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
(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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments
       [not found] <bug-58806-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2013-10-22 11:32 ` glisse at gcc dot gnu.org
@ 2013-10-22 14:58 ` glisse at gcc dot gnu.org
  2013-10-22 20:27 ` glisse at gcc dot gnu.org
  2024-04-09  3:51 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-22 14:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58806

--- Comment #4 from Marc Glisse <glisse at gcc dot gnu.org> ---
(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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments
       [not found] <bug-58806-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2013-10-22 14:58 ` glisse at gcc dot gnu.org
@ 2013-10-22 20:27 ` glisse at gcc dot gnu.org
  2024-04-09  3:51 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-22 20:27 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58806

--- Comment #5 from Marc Glisse <glisse at gcc dot gnu.org> ---
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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments
       [not found] <bug-58806-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2013-10-22 20:27 ` glisse at gcc dot gnu.org
@ 2024-04-09  3:51 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-09  3:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58806

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I thought there was a way already to do this. But nope.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-04-09  3:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-58806-4@http.gcc.gnu.org/bugzilla/>
2013-10-21  2:14 ` [Bug tree-optimization/58806] New attribute for functions that access memory only through their arguments glisse at gcc dot gnu.org
2013-10-21  8:34 ` rguenth at gcc dot gnu.org
2013-10-22 11:32 ` glisse at gcc dot gnu.org
2013-10-22 14:58 ` glisse at gcc dot gnu.org
2013-10-22 20:27 ` glisse at gcc dot gnu.org
2024-04-09  3:51 ` pinskia at gcc dot gnu.org

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).