public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/58480] New: Use attribute((nonnull)) to optimize callers
@ 2013-09-20  9:38 glisse at gcc dot gnu.org
  2013-10-08 10:39 ` [Bug tree-optimization/58480] " glisse at gcc dot gnu.org
  2013-10-08 10:43 ` glisse at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-09-20  9:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58480
           Summary: Use attribute((nonnull)) to optimize callers
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org

Hello,

in this first function, gcc knows that p is not zero and removes the test (I
have to make sure q doesn't disappear too early, or the compiler forgets that p
is dereferenced, maybe when vrp information becomes persistent...):

int f(int*p){
  int q=*p;
  if(!p) __builtin_abort();
  return q;
}

However, in the following:

void g(int*p,int*q){
  __builtin_memcpy(q,p,4);
  if(!p) __builtin_abort();
}

the test isn't removed, although calling memcpy with a zero argument is just as
bad a dereferencing 0.

Replacing __builtin_memcpy with this doesn't help either:

extern void * my_memcpy (void *dest, const void *src, unsigned long len)
__attribute__((nonnull));

However, this is optimized:

__attribute__((nonnull))void g(int*p){
  if(!p) __builtin_abort();
}

So I think gcc should make use of the nonnull attribute for optimization
purposes not just inside the function, but in the callers as well (and make
sure whatever we do for the nonnull attribute applies to __builtin_memcpy as
well).


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

* [Bug tree-optimization/58480] Use attribute((nonnull)) to optimize callers
  2013-09-20  9:38 [Bug tree-optimization/58480] New: Use attribute((nonnull)) to optimize callers glisse at gcc dot gnu.org
@ 2013-10-08 10:39 ` glisse at gcc dot gnu.org
  2013-10-08 10:43 ` glisse at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-08 10:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
Author: glisse
Date: Tue Oct  8 10:39:49 2013
New Revision: 203271

URL: http://gcc.gnu.org/viewcvs?rev=203271&root=gcc&view=rev
Log:
2013-10-08  Marc Glisse  <marc.glisse@inria.fr>

    PR tree-optimization/58480
gcc/
    * tree-vrp.c (infer_nonnull_range): New function.
    (infer_value_range): Call infer_nonnull_range.

gcc/testsuite/
    * gcc.dg/tree-ssa/pr58480.c: New file.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr58480.c   (with props)
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vrp.c

Propchange: trunk/gcc/testsuite/gcc.dg/tree-ssa/pr58480.c
            ('svn:eol-style' added)

Propchange: trunk/gcc/testsuite/gcc.dg/tree-ssa/pr58480.c
            ('svn:keywords' added)


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

* [Bug tree-optimization/58480] Use attribute((nonnull)) to optimize callers
  2013-09-20  9:38 [Bug tree-optimization/58480] New: Use attribute((nonnull)) to optimize callers glisse at gcc dot gnu.org
  2013-10-08 10:39 ` [Bug tree-optimization/58480] " glisse at gcc dot gnu.org
@ 2013-10-08 10:43 ` glisse at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-08 10:43 UTC (permalink / raw)
  To: gcc-bugs

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

Marc Glisse <glisse at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
           Assignee|unassigned at gcc dot gnu.org      |glisse at gcc dot gnu.org

--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> ---
Done for 4.9.


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

end of thread, other threads:[~2013-10-08 10:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-20  9:38 [Bug tree-optimization/58480] New: Use attribute((nonnull)) to optimize callers glisse at gcc dot gnu.org
2013-10-08 10:39 ` [Bug tree-optimization/58480] " glisse at gcc dot gnu.org
2013-10-08 10:43 ` glisse 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).