public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Suboptimal __restrict optimization?
@ 2011-10-02  0:59 Ulf Magnusson
  2011-10-03 20:23 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Ulf Magnusson @ 2011-10-02  0:59 UTC (permalink / raw)
  To: gcc

Hi,

Given the code

class C { void f(int *p); int q; };

void C::f(int * __restrict p) __restrict {
    q += 10;
    *p = 7;
    q += 10;
}

g++ 4.5.2 with -O3 generates the following for C::f() (prologue and
epilogue omitted):

mov    0x8(%ebp),%eax // eax = this (= &q)
mov    0xc(%ebp),%ecx // ecx = p
mov    (%eax),%edx    // edx = q
movl   $0x7,(%ecx)    // *p = 7
add    $0x14,%edx     // q += 20
mov    %edx,(%eax)    // save q

If C::f() is rearranged as

void C::f(int * __restrict p) __restrict {
    *p = 7;
    q += 10;
    q += 10;
}

the following is generated instead:

mov    0x8(%ebp),%eax // eax = this (= &q)
mov    0xc(%ebp),%edx // edx = p
movl   $0x7,(%edx)    // *p = 7
addl   $0x14,(%eax)   // q += 20

Is there some reason why GCC couldn't generate this code for the first
version of C::f()? Is this a failure of optimization, or am I missing
something in how __restricted works?

/Ulf

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

end of thread, other threads:[~2011-10-04 15:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-02  0:59 Suboptimal __restrict optimization? Ulf Magnusson
2011-10-03 20:23 ` Ian Lance Taylor
2011-10-04 15:08   ` Ulf Magnusson
2011-10-04 15:47     ` Richard Guenther

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