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

* Re: Suboptimal __restrict optimization?
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Lance Taylor @ 2011-10-03 20:23 UTC (permalink / raw)
  To: Ulf Magnusson; +Cc: gcc

Ulf Magnusson <ulfalizer@gmail.com> writes:

> 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?

It's a failure of optimization.

Ian

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

* Re: Suboptimal __restrict optimization?
  2011-10-03 20:23 ` Ian Lance Taylor
@ 2011-10-04 15:08   ` Ulf Magnusson
  2011-10-04 15:47     ` Richard Guenther
  0 siblings, 1 reply; 4+ messages in thread
From: Ulf Magnusson @ 2011-10-04 15:08 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc

On Mon, Oct 3, 2011 at 10:22 PM, Ian Lance Taylor <iant@google.com> wrote:
> Ulf Magnusson <ulfalizer@gmail.com> writes:
>
>> 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?
>
> It's a failure of optimization.
>
> Ian
>

Is this something that has been improved in 4.6.x? (Sorry for the
initial non-reply-all.)

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

* Re: Suboptimal __restrict optimization?
  2011-10-04 15:08   ` Ulf Magnusson
@ 2011-10-04 15:47     ` Richard Guenther
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Guenther @ 2011-10-04 15:47 UTC (permalink / raw)
  To: Ulf Magnusson; +Cc: Ian Lance Taylor, gcc

On Tue, Oct 4, 2011 at 5:07 PM, Ulf Magnusson <ulfalizer@gmail.com> wrote:
> On Mon, Oct 3, 2011 at 10:22 PM, Ian Lance Taylor <iant@google.com> wrote:
>> Ulf Magnusson <ulfalizer@gmail.com> writes:
>>
>>> 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?
>>
>> It's a failure of optimization.
>>
>> Ian
>>
>
> Is this something that has been improved in 4.6.x? (Sorry for the
> initial non-reply-all.)

With 4.6 we export points-to info to RTL, so in theory it could, but
in reality combine does not work to fuse load, add and store.

Richard.

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